diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index f615327e56..39b9d774b9 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -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: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..04eb8009bb --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/scripts/github/update-gh-pages.sh b/scripts/github/update-gh-pages.sh index 6427d0c6b8..94d53a4522 100755 --- a/scripts/github/update-gh-pages.sh +++ b/scripts/github/update-gh-pages.sh @@ -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_" 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 diff --git a/scripts/github/update-helm-repo.sh b/scripts/github/update-helm-repo.sh new file mode 100755 index 0000000000..3f2846c840 --- /dev/null +++ b/scripts/github/update-helm-repo.sh @@ -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"