Skip to content

Commit ecea091

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

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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-workflow
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+
- name: Configure Git
31+
run: |
32+
user=${{github.actor}}
33+
if [ -z $user ]; then
34+
user=vyncent-t
35+
fi
36+
git config --global user.name "$user"
37+
git config --global user.email "$user@users.noreply.github.com"
38+
# Set up Node.js environment, pay attention to the version
39+
# Some features might not be available in older versions
40+
- name: Create node.js environment
41+
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
42+
with:
43+
node-version: '21'
44+
# Install the app dependencies for the choco script
45+
- name: Install app dependencies
46+
run: |
47+
cd $GITHUB_WORKSPACE/app
48+
npm ci
49+
# We set the latest tag as an environment variable before we use it in the next steps
50+
# note that we have to echo the variable to the environment file to make it available in the next steps
51+
- name: Set latest tag
52+
run: |
53+
echo "Setting latest tag"
54+
latestTag=$(git tag --list --sort=version:refname 'v*' | tail -1)
55+
# Remove the 'v' from the tag
56+
latestTag=${latestTag#v}
57+
echo "LATEST_HEADLAMP_TAG=$latestTag" >> $GITHUB_ENV
58+
echo $latestTag
59+
- name: Download checksum
60+
run: |
61+
echo "Downloading checksum"
62+
cd $GITHUB_WORKSPACE/app/windows/chocolatey
63+
curl -O "https://github.com/headlamp-k8s/headlamp/releases/download/v$LATEST_HEADLAMP_TAG/checksums.txt"
64+
ls checksums.txt
65+
echo "Setting hash"
66+
- name: Set hash and checksum
67+
run: |
68+
echo "Setting hash and checksum"
69+
cd $GITHUB_WORKSPACE/app/windows/chocolatey
70+
ls
71+
read -r hash win_file_name <<< $(grep win ./checksums.txt)
72+
echo "Hash: $hash"
73+
echo "Win file name: $win_file_name"
74+
echo "WIN_FILE_NAME=$win_file_name" >> $GITHUB_ENV
75+
echo "WIN_FILE_HASH=$hash" >> $GITHUB_ENV
76+
cat $GITHUB_WORKSPACE/app/windows/chocolatey/checksums.txt
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+
ls
103+
echo echo "https://github.com/headlamp-k8s/headlamp/pull/new/WIP-choco-update-$LATEST_HEADLAMP_TAG"
104+
git checkout -b "WIP-choco-update-$LATEST_HEADLAMP_TAG"
105+
git add .
106+
git commit -s -m "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG"
107+
git push origin "WIP-choco-update-$LATEST_HEADLAMP_TAG"
108+
gh pr create \
109+
--title "chocolatey: Bump Headlamp version to $LATEST_HEADLAMP_TAG" \
110+
--base main \
111+
--assignee $user \
112+
--body "This PR updates the chocolatey package to the latest version of Headlamp" \
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.KINVOLK_REPOS_TOKEN }}

0 commit comments

Comments
 (0)