From f3e29f7450ec41848058c09d0a2c3adb4f6f484a Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 20 Feb 2019 11:07:26 -0800 Subject: [PATCH] hack: fix release scripts (#157) Previous release script wasn't committing/tagging in the right order. Also made scripts resistant to: * empty env vars * current workdir the script is invoked from cc: @m-okeefe --- hack/make-docker-images.sh | 4 ++-- hack/make-release-artifacts.sh | 4 ++-- hack/make-release.sh | 25 +++++++++++++++++-------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/hack/make-docker-images.sh b/hack/make-docker-images.sh index cd4cc63..69afd0f 100755 --- a/hack/make-docker-images.sh +++ b/hack/make-docker-images.sh @@ -21,8 +21,8 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" log() { echo "$1" >&2; } -TAG="${TAG?TAG env variable must be specified}" -REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}" +TAG="${TAG:?TAG env variable must be specified}" +REPO_PREFIX="${REPO_PREFIX:?REPO_PREFIX env variable must be specified}" while IFS= read -d $'\0' -r dir; do # build image diff --git a/hack/make-release-artifacts.sh b/hack/make-release-artifacts.sh index 213472b..2a14ae5 100755 --- a/hack/make-release-artifacts.sh +++ b/hack/make-release-artifacts.sh @@ -23,8 +23,8 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" log() { echo "$1" >&2; } -TAG="${TAG?TAG env variable must be specified}" -REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}" +TAG="${TAG:?TAG env variable must be specified}" +REPO_PREFIX="${REPO_PREFIX:?REPO_PREFIX env variable must be specified}" OUT_DIR="${OUT_DIR:-${SCRIPTDIR}/../release}" read_manifests() { diff --git a/hack/make-release.sh b/hack/make-release.sh index ff49ff4..04fb276 100755 --- a/hack/make-release.sh +++ b/hack/make-release.sh @@ -14,28 +14,37 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Creates a new release by 1) building/pushing images, 2) injecting tag into YAML, -# 3) creating a new git tag, and 4) pushing tags/updated YAML to $BRANCH. +# This script creates a new release by: +# - 1. building/pushing images +# - 2. injecting tags into YAML manifests +# - 3. creating a new git tag +# - 4. pushing the tag/commit to master. set -euo pipefail +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +[[ -n "${DEBUG:-}" ]] && set -x log() { echo "$1" >&2; } fail() { log "$1"; exit 1; } -TAG="${TAG?TAG env variable must be specified}" -REPO_PREFIX="${REPO_PREFIX?REPO_PREFIX env variable must be specified}" +TAG="${TAG:?TAG env variable must be specified}" +REPO_PREFIX="${REPO_PREFIX:?REPO_PREFIX env variable must be specified e.g. gcr.io\/google-samples\/microservices-demo}" + +if [[ "$TAG" != v* ]]; then + fail "\$TAG must start with 'v', e.g. v0.1.0 (got: $TAG)" +fi # build and push images -./hack/make-docker-images.sh +"${SCRIPTDIR}"/make-docker-images.sh # update yaml -./hack/make-release-artifacts.sh +"${SCRIPTDIR}"/make-release-artifacts.sh # create git release / push to master +git add "${SCRIPTDIR}/../release/" +git commit --allow-empty -m "Release $TAG" log "Pushing k8s manifests to master..." git tag "$TAG" -git add release/ -git commit --allow-empty -m "Release $TAG" git push --tags git push origin master