Skip to content

Commit

Permalink
workflows: Add automation for choco upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent T <[email protected]>
  • Loading branch information
vyncent-t committed Dec 18, 2024
1 parent 81fb494 commit f558a6b
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/pr-to-update-choco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: PR for updating Chocolatey

# This action will run after a tag starting with "v" is published
# on:
# push:
# tags:
# - 'v*'
# workflow_dispatch:

on:
push:
branches:
- automate-choco-workflow

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
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
- name: Set hash and checksum
run: |
echo "Setting hash and checksum"
cd $GITHUB_WORKSPACE/app/windows/chocolatey
ls
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
# 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"
echo "Checksum file still exists"
ls
echo "Removing checksums.txt"
rm $GITHUB_WORKSPACE/app/windows/chocolatey/checksums.txt
ls
echo "Checksum file removed"
# 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
ls
echo echo "https://github.com/headlamp-k8s/headlamp/pull/new/WIP0-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 }}
10 changes: 10 additions & 0 deletions app/windows/chocolatey/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
4a926c3f9175fca2f71bd777db33b0a9b272cd88e980f6d9ca3422ef99a0035e Headlamp-0.27.0-linux-arm64.AppImage
cbaecfba70966938d6d9c6883b267e8c7e5f33c8b823a2d225d78a39f51921f6 Headlamp-0.27.0-linux-arm64.tar.gz
2d369e7f9bb70676b7e48e2d8aafe667fc9748f7a4189074e8d7ad5e7ed01251 Headlamp-0.27.0-linux-armv7l.AppImage
81e941a6b9f74b9f5abde787ff4a3d6022e5a6a003ce5a00a41ea7e0b85290f3 Headlamp-0.27.0-linux-armv7l.tar.gz
0e12d342cd1cc491173d1cc0776049ad0cacf1f3972f87c7704d5a15031fba21 Headlamp-0.27.0-linux-x64.AppImage
11955d1b81d3ce45ae13d03541904ab07222b0ebf84d077582102b454b9d2255 Headlamp-0.27.0-linux-x64.tar.gz
d4ed9d1fe4313053ac5be577e12fdddbdc8495bef415147b518e81cdd3644249 Headlamp-0.27.0-mac-arm64.dmg
a5e8b2821890012e2c5ef0695863a5d83bbbc66d64bc6a057a036fac6f2ad9c0 Headlamp-0.27.0-mac-x64.dmg
b94dec3f29b0024a694e140ec0a343e8143d147f352fde095eda4908e141035d Headlamp-0.27.0-win-x64.exe
6582c5500e3e76092c1d729596ebd13431c6089f71df604e28c83525552083b3 headlamp_0.27.0-1_amd64.deb

0 comments on commit f558a6b

Please sign in to comment.