Skip to content

Commit 181ed6c

Browse files
committed
workflows: Add automation for choco upgrade
Signed-off-by: Vincent T <vtaylor@microsoft.com>
1 parent 22688fa commit 181ed6c

File tree

1 file changed

+108
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)