Skip to content

Commit

Permalink
Merge pull request #149 from e0ne/auto-release
Browse files Browse the repository at this point in the history
Add 'prepare-release.sh' script
  • Loading branch information
moshe010 authored Mar 30, 2021
2 parents 2935f8f + 2c20284 commit 872004a
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/new-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ Please do not remove items from the checklist
- [ ] Manifest related component default versions
- [ ] Example folder is up to date (otherwise submit PR to update)
- [ ] Update network-operator Helm `Chart.yaml` with the release version (`appVersion`, `version` fields)
```
> ./scripts/releases/prepare-release.sh v0.1.2 "Jane Doe <jane.doe@example.com>"
```
- [ ] Ensure Helm CI is passing on updated Chart.
- [ ] Tag release
- [ ] Create a new github release
- [ ] Release title: vx.y.z, Release description: Changelog from this issue
- [ ] Release artifacts for current release
- [ ] Update gh-pages branch
```
> ./scripts/releases/update-gh-pages.sh network-operator-0.1.2.tgz
```
- [ ] Create Helm package (master branch on release tag commit):
```
> helm package deployment/network-operator
Expand Down
140 changes: 140 additions & 0 deletions scripts/releases/prepare-release.sh
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

80 changes: 80 additions & 0 deletions scripts/releases/update-gh-pages.sh
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

0 comments on commit 872004a

Please sign in to comment.