mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-05 08:17:04 +00:00
scripts/update-gh-pages: manage a Helm repo
Make the update-gh-pages.sh script to maintain a Helm charts repository under charts/ subdirectory in gh-pages. The script now (always) scans throught all release assets and injects any found Helm chart archives into the Helm repo. In practice, new assets in all Github releases are scanned and the Helm repo is updated on any update of the master or release branches or on any new tags. Asset ids are tracked/cached in order to avoid unnecessary downloads, but also, to capture any changes in assets that were already merged in the repo index. After this a user is able to do something like $ helm repo add nfd http://kubernetes-sigs.github.io/node-feature-discovery/charts ... $ helm repo update ... $ helm install nfd/node-feature-discovery --namespace nfd --create-namespace --generate-name ...
This commit is contained in:
parent
b72b5f751a
commit
dfae747e84
2 changed files with 64 additions and 3 deletions
5
.github/workflows/gh-pages.yml
vendored
5
.github/workflows/gh-pages.yml
vendored
|
@ -12,6 +12,11 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get install -y jq curl
|
||||
curl -sfL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -s -- --version v3.5.2
|
||||
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
|
|
|
@ -22,11 +22,59 @@ create_versions_js() {
|
|||
# 'stable' is a symlink pointing to the latest version
|
||||
[ -f stable ] && echo " { name: 'stable', url: '$_baseurl/stable' },"
|
||||
for f in `ls -d */ | tr -d /` ; do
|
||||
echo " { name: '$f', url: '$_baseurl/$f' },"
|
||||
if [ -f "$f/index.html" ]; then
|
||||
echo " { name: '$f', url: '$_baseurl/$f' },"
|
||||
fi
|
||||
done
|
||||
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 '.[]'`"
|
||||
|
||||
for release_meta in $releases; 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])'"'"'"'`
|
||||
|
||||
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 $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
|
||||
#
|
||||
|
@ -132,7 +180,7 @@ else
|
|||
fi
|
||||
|
||||
# Switch to work in the gh-pages worktree
|
||||
cd "$build_dir"
|
||||
pushd "$build_dir"
|
||||
|
||||
_stable=`(ls -d1 v*/ || :) | sort -n | tail -n1`
|
||||
[ -n "$_stable" ] && ln -sfT "$_stable" stable
|
||||
|
@ -140,10 +188,18 @@ _stable=`(ls -d1 v*/ || :) | sort -n | tail -n1`
|
|||
# Detect existing versions from the gh-pages branch
|
||||
create_versions_js > versions.js
|
||||
|
||||
# Create index.html
|
||||
cat > index.html << EOF
|
||||
<meta http-equiv="refresh" content="0; URL='stable/'"/>
|
||||
EOF
|
||||
|
||||
# Update Helm repo
|
||||
mkdir -p charts
|
||||
pushd charts
|
||||
update_helm_repo_index
|
||||
popd
|
||||
|
||||
# Check if there were any changes in the repo
|
||||
if [ -z "`git status --short`" ]; then
|
||||
echo "No new content, gh-pages branch already up-to-date"
|
||||
exit 0
|
||||
|
@ -156,7 +212,7 @@ echo "Committing changes..."
|
|||
git add .
|
||||
git commit $amend -m "$commit_msg"
|
||||
|
||||
cd -
|
||||
popd
|
||||
|
||||
echo "gh-pages branch successfully updated"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue