Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
  • Loading branch information
ArangoGutierrez committed May 8, 2024
1 parent e16f7f4 commit 4d6b6e5
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 26 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:

jobs:
update-helm-charts:
name: Update gh-pages helm repo index
name: Update gh-pages branch helm charts and index
runs-on: ubuntu-latest
steps:
- name: Install Helm
Expand All @@ -35,17 +35,17 @@ jobs:
fetch-depth: 0

- name: Update helm index
en:
env:
VERSION: ${{ github.event.release.tag_name }}
HELM_REPO_PATH: releases/helm-${{ github.event.release.tag_name }}/
DOWNLOAD_URL: ${{ join(github.event.release.assets.*.browser_download_url, ' ') }}
run: |
git config user.name "Github Actions"
git config user.email "no-reply@github.com"
./hack/update-helm-index.sh ${{ join(github.event.release.assets.*.browser_download_url, ' ') }}
./hack/update-helm-index.sh $DOWNLOAD_URL
- name: Push updated index to gh-pages branch
- name: Push updated Helm charts and index to gh-pages branch
env:
HELM_REPO_PATH: releases/helm-${{ github.event.release.tag_name }}/
run: |
cd $HELM_REPO_PATH
git push -f https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} gh-pages
git -C $HELM_REPO_PATH https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} gh-pages
104 changes: 84 additions & 20 deletions hack/update-helm-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,59 @@

set -o pipefail

asset_urls="$@"
this=`basename $0`

usage () {
cat << EOF
Usage: $this [-h]
Options:
--helm-repo-path specify the path to the Helm repo (defaults to HELM_REPO_PATH)
--help/-h show this help and exit
NOTE: only one of --from-url or --from-local can be specified
Example:
- from a local path:
$this --from-local /path/to/nvidia-device-plugin-0.15.0.tgz
- from a URL:
$this --from-url https://github.com/NVIDIA/k8s-device-plugin/archive/refs/tags/nvidia-device-plugin-0.15.0.tgz
EOF
}

#
# Parse command line
#
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--helm-repo-path)
HELM_REPO_PATH="$2"
shift 2
;;
--help/h) usage
exit 0
;;
*) usage
exit 1
;;
esac
done

# now we take the input from the user and check if is a path or url http/https
asset_path="$@"

if [ -z "$asset_path" ]; then
echo "No assets provided"
exit 1
fi

if [[ $asset_path =~ ^https?:// ]]; then
asset_url=$asset_path
else
asset_local=$asset_path
fi

GH_REPO_PULL_URL="https://github.com/NVIDIA/k8s-device-plugin.git"
git clone --local $$(pwd) $(HELM_REPO_PATH)
Expand All @@ -26,41 +78,53 @@ git -C $(HELM_REPO_PATH) checkout gh-pages

pushd $HELM_REPO_PATH/stable > /dev/null
# Download charts from release assets
for asset_url in $asset_urls; do
if ! echo "$asset_url" | grep -q '.*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
if [ -n "$asset_local" ]; then
echo "Copying $asset_local..."
cp -f $asset_local $HELM_REPO_PATH/stable
fi

if [ -n "$asset_url" ]; then
for asset_url in $asset_urls; do
if ! echo "$asset_url" | grep -q '.*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
fi

echo "Updating helm index"
helm repo index stable --merge index.yaml --url https://nvidia.github.io/k8s-device-plugin/stable
cp -f stable/index.yaml index.yaml
popd > /dev/null

cp -f $HELM_REPO_PATH/stable/index.yaml $HELM_REPO_PATH/index.yaml

pushd $HELM_REPO_PATH > /dev/null
# Check if there were any changes in the repo
if [ -z "`git status --short`" ]; then
if [ -z $(git status --short) ]; then
echo "No changes in Helm repo index, gh-pages branch already up-to-date"
exit 0
fi

# Create a new commit
commit_msg="Update Helm repo index for release $VERSION"
commit_msg="Update helm charts for release $VERSION
This commit was created by the k8s-device-plugin release workflow.
It updates the Helm charts in the gh-pages branch to include the $VERSION release assets.
Also updates the Helm index.yaml file to include the new chart versions."

echo "Committing changes..."
git commit -am "$commit_msg"
git add index.yaml stable
git commit --signoff -m "$commit_msg"

echo "gh-pages branch successfully updated"
popd > /dev/null

0 comments on commit 4d6b6e5

Please sign in to comment.