Skip to content

Commit 72bf84c

Browse files
committed
github: separate workflow for helm repo index update
No need to (re-)build documentation when a release is published. Great simplification of the Helm repo index update script: do not scan all releases but just get the assets from the release that was published. This separation should make the maintenance of scripts and workflows easier.
1 parent 45cc1cf commit 72bf84c

File tree

4 files changed

+78
-54
lines changed

4 files changed

+78
-54
lines changed

.github/workflows/gh-pages.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ on:
66
- release-*
77
tags:
88
- v[0-9]+.[0-9]+.[0-9]+
9-
release:
10-
types: [published]
119

1210
concurrency:
13-
group: ${{ github.workflow }}
11+
group: gh-pages
1412

1513
jobs:
16-
build:
17-
name: Update gh-pages
14+
update-docs:
15+
name: Update gh-pages documentation
1816
runs-on: ubuntu-latest
1917
steps:
2018

.github/workflows/release.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: gh-pages
2+
on:
3+
release:
4+
types: [published, edited]
5+
6+
concurrency:
7+
group: gh-pages
8+
9+
jobs:
10+
update-helm-repo:
11+
name: Update gh-pages helm repo index
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install Helm
15+
uses: azure/setup-helm@v3
16+
with:
17+
version: 3.12.3
18+
19+
- name: Check out repo
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Update repo index
25+
run: |
26+
git config user.name "Github Actions"
27+
git config user.email "[email protected]"
28+
./scripts/github/update-helm-repo.sh ${{ join(github.event.release.assets.*.browser_download_url, ' ') }}
29+
30+
- name: Push
31+
run: git push -f https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} gh-pages

scripts/github/update-gh-pages.sh

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,54 +29,6 @@ create_versions_js() {
2929
echo -e " ];\n}"
3030
}
3131

32-
# Helper for updating help repo index
33-
update_helm_repo_index() {
34-
echo "Updating Helm repo index"
35-
36-
# TODO: with a lot of releases github API will paginate and this will break
37-
releases="`curl -sSf -H 'Accept: application/vnd.github.v3+json' \
38-
$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases | jq -c '.[]'`"
39-
40-
echo "$releases" | while read -r release_meta; do
41-
# Set fields we're interested in as shell variables
42-
eval `echo "$release_meta" | jq -r '{tag_name, url, assets} | keys[] as $k | "\($k)='"'"'\(.[$k])'"'"'"'`
43-
44-
echo "Scanning assets of release $tag_name..."
45-
46-
for asset_meta in `echo $assets | jq -c '.[]'`; do
47-
# Set fields we're interested in as "asset_<field>" shell variables
48-
eval `echo $asset_meta | jq -r '{id, name, url, browser_download_url} | keys[] as $k | "local asset_\($k)=\(.[$k])"'`
49-
50-
if [[ "$asset_name" != node-feature-discovery-chart-*tgz ]]; then
51-
echo " $asset_name does not look like a Helm chart archive, skipping..."
52-
continue
53-
fi
54-
55-
# Check if the asset has changed
56-
asset_id_old=`cat "$asset_name".id 2> /dev/null || :`
57-
if [[ $asset_id_old == $asset_id ]]; then
58-
echo " $asset_name (id=$asset_id) unchanged, skipping..."
59-
continue
60-
fi
61-
62-
# Update helm repo index
63-
local tmpdir="`mktemp -d`"
64-
65-
echo " downloading $asset_name..."
66-
curl -sSfL -H "Accept:application/octet-stream" -o "$tmpdir/$asset_name" $asset_url
67-
68-
echo " updating helm index for $asset_name..."
69-
local download_baseurl=`dirname $asset_browser_download_url`
70-
helm repo index "$tmpdir" --merge index.yaml --url $download_baseurl
71-
cp "$tmpdir/index.yaml" .
72-
rm -rf "$tmpdir"
73-
74-
# Update id cache file
75-
echo $asset_id > "$asset_name".id
76-
done
77-
done
78-
}
79-
8032
#
8133
# Argument parsing
8234
#
@@ -203,7 +155,6 @@ EOF
203155
# Update Helm repo
204156
mkdir -p charts
205157
pushd charts > /dev/null
206-
update_helm_repo_index
207158
popd > /dev/null
208159

209160
# Check if there were any changes in the repo

scripts/github/update-helm-repo.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash -e
2+
set -o pipefail
3+
4+
asset_urls="$@"
5+
6+
git checkout gh-pages
7+
cd charts
8+
9+
# Download chart(s) from release assets
10+
for asset_url in $asset_urls; do
11+
if ! echo "$asset_url" | grep -q 'chart.*tgz$'; then
12+
echo "Skipping $asset_url, does not look like a Helm chart archive"
13+
continue
14+
fi
15+
16+
echo "Downloading $asset_url..."
17+
curl -sSfLO $asset_url
18+
# We rely on all release assets having the same baseurl
19+
download_baseurl=`dirname $asset_url`
20+
done
21+
22+
if [ -z "$download_baseurl" ]; then
23+
echo "No Helm chart release assets found"
24+
exit 0
25+
fi
26+
27+
echo "Updating helm index"
28+
helm repo index . --merge index.yaml --url $download_baseurl
29+
30+
# Check if there were any changes in the repo
31+
if [ -z "`git status --short`" ]; then
32+
echo "No changes in Helm repo incex, gh-pages branch already up-to-date"
33+
exit 0
34+
fi
35+
36+
# Create a new commit
37+
commit_msg="Update Helm repo index for release `basename $download_baseurl`
38+
39+
Auto-generated by `basename $0`"
40+
41+
echo "Committing changes..."
42+
git commit -m "$commit_msg" -- index.yaml
43+
44+
echo "gh-pages branch successfully updated"

0 commit comments

Comments
 (0)