-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from e0ne/auto-release
Add 'prepare-release.sh' script
- Loading branch information
Showing
3 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/bin/bash -e | ||
# Copyright 2021 NVIDIA | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o pipefail | ||
|
||
this=`basename $0` | ||
|
||
usage () { | ||
cat << EOF | ||
Usage: $this [-h] [-p remote name] RELEASE_VERSION GPG_KEY | ||
Options: | ||
-h show this help and exit | ||
-p REMOTE do git push to remote repo | ||
Example: | ||
$this v0.1.2 "Jane Doe <jane.doe@example.com>" | ||
NOTE: The GPG key should be associated with the signer's Github account. | ||
EOF | ||
} | ||
|
||
sign_helm_chart() { | ||
local chart="$1" | ||
echo "Signing Helm chart $chart" | ||
local sha256=`openssl dgst -sha256 "$chart" | awk '{ print $2 }'` | ||
local yaml=`tar xf $chart -O network-operator/Chart.yaml` | ||
echo "$yaml | ||
... | ||
files: | ||
$chart: sha256:$sha256" | gpg -u "$key" --clearsign -o "$chart.prov" | ||
} | ||
|
||
# | ||
# Parse command line | ||
# | ||
while getopts "h" opt; do | ||
case $opt in | ||
h) usage | ||
exit 0 | ||
;; | ||
p) push_remote="$OPTARG" | ||
;; | ||
*) usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift "$((OPTIND - 1))" | ||
|
||
# Check that no extra args were provided | ||
if [ $# -ne 2 ]; then | ||
if [ $# -lt 2 ]; then | ||
echo -e "ERROR: too few arguments\n" | ||
else | ||
echo -e "ERROR: unknown arguments: ${@:3}\n" | ||
fi | ||
usage | ||
exit 1 | ||
fi | ||
|
||
release=$1 | ||
key="$2" | ||
shift 2 | ||
|
||
container_image=k8s.gcr.io/nfd/node-feature-discovery:$release | ||
|
||
# | ||
# Check/parse release number | ||
# | ||
if [ -z "$release" ]; then | ||
echo -e "ERROR: missing RELEASE_VERSION\n" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
if [[ $release =~ ^(v[0-9]+\.[0-9]+)(\..+)?$ ]]; then | ||
docs_version=${BASH_REMATCH[1]} | ||
semver=${release:1} | ||
else | ||
echo -e "ERROR: invalid RELEASE_VERSION '$release'" | ||
exit 1 | ||
fi | ||
|
||
## Patch deployment files | ||
sed -e s"/image:.*/image: mellanox\/network-operator:$release/" \ | ||
-i deploy/operator.yaml | ||
|
||
# Patch Helm chart | ||
chart=`echo $release | cut -c 2-` | ||
sed -e s"/appVersion:.*/appVersion: $release/" \ | ||
-e s"/^version:.*/version: $chart/" \ | ||
-i deployment/network-operator/Chart.yaml | ||
sed -e s"/pullPolicy:.*/pullPolicy: IfNotPresent/" \ | ||
-i deployment/network-operator/values.yaml | ||
|
||
# Commit changes | ||
git add . | ||
git commit -S -m "Release $release" | ||
|
||
if [ -n "$push_remote" ]; then | ||
echo "Pushing gh-pages to $push_remote" | ||
git push "$push_remote" gh-pages | ||
|
||
fi | ||
|
||
# | ||
# Create release assets to be uploaded | ||
# | ||
helm package deployment/network-operator/ --version $semver | ||
|
||
chart_name="network-operator-$semver.tgz" | ||
sign_helm_chart $chart_name | ||
|
||
cat << EOF | ||
******************************************************************************* | ||
*** Please manually upload the following generated files to the Github release | ||
*** page: | ||
*** | ||
*** $chart_name | ||
*** $chart_name.prov | ||
*** | ||
******************************************************************************* | ||
EOF | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash -e | ||
# Copyright 2021 NVIDIA | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o pipefail | ||
|
||
this=`basename $0` | ||
|
||
usage () { | ||
cat << EOF | ||
Usage: $this [-h] [-p remote name] <helm-chart> | ||
Options: | ||
-h show this help and exit | ||
-p REMOTE do git push to remote repo | ||
EOF | ||
} | ||
|
||
# | ||
# Argument parsing | ||
# | ||
while getopts "hap:" opt; do | ||
case $opt in | ||
h) usage | ||
exit 0 | ||
;; | ||
p) push_remote="$OPTARG" | ||
;; | ||
*) usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Check that no extra args were provided | ||
if [ $# -ne 1 ]; then | ||
echo "ERROR: extra positional arguments: $@" | ||
usage | ||
exit 1 | ||
fi | ||
|
||
exit 2 | ||
chart="$1" | ||
release=${chart::-4} | ||
|
||
build_dir="/tmp/network-operator-build" | ||
|
||
src_dir=$(pwd) | ||
|
||
git worktree add $build_dir origin/gh-pages | ||
|
||
# Drop worktree on exit | ||
trap "echo 'Removing Git worktree $build_dir'; git worktree remove '$build_dir'" EXIT | ||
|
||
# Update Helm package index | ||
mv $chart $build_dir/release | ||
cd $build_dir/release | ||
helm repo index . --url https://mellanox.github.io/network-operator/release --merge ./index.yaml | ||
|
||
# Commit change | ||
commit_msg="Release $release" | ||
git add . | ||
git commit -S -m "$commit_msg" | ||
|
||
if [ -n "$push_remote" ]; then | ||
echo "Pushing gh-pages to $push_remote" | ||
git push "$push_remote" gh-pages | ||
|
||
fi |