-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
workflows: Add automation for choco upgrade
Signed-off-by: Vincent T <[email protected]>
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
name: PR for updating Chocolatey | ||
|
||
# This action will run after a tag starting with "v" is published | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
choco-update: | ||
permissions: | ||
contents: write # for Git to git push | ||
pull-requests: write # for creating PRs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Headlamp | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
with: | ||
token: ${{ secrets.KINVOLK_REPOS_TOKEN }} | ||
# we need the full history for the git tag command, so fetch all the branches | ||
fetch-depth: 0 | ||
- name: Configure Git | ||
run: | | ||
user=${{github.actor}} | ||
if [ -z $user ]; then | ||
user=vyncent-t | ||
fi | ||
git config --global user.name "$user" | ||
git config --global user.email "[email protected]" | ||
# Set up Node.js environment, pay attention to the version | ||
# Some features might not be available in older versions | ||
- name: Create node.js environment | ||
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 | ||
with: | ||
node-version: '21' | ||
# Install the app dependencies for the choco script | ||
- name: Install app dependencies | ||
run: | | ||
cd $GITHUB_WORKSPACE/app | ||
npm ci | ||
# We set the latest tag as an environment variable before we use it in the next steps | ||
# note that we have to echo the variable to the environment file to make it available in the next steps | ||
- name: Set latest tag | ||
run: | | ||
echo "Setting latest tag" | ||
latestTag=$(git tag --list --sort=version:refname 'v*' | tail -1) | ||
# Remove the 'v' from the tag | ||
latestTag=${latestTag#v} | ||
echo "LATEST_HEADLAMP_TAG=$latestTag" >> $GITHUB_ENV | ||
echo $latestTag | ||
- name: Download checksum / Set hash and checksum | ||
run: | | ||
echo "Downloading checksum" | ||
cd $GITHUB_WORKSPACE/app/windows/chocolatey | ||
curl -L -O "https://github.com/headlamp-k8s/headlamp/releases/download/v$LATEST_HEADLAMP_TAG/checksums.txt" | ||
echo "Checksum downloaded" | ||
if [ -f checksums.txt ]; then | ||
echo "Checksum file exists" | ||
else | ||
echo "Checksum file does not exist" | ||
exit 1 | ||
fi | ||
echo "Setting hash and checksum" | ||
read -r hash win_file_name <<< $(grep 'win-x64' ./checksums.txt) | ||
echo "Hash: $hash" | ||
echo "Win file name: $win_file_name" | ||
echo "WIN_FILE_NAME=$win_file_name" >> $GITHUB_ENV | ||
echo "WIN_FILE_HASH=$hash" >> $GITHUB_ENV | ||
echo "Checksum file still exists" | ||
echo "Removing checksums.txt" | ||
rm $GITHUB_WORKSPACE/app/windows/chocolatey/checksums.txt | ||
echo "Checksum file removed" | ||
# Run the choco script | ||
- name: Create nuget package | ||
run: | | ||
echo "Running choco script" | ||
echo "Repository: ${{ github.repository }}" | ||
echo "Workspace: ${GITHUB_WORKSPACE}" | ||
echo $GITHUB_WORKSPACE | ||
pwd | ||
echo "LATEST_HEADLAMP_TAG=$LATEST_HEADLAMP_TAG" | ||
echo "WIN_FILE_HASH=$WIN_FILE_HASH" | ||
echo "creating nuget pkgs" | ||
cd $GITHUB_WORKSPACE/app/windows/chocolatey | ||
./choco-bump.sh $LATEST_HEADLAMP_TAG $WIN_FILE_HASH | ||
echo "Script finished" | ||
# REFACTOR FOR CUSTOM NUGET REPO LATER IF NEEDED | ||
- name: Create PR branch and push | ||
run: | | ||
user=${{github.actor}} | ||
if [ -z $user ]; then | ||
user=vyncent-t | ||
fi | ||
echo "Creating PR branch" | ||
echo "Repository: ${{ github.repository }}" | ||
echo "Workspace: ${GITHUB_WORKSPACE}" | ||
pwd | ||
echo echo "https://github.com/headlamp-k8s/headlamp/pull/new/choco-update-$LATEST_HEADLAMP_TAG" | ||
git checkout -b "choco-update-$LATEST_HEADLAMP_TAG" | ||
git add . | ||
git commit -s -m "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG" | ||
git push origin "choco-update-$LATEST_HEADLAMP_TAG" | ||
gh pr create \ | ||
--title "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG" \ | ||
--base main \ | ||
--assignee $user \ | ||
--body "This PR updates the chocolatey package to the latest version of Headlamp" \ | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.KINVOLK_REPOS_TOKEN }} |