Skip to content

Commit ad4aae5

Browse files
authored
Merge pull request #691 from ArangoGutierrez/releaseAction
GitHub Actions: Add Release workflow
2 parents 6a10d70 + 61ac478 commit ad4aae5

File tree

7 files changed

+279
-10
lines changed

7 files changed

+279
-10
lines changed

.github/workflows/helm.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2024 NVIDIA CORPORATION
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Run this workflow on new tags
16+
name: Publish Helm Chart
17+
18+
on:
19+
release:
20+
types:
21+
- published
22+
23+
jobs:
24+
update-helm-charts:
25+
name: Update gh-pages branch helm charts and index
26+
runs-on: ubuntu-latest
27+
env:
28+
HELM_REPO_PATH: releases/helm-${{ github.event.release.tag_name }}/
29+
steps:
30+
- name: Install Helm
31+
uses: azure/setup-helm@v4.2.0
32+
with:
33+
version: 3.14.4
34+
35+
- name: Check out repo
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
40+
- name: Update helm index
41+
env:
42+
VERSION: ${{ github.event.release.tag_name }}
43+
DOWNLOAD_URL: ${{ join(github.event.release.assets.*.browser_download_url, ' ') }}
44+
run: |
45+
git config user.name "Github Actions"
46+
git config user.email "no-reply@github.com"
47+
./hack/update-helm-index.sh --helm-repo-path $HELM_REPO_PATH $DOWNLOAD_URL
48+
49+
- name: Push updated Helm charts and index to gh-pages branch
50+
run: |
51+
git -C $HELM_REPO_PATH push https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} gh-pages

.github/workflows/release.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright 2024 NVIDIA CORPORATION
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Run this workflow on new tags
16+
name: Release
17+
18+
on:
19+
push:
20+
tags:
21+
- v*
22+
23+
jobs:
24+
release:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
name: Check out code
29+
30+
- name: Create Draft Release
31+
env:
32+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
OWNER: ${{ github.repository_owner }}
34+
REPO: ${{ github.event.repository.name }}
35+
run: |
36+
PRERELEASE_FLAG=""
37+
if [[ ${{ github.ref_name }} == v*-rc.* ]]; then
38+
PRERELEASE_FLAG="--prerelease"
39+
fi
40+
gh release create ${{ github.ref_name }} \
41+
--draft \
42+
-t ${{ github.ref_name }} \
43+
-n $(./hack/generate-changelog.sh --version ${{ github.ref_name }}) \
44+
-R $OWNER/$REPO \
45+
--verify-tag \
46+
$PRERELEASE_FLAG
47+
48+
- name: Install Helm
49+
uses: azure/setup-helm@v4.2.0
50+
with:
51+
version: 3.14.4
52+
53+
- name: Generate Helm Charts
54+
run: |
55+
./hack/package-helm-charts.sh ${{ github.ref_name }}
56+
57+
- name: Upload Release Artifacts
58+
env:
59+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
OWNER: ${{ github.repository_owner }}
61+
REPO: ${{ github.event.repository.name }}
62+
run: |
63+
HELM_PACKAGE_VERSION=${GITHUB_REF_NAME#v}
64+
gh release upload ${{ github.ref_name }} ./nvidia-device-plugin-${HELM_PACKAGE_VERSION}.tgz -R $OWNER/$REPO
65+
gh release upload ${{ github.ref_name }} ./gpu-feature-discovery-${HELM_PACKAGE_VERSION}.tgz -R $OWNER/$REPO

RELEASE.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ The device plugin consists in two artifacts:
55
- The Device Plugin helm chart
66

77
Publishing the container is automated through gitlab-ci and only requires one to tag the commit and push it to gitlab.
8-
Publishing the helm chart is currently manual, and we should move to an automated process ASAP
98

109
# Release Process Checklist
1110
- [ ] Run the `./hack/prepare-release.sh` script to update the version in all the needed files
1211
- [ ] Run the `./hack/package-helm-charts.sh` script to generate the helm charts
1312
- [ ] Run the `./hack/generate-changelog.sh` script to generate the a draft changelog
1413
- [ ] Update the CHANGELOG.md file with the generated changelog
1514
- [ ] Commit, Tag and Push to Gitlab
16-
- [ ] Switch to the `gh-pages` branch and move the newly generated package to the `stable` helm repo
17-
- [ ] While on the `gh-pages` branch, run the `./build-index.sh` script to rebuild the indices for each repo
18-
- [ ] Commit and push the `gh-pages` branch to GitHub
19-
- [ ] Wait for the [CI job associated with your tag] (https://gitlab.com/nvidia/kubernetes/device-plugin/-/pipelines) to complete
20-
- [ ] Create a [new release](https://github.com/NVIDIA/k8s-device-plugin/releases) on Github with the changelog
15+
- [ ] Wait for the `Release` GitHub Action to complete
16+
- [ ] Publish the [draft release](https://github.com/NVIDIA/k8s-device-plugin/releases) created by the GitHub Action
17+
- [ ] Wait for the `Publish Helm Chart` GitHub Action to complete
18+
19+
## Troubleshooting
20+
- If the `Release` GitHub Action fails:
21+
- check the logs for the error first.
22+
- Manually run the `Release` GitHub Action locally with the same inputs.
23+
- If the action fails, manually run `./hack/package-helm-charts.sh` and upload the generated charts to the release assets.
24+
- If the `Publish Helm Chart` GitHub Action fails:
25+
- Check the logs for the error.
26+
- Manually run `./hack/update-helm-index.sh` with the generated charts from the `Release` GitHub Action or the `./hack/package-helm-charts.sh` script.

hack/generate-changelog.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,4 @@ echo ""
7777
echo "### Version $VERSION"
7878

7979
# Iterate over the commit messages and ignore the ones that start with "Merge" or "Bump"
80-
git log --pretty=format:"%s" $REFERENCE..@ | grep -Ev "(^Merge )|(^Bump)" | sed 's/^\(.*\)/- \1/g'
80+
git log --pretty=format:"%s" $REFERENCE..@ | grep -Ev "(^Merge )|(^Bump)|(no-relnote)" | sed 's/^\(.*\)/- \1/g'

hack/package-helm-charts.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
set -o pipefail
1818

19+
# if arg1 is set, it will be used as the version number
20+
if [ -z "$1" ]; then
21+
VERSION=$(awk -F= '/^VERSION/ { print $2 }' versions.mk | tr -d '[:space:]')
22+
else
23+
VERSION=$1
24+
fi
25+
VERSION=${VERSION#v}
26+
1927
# Create temporary directory for GFD Helm chart
2028
rm -rf deployments/helm/gpu-feature-discovery
2129
mkdir -p deployments/helm/gpu-feature-discovery
@@ -24,5 +32,5 @@ yq e -i '.devicePlugin.enabled = false | .gfd.enabled = true' deployments/helm/
2432
yq e -i '.name = "gpu-feature-discovery" | .description = "A Helm chart for gpu-feature-discovery on Kubernetes"' deployments/helm/gpu-feature-discovery/Chart.yaml
2533

2634
# Create release assets to be uploaded
27-
helm package deployments/helm/gpu-feature-discovery/
28-
helm package deployments/helm/nvidia-device-plugin/
35+
helm package deployments/helm/gpu-feature-discovery/ --version $VERSION --app-version $VERSION
36+
helm package deployments/helm/nvidia-device-plugin/ --version $VERSION --app-version $VERSION

hack/prepare-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Options:
2828
2929
Example:
3030
31-
$this v0.15.0
31+
$this {{ VERSION }}
3232
3333
EOF
3434
}

hack/update-helm-index.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash -e
2+
3+
# Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o pipefail
18+
19+
this=`basename $0`
20+
21+
usage () {
22+
cat << EOF
23+
Usage: $this [-h]
24+
25+
Options:
26+
--helm-repo-path specify the path to the Helm repo (defaults to HELM_REPO_PATH)
27+
--help/-h show help for this command and exit
28+
29+
Example:
30+
- from a local path:
31+
$this /path/to/nvidia-device-plugin-{{ VERSION }}.tgz
32+
- from a URL:
33+
$this https://github.com/NVIDIA/k8s-device-plugin/archive/refs/tags/nvidia-device-plugin-{{ VERSION }}.tgz
34+
35+
EOF
36+
}
37+
38+
#
39+
# Parse command line
40+
#
41+
while [[ $# -gt 0 ]]; do
42+
key="$1"
43+
case $key in
44+
--helm-repo-path)
45+
HELM_REPO_PATH="$2"
46+
shift 2
47+
break
48+
;;
49+
--help/h) usage
50+
exit 0
51+
;;
52+
esac
53+
done
54+
55+
if [ -z "${HELM_REPO_PATH}" ]; then
56+
echo "helm repo path not specified"
57+
usage
58+
exit 1
59+
fi
60+
61+
# now we take the input from the user and check if is a path or url http/https
62+
asset_path="$@"
63+
64+
if [ -z "$asset_path" ]; then
65+
echo "No assets provided"
66+
usage
67+
exit 1
68+
fi
69+
70+
if [[ $asset_path =~ ^https?:// ]]; then
71+
asset_urls=$asset_path
72+
else
73+
asset_local=$asset_path
74+
fi
75+
76+
GH_REPO_PULL_URL="https://github.com/NVIDIA/k8s-device-plugin.git"
77+
git clone --depth=1 --branch=gh-pages ${GH_REPO_PULL_URL} ${HELM_REPO_PATH}
78+
mkdir -p ${HELM_REPO_PATH}/stable
79+
80+
# Charts are local, no need to download
81+
if [ -n "$asset_local" ]; then
82+
echo "Copying $asset_local..."
83+
cp -f $asset_local $HELM_REPO_PATH/stable
84+
else
85+
# Download charts from release assets
86+
for asset_url in $asset_urls; do
87+
if ! echo "$asset_url" | grep -q '.*tgz$'; then
88+
echo "Skipping $asset_url, does not look like a Helm chart archive"
89+
continue
90+
fi
91+
echo "Downloading $asset_url..."
92+
curl -sSfLO -o $HELM_REPO_PATH/stable/$(basename $asset_url) $asset_url
93+
# We rely on all release assets having the same baseurl
94+
download_baseurl=`dirname $HELM_REPO_PATH/stable/$(basename $asset_url)`
95+
done
96+
if [ -z "$download_baseurl" ]; then
97+
echo "No Helm chart release assets found"
98+
exit 0
99+
fi
100+
fi
101+
102+
echo "Updating helm index"
103+
helm repo index $HELM_REPO_PATH/stable --merge $HELM_REPO_PATH/stable/index.yaml --url https://nvidia.github.io/k8s-device-plugin/stable
104+
cp -f $HELM_REPO_PATH/stable/index.yaml $HELM_REPO_PATH/index.yaml
105+
106+
changes=$( git -C $HELM_REPO_PATH status --short )
107+
108+
# Check if there were any changes in the repo
109+
if [ -z "${changes}" ]; then
110+
echo "No changes in Helm repo index, gh-pages branch already up-to-date"
111+
exit 0
112+
fi
113+
114+
VERSION=$( echo "${changes}" | grep -v index | grep -oE "\-[0-9\.]+(\-[\-\.rc0-9]+)?.tgz" | sort -u )
115+
VERSION=${VERSION#-}
116+
VERSION=${VERSION%.tgz}
117+
118+
if [ -z "${VERSION}" ]; then
119+
echo "Could not extract version information"
120+
exit 1
121+
fi
122+
123+
VERSION="v$VERSION"
124+
125+
# Create a new commit
126+
echo "Committing changes..."
127+
git -C $HELM_REPO_PATH add index.yaml stable
128+
129+
cat <<EOF | git -C $HELM_REPO_PATH commit --signoff -F -
130+
Add packages for ${VERSION} release
131+
132+
This adds the following packages to the NVIDIA GPU Device Plugin Helm repo:
133+
$( git -C $HELM_REPO_PATH diff HEAD --name-only | grep -v index | sed 's#stable/#* #g' | sort -r )
134+
135+
Note: This is an automated commit.
136+
137+
EOF
138+
139+
echo "gh-pages branch successfully updated"

0 commit comments

Comments
 (0)