Skip to content

Commit b298ed3

Browse files
committed
workflows: Add automation for choco upgrade
Signed-off-by: Vincent T <vtaylor@microsoft.com>
1 parent 81fb494 commit b298ed3

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: PR for updating Chocolatey
2+
3+
# This action will run after a tag starting with "v" is published
4+
on:
5+
push:
6+
tags:
7+
- 'v*'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
choco-update:
15+
permissions:
16+
contents: write # for Git to git push
17+
pull-requests: write # for creating PRs
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout Headlamp
21+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
22+
with:
23+
token: ${{ secrets.KINVOLK_REPOS_TOKEN }}
24+
# we need the full history for the git tag command, so fetch all the branches
25+
fetch-depth: 0
26+
- name: Configure Git
27+
run: |
28+
user=${{github.actor}}
29+
if [ -z $user ]; then
30+
user=vyncent-t
31+
fi
32+
git config --global user.name "$user"
33+
git config --global user.email "$user@users.noreply.github.com"
34+
# Set up Node.js environment, pay attention to the version
35+
# Some features might not be available in older versions
36+
- name: Create node.js environment
37+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
38+
with:
39+
node-version: '21'
40+
# Install the app dependencies for the choco script
41+
- name: Install app dependencies
42+
run: |
43+
cd $GITHUB_WORKSPACE/app
44+
npm ci
45+
# We set the latest tag as an environment variable before we use it in the next steps
46+
# note that we have to echo the variable to the environment file to make it available in the next steps
47+
- name: Set latest tag
48+
run: |
49+
echo "Setting latest tag"
50+
latestTag=$(git tag --list --sort=version:refname 'v*' | tail -1)
51+
# Remove the 'v' from the tag
52+
latestTag=${latestTag#v}
53+
echo "LATEST_HEADLAMP_TAG=$latestTag" >> $GITHUB_ENV
54+
echo $latestTag
55+
- name: Download checksum / Set hash and checksum
56+
run: |
57+
echo "Downloading checksum"
58+
cd $GITHUB_WORKSPACE/app/windows/chocolatey
59+
curl -L -O "https://github.com/headlamp-k8s/headlamp/releases/download/v$LATEST_HEADLAMP_TAG/checksums.txt"
60+
echo "Checksum downloaded"
61+
if [ -f checksums.txt ]; then
62+
echo "Checksum file exists"
63+
else
64+
echo "Checksum file does not exist"
65+
exit 1
66+
fi
67+
echo "Setting hash and checksum"
68+
read -r hash win_file_name <<< $(grep 'win-x64' ./checksums.txt)
69+
echo "Hash: $hash"
70+
echo "Win file name: $win_file_name"
71+
echo "WIN_FILE_NAME=$win_file_name" >> $GITHUB_ENV
72+
echo "WIN_FILE_HASH=$hash" >> $GITHUB_ENV
73+
echo "Checksum file still exists"
74+
echo "Removing checksums.txt"
75+
rm $GITHUB_WORKSPACE/app/windows/chocolatey/checksums.txt
76+
echo "Checksum file removed"
77+
# Run the choco script
78+
- name: Create nuget package
79+
run: |
80+
echo "Running choco script"
81+
echo "Repository: ${{ github.repository }}"
82+
echo "Workspace: ${GITHUB_WORKSPACE}"
83+
echo $GITHUB_WORKSPACE
84+
pwd
85+
echo "LATEST_HEADLAMP_TAG=$LATEST_HEADLAMP_TAG"
86+
echo "WIN_FILE_HASH=$WIN_FILE_HASH"
87+
echo "creating nuget pkgs"
88+
cd $GITHUB_WORKSPACE/app/windows/chocolatey
89+
./choco-bump.sh $LATEST_HEADLAMP_TAG $WIN_FILE_HASH
90+
echo "Script finished"
91+
# REFACTOR FOR CUSTOM NUGET REPO LATER IF NEEDED
92+
- name: Create PR branch and push
93+
run: |
94+
user=${{github.actor}}
95+
if [ -z $user ]; then
96+
user=vyncent-t
97+
fi
98+
echo "Creating PR branch"
99+
echo "Repository: ${{ github.repository }}"
100+
echo "Workspace: ${GITHUB_WORKSPACE}"
101+
pwd
102+
echo echo "https://github.com/headlamp-k8s/headlamp/pull/new/choco-update-$LATEST_HEADLAMP_TAG"
103+
git checkout -b "choco-update-$LATEST_HEADLAMP_TAG"
104+
git add .
105+
git commit -s -m "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG"
106+
git push origin "choco-update-$LATEST_HEADLAMP_TAG"
107+
gh pr create \
108+
--title "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG" \
109+
--base main \
110+
--assignee $user \
111+
--body "This PR updates the chocolatey package to the latest version of Headlamp" \
112+
env:
113+
GITHUB_TOKEN: ${{ secrets.KINVOLK_REPOS_TOKEN }}

0 commit comments

Comments
 (0)