Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.14] github: separate workflow for helm repo index update #1361

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- release-*
tags:
- v[0-9]+.[0-9]+.[0-9]+
release:
types: [published]

concurrency:
group: gh-pages

jobs:
build:
name: Update gh-pages
update-docs:
name: Update gh-pages documentation
runs-on: ubuntu-latest
steps:

Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 0 additions & 49 deletions scripts/github/update-gh-pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -198,7 +150,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
Expand Down
44 changes: 44 additions & 0 deletions scripts/github/update-helm-repo.sh
Original file line number Diff line number Diff line change
@@ -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"