|
| 1 | +#!/bin/bash -e |
| 2 | +# Copyright 2021 NVIDIA |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -o pipefail |
| 17 | + |
| 18 | +this=`basename $0` |
| 19 | + |
| 20 | +usage () { |
| 21 | +cat << EOF |
| 22 | +Usage: $this [-h] [-p remote name] RELEASE_VERSION GPG_KEY |
| 23 | +
|
| 24 | +Options: |
| 25 | + -h show this help and exit |
| 26 | + -p REMOTE do git push to remote repo |
| 27 | +
|
| 28 | +Example: |
| 29 | +
|
| 30 | + $this v0.1.2 "Jane Doe <[email protected]>" |
| 31 | +
|
| 32 | +
|
| 33 | +NOTE: The GPG key should be associated with the signer's Github account. |
| 34 | +EOF |
| 35 | +} |
| 36 | + |
| 37 | +sign_helm_chart() { |
| 38 | + local chart="$1" |
| 39 | + echo "Signing Helm chart $chart" |
| 40 | + local sha256=`openssl dgst -sha256 "$chart" | awk '{ print $2 }'` |
| 41 | + local yaml=`tar xf $chart -O network-operator/Chart.yaml` |
| 42 | + echo "$yaml |
| 43 | +... |
| 44 | +files: |
| 45 | + $chart: sha256:$sha256" | gpg -u "$key" --clearsign -o "$chart.prov" |
| 46 | +} |
| 47 | + |
| 48 | +# |
| 49 | +# Parse command line |
| 50 | +# |
| 51 | +while getopts "h" opt; do |
| 52 | + case $opt in |
| 53 | + h) usage |
| 54 | + exit 0 |
| 55 | + ;; |
| 56 | + p) push_remote="$OPTARG" |
| 57 | + ;; |
| 58 | + *) usage |
| 59 | + exit 1 |
| 60 | + ;; |
| 61 | + esac |
| 62 | +done |
| 63 | +shift "$((OPTIND - 1))" |
| 64 | + |
| 65 | +# Check that no extra args were provided |
| 66 | +if [ $# -ne 2 ]; then |
| 67 | + if [ $# -lt 2 ]; then |
| 68 | + echo -e "ERROR: too few arguments\n" |
| 69 | + else |
| 70 | + echo -e "ERROR: unknown arguments: ${@:3}\n" |
| 71 | + fi |
| 72 | + usage |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +release=$1 |
| 77 | +key="$2" |
| 78 | +shift 2 |
| 79 | + |
| 80 | +container_image=k8s.gcr.io/nfd/node-feature-discovery:$release |
| 81 | + |
| 82 | +# |
| 83 | +# Check/parse release number |
| 84 | +# |
| 85 | +if [ -z "$release" ]; then |
| 86 | + echo -e "ERROR: missing RELEASE_VERSION\n" |
| 87 | + usage |
| 88 | + exit 1 |
| 89 | +fi |
| 90 | + |
| 91 | +if [[ $release =~ ^(v[0-9]+\.[0-9]+)(\..+)?$ ]]; then |
| 92 | + docs_version=${BASH_REMATCH[1]} |
| 93 | + semver=${release:1} |
| 94 | +else |
| 95 | + echo -e "ERROR: invalid RELEASE_VERSION '$release'" |
| 96 | + exit 1 |
| 97 | +fi |
| 98 | + |
| 99 | +## Patch deployment files |
| 100 | +sed -e s"/image:.*/image: mellanox\/network-operator:$release/" \ |
| 101 | + -i deploy/operator.yaml |
| 102 | + |
| 103 | +# Patch Helm chart |
| 104 | +chart=`echo $release | cut -c 2-` |
| 105 | +sed -e s"/appVersion:.*/appVersion: $release/" \ |
| 106 | + -e s"/^version:.*/version: $chart/" \ |
| 107 | + -i deployment/network-operator/Chart.yaml |
| 108 | +sed -e s"/pullPolicy:.*/pullPolicy: IfNotPresent/" \ |
| 109 | + -i deployment/network-operator/values.yaml |
| 110 | + |
| 111 | +# Commit changes |
| 112 | +git add . |
| 113 | +git commit -S -m "Release $release" |
| 114 | + |
| 115 | +if [ -n "$push_remote" ]; then |
| 116 | + echo "Pushing gh-pages to $push_remote" |
| 117 | + git push "$push_remote" gh-pages |
| 118 | + |
| 119 | +fi |
| 120 | + |
| 121 | +# |
| 122 | +# Create release assets to be uploaded |
| 123 | +# |
| 124 | +helm package deployment/network-operator/ --version $semver |
| 125 | + |
| 126 | +chart_name="network-operator-$semver.tgz" |
| 127 | +sign_helm_chart $chart_name |
| 128 | + |
| 129 | +cat << EOF |
| 130 | +
|
| 131 | +******************************************************************************* |
| 132 | +*** Please manually upload the following generated files to the Github release |
| 133 | +*** page: |
| 134 | +*** |
| 135 | +*** $chart_name |
| 136 | +*** $chart_name.prov |
| 137 | +*** |
| 138 | +******************************************************************************* |
| 139 | +EOF |
| 140 | + |
0 commit comments