From 132f1fd3a8fd55426cff6aa4d94096926a91ba9e Mon Sep 17 00:00:00 2001 From: Nolan Brubaker Date: Tue, 1 Oct 2019 14:04:57 -0400 Subject: [PATCH] Prevent master from being tagged as latest (#1922) By default, git does not fetch tags on a checkout, so fetch those when building a tag. When the tags are not fetched and building master, both HIGHEST and LATEST_TAG were "", which was equal. Thus, every master push was tagged as latest. This is now handled correctly. Signed-off-by: Nolan Brubaker --- hack/gcr-push.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hack/gcr-push.sh b/hack/gcr-push.sh index c7fa4f908..8001b24b3 100755 --- a/hack/gcr-push.sh +++ b/hack/gcr-push.sh @@ -47,24 +47,34 @@ function highest_release() { done } -if [ "$BRANCH" == "master" ]; then +if [[ "$BRANCH" == "master" ]]; then VERSION="$BRANCH" -elif [ ! -z "$TRAVIS_TAG" ]; then +elif [[ ! -z "$TRAVIS_TAG" ]]; then + # Tags aren't fetched by Travis on checkout, and we don't need them for master + git fetch --tags + # Calculate the latest release if there's a tag. + highest_release VERSION="$TRAVIS_TAG" else # If we're not on master and we're not building a tag, exit early. exit 0 fi -# Calculate the latest release -highest_release -# Assume we're not tagging `latest` by default. +# Assume we're not tagging `latest` by default, and never on master. TAG_LATEST=false -if [[ "$TRAVIS_TAG" == "$HIGHEST" ]]; then +if [[ "$BRANCH" == "master" ]]; then + echo "Building master, not tagging latest." +elif [[ "$TRAVIS_TAG" == "$HIGHEST" ]]; then TAG_LATEST=true fi +# Debugging info +echo "Highest tag found: $HIGHEST" +echo "BRANCH: $BRANCH" +echo "TRAVIS_TAG: $TRAVIS_TAG" +echo "TAG_LATEST: $TAG_LATEST" + openssl aes-256-cbc -K $encrypted_f58ab4413c21_key -iv $encrypted_f58ab4413c21_iv -in heptio-images-fac92d2303ac.json.enc -out heptio-images-fac92d2303ac.json -d gcloud auth activate-service-account --key-file heptio-images-fac92d2303ac.json gcloud auth configure-docker -q