Skip to content

Commit

Permalink
Handle multiple tags on the same commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tnozicka committed Sep 15, 2021
1 parent 8c31706 commit 2a3f4cf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ jobs:
with:
path: ${{ env.git_repo_path }}
fetch-depth: 0
- name: Setup git tags
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./hack/ci-detect-tags.sh
- name: Setup go
uses: actions/setup-go@v2
with:
Expand All @@ -101,6 +104,9 @@ jobs:
with:
path: ${{ env.git_repo_path }}
fetch-depth: 0 # also fetch tags
- name: Setup git tags
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./hack/ci-detect-tags.sh
- name: Install podman
run: |
set -x
Expand Down Expand Up @@ -135,6 +141,9 @@ jobs:
with:
path: ${{ env.git_repo_path }}
fetch-depth: 0 # also fetch tags
- name: Setup git tags
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./hack/ci-detect-tags.sh
- name: Create artifacts dir
env:
ARTIFACTS_DIR: ${{ runner.temp }}/e2e-artifacts
Expand Down Expand Up @@ -254,6 +263,9 @@ jobs:
path: ${{ env.git_repo_path }}
# Helm Chart version needs to be semantic, we need tags in checked out repo to determine latest one.
fetch-depth: 0
- name: Setup git tags
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: ./hack/ci-detect-tags.sh
- name: Setup go
uses: actions/setup-go@v2
with:
Expand All @@ -262,14 +274,14 @@ jobs:
if: ${{ github.event_name != 'schedule' }}
run: |
source ./hack/lib/tag-from-gh-ref.sh
IMAGE_TAG=$( tag_from_gh_ref "${GITHUB_REF}" )
echo "IMAGE_TAG=${IMAGE_TAG}" | tee -a ${GITHUB_ENV}
CI_IMAGE_TAG=$( tag_from_gh_ref "${GITHUB_REF}" )
echo "CI_IMAGE_TAG=${CI_IMAGE_TAG}" | tee -a ${GITHUB_ENV}
- name: Determine promotion tag for scheduled job
if: ${{ github.event_name == 'schedule' }}
run: |
IMAGE_TAG=nightly
echo "IMAGE_TAG=${IMAGE_TAG}" | tee -a ${GITHUB_ENV}
echo "HELM_CHART_VERSION_SUFFIX=-${IMAGE_TAG}" | tee -a ${GITHUB_ENV}
CI_IMAGE_TAG=nightly
echo "CI_IMAGE_TAG=${CI_IMAGE_TAG}" | tee -a ${GITHUB_ENV}
echo "HELM_CHART_VERSION_SUFFIX=-${CI_IMAGE_TAG}" | tee -a ${GITHUB_ENV}
- uses: actions/download-artifact@v2
with:
name: operatorimage.tar.lz4
Expand All @@ -289,16 +301,16 @@ jobs:
- name: Promote image
run: |
set -x
docker tag '${{ env.image_repo_ref }}:ci' '${{ env.image_repo_ref }}:${{ env.IMAGE_TAG }}'
docker push '${{ env.image_repo_ref }}:${{ env.IMAGE_TAG }}'
docker tag '${{ env.image_repo_ref }}:ci' '${{ env.image_repo_ref }}:${{ env.CI_IMAGE_TAG }}'
docker push '${{ env.image_repo_ref }}:${{ env.CI_IMAGE_TAG }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@master
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
- name: Publish Helm Chart
env:
HELM_CHANNEL: latest
HELM_APP_VERSION: ${{ env.IMAGE_TAG }}
HELM_APP_VERSION: ${{ env.CI_IMAGE_TAG }}
run: make helm-publish

failure-notifications:
Expand Down
21 changes: 21 additions & 0 deletions hack/ci-detect-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
#
# Copyright (C) 2021 ScyllaDB
#
# This script will set appropriate tag variables in the CI environment.
# Multiple tags can point to one commit which makes `git describe` ambiguous
# for the purposes of promotion. Like when vX.Y.Z-beta.0 and vX.Y.Z-rc.0 point
# to the same commit. Git describe could return any of those and even if it would
# return the newest, the job order is not determined either. And jobs can be rerun
# which would make the beta job promoting to rc.0.
set -euExo pipefail
shopt -s inherit_errexit

parent_dir=$( dirname "${BASH_SOURCE[0]}" )
source "${parent_dir}/lib/tag-from-gh-ref.sh"

tag=$( tag_from_gh_ref "${GITHUB_REF}" )
git_sha=$( git rev-parse --short=7 "HEAD^{commit}" )

echo "GIT_TAG=${tag}-0-g${git_sha}" | tee -a ${GITHUB_ENV}
echo "GIT_TAG_SHORT=${tag}" | tee -a ${GITHUB_ENV}

0 comments on commit 2a3f4cf

Please sign in to comment.