From d8c5f459de446d05471b07fa075aa792086c38cd Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Mon, 26 Jul 2021 15:35:08 -0600 Subject: [PATCH] build: publish and promote with correct branch name The tagged builds will run git checkout on the correct tag, though the publish and promote actions expect a branch name to be available due to internal build assumptions. Now the publish looks up the branch name from the tag and passes it to the publish command as expected. Signed-off-by: Travis Nielsen --- .github/workflows/push-build.yaml | 8 ++-- tests/scripts/build-release.sh | 66 +++++++++++++++++++------------ 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/.github/workflows/push-build.yaml b/.github/workflows/push-build.yaml index f71990d45..7bfd73c32 100644 --- a/.github/workflows/push-build.yaml +++ b/.github/workflows/push-build.yaml @@ -19,6 +19,8 @@ jobs: steps: - name: checkout uses: actions/checkout@v2 + with: + fetch-depth: 0 # docker/setup-qemu action installs QEMU static binaries, which are used to run builders for architectures other than the host. - name: set up QEMU @@ -56,8 +58,4 @@ jobs: AWS_PSW: ${{ secrets.AWS_PSW }} GITHUB_REF: $ {{ env.GITHUB_REF }} run: | - if [[ ${GITHUB_REF} =~ master|v ]]; then - tests/scripts/build-release.sh publish_and_promote - else - tests/scripts/build-release.sh publish - fi + tests/scripts/build-release.sh diff --git a/tests/scripts/build-release.sh b/tests/scripts/build-release.sh index a77387784..9dd8fb6a3 100755 --- a/tests/scripts/build-release.sh +++ b/tests/scripts/build-release.sh @@ -5,13 +5,6 @@ set -ex # FUNCTIONS # ############# - -if [[ ${GITHUB_REF} =~ master ]]; then - CHANNEL=master -else - CHANNEL=release -fi - function build() { # set VERSION to a dummy value since Jenkins normally sets it for us. Do this to make Helm happy and not fail with "Error: Invalid Semantic Version" build/run make VERSION=0 build.all @@ -19,28 +12,51 @@ function build() { build/run make mod.check } -function publish_and_promote() { - build - build/run make -C build/release build BRANCH_NAME=${BRANCH_NAME} GIT_API_TOKEN=${GIT_API_TOKEN} - git status & - git diff & - build/run make -C build/release publish BRANCH_NAME=${BRANCH_NAME} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} GIT_API_TOKEN=${GIT_API_TOKEN} - # automatically promote the master builds - build/run make -C build/release promote BRANCH_NAME=${BRANCH_NAME} CHANNEL=${CHANNEL} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} - -} - function publish() { build - build/run make -C build/release build BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=true GIT_API_TOKEN=${GIT_API_TOKEN} + build/run make -C build/release build BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=${TAG_WITH_SUFFIX} GIT_API_TOKEN=${GIT_API_TOKEN} git status & git diff & - build/run make -C build/release publish BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=true AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} GIT_API_TOKEN=${GIT_API_TOKEN} + build/run make -C build/release publish BRANCH_NAME=${BRANCH_NAME} TAG_WITH_SUFFIX=${TAG_WITH_SUFFIX} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} GIT_API_TOKEN=${GIT_API_TOKEN} } -selected_function="$1" -if [ "$selected_function" = "publish_and_promote" ]; then - publish_and_promote -elif [ "$selected_function" = "publish" ]; then - publish +function promote() { + # automatically promote the master builds + echo "Promoting from branch ${BRANCH_NAME}" + build/run make -C build/release promote BRANCH_NAME=${BRANCH_NAME} CHANNEL=${CHANNEL} AWS_ACCESS_KEY_ID=${AWS_USR} AWS_SECRET_ACCESS_KEY=${AWS_PSW} +} + +############# +# MAIN # +############# + +SHOULD_PROMOTE=true +if [[ ${GITHUB_REF} =~ master ]]; then + echo "Publishing from master" + CHANNEL=master +else + echo "Tagging with suffix for release and tagged builds" + TAG_WITH_SUFFIX=true + CHANNEL=release + + # If a tag, find the source release branch + if [[ $BRANCH_NAME = v* ]]; then + TAG_NAME=${BRANCH_NAME} + BRANCH_NAME=$(git branch -r --contain refs/tags/${BRANCH_NAME} | grep "origin/release-." | sed 's/origin\///' | xargs) + if [[ $BRANCH_NAME = "" ]]; then + echo "Branch name not found in tag $TAG_NAME" + exit 1 + fi + echo "Publishing tag ${TAG_NAME} in branch ${BRANCH_NAME}" + else + echo "Publishing from release branch ${BRANCH_NAME}" + SHOULD_PROMOTE=false + fi +fi + + +publish + +if [[ "$SHOULD_PROMOTE" = true ]]; then + promote fi