Skip to content

Commit

Permalink
ci: Update the XTS workflows to prevent double tagging on commits (#1…
Browse files Browse the repository at this point in the history
…6330)

Signed-off-by: Roger Barker <[email protected]>
  • Loading branch information
rbarkerSL authored Oct 31, 2024
1 parent a1e9414 commit 2bb9c6c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/zxcron-extended-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ defaults:

env:
XTS_CANDIDATE_TAG: "xts-candidate"
XTS_PASS_GREP_PATTERN: "xts-pass-*"
PROMOTED_GREP_PATTERN: "build-.{5}"

jobs:
fetch-xts-candidate:
Expand Down Expand Up @@ -65,6 +67,8 @@ jobs:
id: check-tags-exist
env:
GH_TOKEN: ${{ github.token }}
XTS_PASS_PATTERN: ${{ env.XTS_PASS_GREP_PATTERN }}
BUILD_PROMO_PATTERN: ${{ env.PROMOTED_GREP_PATTERN }}
run: |
# Check if the tag exists and if so grab its commit id
set +e
Expand All @@ -77,6 +81,17 @@ jobs:
gh run cancel ${{ github.run_id }}
fi
# Check if this commit has already been tagged xts-pass-* or build-*
set +e
XTS_PASS_TAGGED=$(git tag --contains "${XTS_COMMIT}" | grep -E "${XTS_PASS_PATTERN}")
BUILD_PROMOTED_TAGGED=$(git tag --contains "${XTS_COMMIT}" | grep -E "${BUILD_PROMO_PATTERN}")
set -e
# Use -n; if the BUILD_PROMOTED_TAGGED/XTS_PASS_TAGGED flags are not empty than the commit has been tagged.
if [[ -n "${XTS_PASS_TAGGED}" || -n "${BUILD_PROMOTED_TAGGED}" ]]; then
gh run cancel ${{ github.run_id }}
fi
# Check if the tag exists on the develop branch
set +e
git branch --contains "${XTS_COMMIT}" | grep --quiet develop >/dev/null 2>&1
Expand Down
19 changes: 17 additions & 2 deletions .github/workflows/zxcron-promote-build-candidate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ on:

permissions:
actions: write
contents: read
contents: write
statuses: write

defaults:
run:
shell: bash

env:
XTS_PASS_GREP_PATTERN: "xts-pass-*"
PROMOTED_GREP_PATTERN: "build-.{5}"

jobs:
determine-build-candidate:
name: Fetch Latest Build Candidate
Expand All @@ -55,11 +59,22 @@ jobs:
id: find-build-candidates
env:
GH_TOKEN: ${{ github.token }}
TAG_PATTERN: ${{ env.XTS_PASS_GREP_PATTERN }}
BUILD_PROMO_PATTERN: ${{ env.PROMOTED_GREP_PATTERN }}
run: |
TAG_PATTERN="xts-pass-*"
CANDIDATE_TAG="$(git tag --list --sort=-version:refname "${TAG_PATTERN}" | head --lines 1)"
if [[ -n "${CANDIDATE_TAG}" ]]; then
set +e
CANDIDATE_COMMIT=$(git rev-list --max-count 1 ${CANDIDATE_TAG})
BUILD_PROMOTED_TAGGED=$(git tag --contains "${CANDIDATE_COMMIT}" | grep -E "${BUILD_PROMO_PATTERN}")
set -e
# Use -n; if the BUILD_PROMOTED_TAGGED flag is not empty than the commit has been tagged.
if [[ -n "${BUILD_PROMOTED_TAGGED}" ]]; then
gh run cancel ${{ github.run_id }}
fi
# Verify the commit is on develop and continue
if git branch --contains "${CANDIDATE_COMMIT}" | grep --quiet develop >/dev/null 2>&1; then
git push --delete origin $(git tag --list "${TAG_PATTERN}")
git tag --delete $(git tag --list "${TAG_PATTERN}")
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/zxf-prepare-extended-test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ defaults:
permissions:
actions: write
contents: write
statuses: write

env:
XTS_CANDIDATE_TAG: "xts-candidate"
XTS_PASS_GREP_PATTERN: "xts-pass-*"
PROMOTED_GREP_PATTERN: "build-.{5}"

jobs:
tag-for-xts:
Expand Down Expand Up @@ -80,8 +83,32 @@ jobs:
gpg_private_key: ${{ secrets.SVCS_GPG_KEY_CONTENTS }}
passphrase: ${{ secrets.SVCS_GPG_KEY_PASSPHRASE }}

# Check if this commit is already tagged in the XTS flow
- name: Check if XTS flow is required
id: check-xts-required
env:
GH_TOKEN: ${{ github.token }}
CANDIDATE_PATTERN: ${{ env.XTS_CANDIDATE_TAG }}
XTS_PASS_PATTERN: ${{ env.XTS_PASS_GREP_PATTERN }}
BUILD_PROMO_PATTERN: ${{ env.PROMOTED_GREP_PATTERN }}
run: |
set +e
# Check if the HEAD ref is already tagged in the XTS workflows
XTS_CANDIDATE_TAGGED=$(git tag --contains HEAD | grep -E "${CANDIDATE_PATTERN}")
XTS_PASS_TAGGED=$(git tag --contains HEAD | grep -E "${XTS_PASS_PATTERN}")
BUILD_PROMOTED_TAGGED=$(git tag --contains HEAD | grep -E "${BUILD_PROMO_PATTERN}")
set -e
# if the strings are not empty than the commit has been tagged.
if [[ -n "${XTS_CANDIDATE_TAGGED}" || -n "${XTS_PASS_TAGGED}" || -n "${BUILD_PROMOTED_TAGGED}" ]]; then
gh run cancel ${{ github.run_id }}
else
echo "xts-checks-required=true" >> $GITHUB_OUTPUT
fi
# move the tag if successful
- name: Tag Code and push
if: ${{ steps.check-xts-required.outputs.xts-checks-required == 'true' }}
run: |
# Check if the tag exists
set +e
Expand Down

0 comments on commit 2bb9c6c

Please sign in to comment.