mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-28 02:37:11 +00:00
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.
This commit is contained in:
parent
45cc1cfc25
commit
72bf84c4fa
4 changed files with 78 additions and 54 deletions
8
.github/workflows/gh-pages.yml
vendored
8
.github/workflows/gh-pages.yml
vendored
|
@ -6,15 +6,13 @@ on:
|
|||
- release-*
|
||||
tags:
|
||||
- v[0-9]+.[0-9]+.[0-9]+
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}
|
||||
group: gh-pages
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Update gh-pages
|
||||
update-docs:
|
||||
name: Update gh-pages documentation
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
|
|
31
.github/workflows/release.yml
vendored
Normal file
31
.github/workflows/release.yml
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
name: gh-pages
|
||||
on:
|
||||
release:
|
||||
types: [published, edited]
|
||||
|
||||
concurrency:
|
||||
group: gh-pages
|
||||
|
||||
jobs:
|
||||
update-helm-repo:
|
||||
name: Update gh-pages helm repo index
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install Helm
|
||||
uses: azure/setup-helm@v3
|
||||
with:
|
||||
version: 3.12.3
|
||||
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Update repo index
|
||||
run: |
|
||||
git config user.name "Github Actions"
|
||||
git config user.email "no-reply@github.com"
|
||||
./scripts/github/update-helm-repo.sh ${{ join(github.event.release.assets.*.browser_download_url, ' ') }}
|
||||
|
||||
- name: Push
|
||||
run: git push -f https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} gh-pages
|
|
@ -29,54 +29,6 @@ create_versions_js() {
|
|||
echo -e " ];\n}"
|
||||
}
|
||||
|
||||
# Helper for updating help repo index
|
||||
update_helm_repo_index() {
|
||||
echo "Updating Helm repo index"
|
||||
|
||||
# TODO: with a lot of releases github API will paginate and this will break
|
||||
releases="`curl -sSf -H 'Accept: application/vnd.github.v3+json' \
|
||||
$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases | jq -c '.[]'`"
|
||||
|
||||
echo "$releases" | while read -r release_meta; do
|
||||
# Set fields we're interested in as shell variables
|
||||
eval `echo "$release_meta" | jq -r '{tag_name, url, assets} | keys[] as $k | "\($k)='"'"'\(.[$k])'"'"'"'`
|
||||
|
||||
echo "Scanning assets of release $tag_name..."
|
||||
|
||||
for asset_meta in `echo $assets | jq -c '.[]'`; do
|
||||
# Set fields we're interested in as "asset_<field>" shell variables
|
||||
eval `echo $asset_meta | jq -r '{id, name, url, browser_download_url} | keys[] as $k | "local asset_\($k)=\(.[$k])"'`
|
||||
|
||||
if [[ "$asset_name" != node-feature-discovery-chart-*tgz ]]; then
|
||||
echo " $asset_name does not look like a Helm chart archive, skipping..."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if the asset has changed
|
||||
asset_id_old=`cat "$asset_name".id 2> /dev/null || :`
|
||||
if [[ $asset_id_old == $asset_id ]]; then
|
||||
echo " $asset_name (id=$asset_id) unchanged, skipping..."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Update helm repo index
|
||||
local tmpdir="`mktemp -d`"
|
||||
|
||||
echo " downloading $asset_name..."
|
||||
curl -sSfL -H "Accept:application/octet-stream" -o "$tmpdir/$asset_name" $asset_url
|
||||
|
||||
echo " updating helm index for $asset_name..."
|
||||
local download_baseurl=`dirname $asset_browser_download_url`
|
||||
helm repo index "$tmpdir" --merge index.yaml --url $download_baseurl
|
||||
cp "$tmpdir/index.yaml" .
|
||||
rm -rf "$tmpdir"
|
||||
|
||||
# Update id cache file
|
||||
echo $asset_id > "$asset_name".id
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# Argument parsing
|
||||
#
|
||||
|
@ -203,7 +155,6 @@ EOF
|
|||
# Update Helm repo
|
||||
mkdir -p charts
|
||||
pushd charts > /dev/null
|
||||
update_helm_repo_index
|
||||
popd > /dev/null
|
||||
|
||||
# Check if there were any changes in the repo
|
||||
|
|
44
scripts/github/update-helm-repo.sh
Executable file
44
scripts/github/update-helm-repo.sh
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/bin/bash -e
|
||||
set -o pipefail
|
||||
|
||||
asset_urls="$@"
|
||||
|
||||
git checkout gh-pages
|
||||
cd charts
|
||||
|
||||
# Download chart(s) from release assets
|
||||
for asset_url in $asset_urls; do
|
||||
if ! echo "$asset_url" | grep -q 'chart.*tgz$'; then
|
||||
echo "Skipping $asset_url, does not look like a Helm chart archive"
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "Downloading $asset_url..."
|
||||
curl -sSfLO $asset_url
|
||||
# We rely on all release assets having the same baseurl
|
||||
download_baseurl=`dirname $asset_url`
|
||||
done
|
||||
|
||||
if [ -z "$download_baseurl" ]; then
|
||||
echo "No Helm chart release assets found"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Updating helm index"
|
||||
helm repo index . --merge index.yaml --url $download_baseurl
|
||||
|
||||
# Check if there were any changes in the repo
|
||||
if [ -z "`git status --short`" ]; then
|
||||
echo "No changes in Helm repo incex, gh-pages branch already up-to-date"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Create a new commit
|
||||
commit_msg="Update Helm repo index for release `basename $download_baseurl`
|
||||
|
||||
Auto-generated by `basename $0`"
|
||||
|
||||
echo "Committing changes..."
|
||||
git commit -m "$commit_msg" -- index.yaml
|
||||
|
||||
echo "gh-pages branch successfully updated"
|
Loading…
Add table
Reference in a new issue