From 6620006cbab80bb3dc050aac4886e9d6f28b46dd Mon Sep 17 00:00:00 2001 From: Roger Barker Date: Thu, 24 Oct 2024 22:10:17 -0500 Subject: [PATCH] ci: Fix bug with deleting xts-candidate tag prior to creation or use (#16159) Signed-off-by: Roger Barker --- .../workflows/zxcron-extended-test-suite.yaml | 30 ++++++++++++++----- .../zxf-prepare-extended-test-suite.yaml | 10 ++++--- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.github/workflows/zxcron-extended-test-suite.yaml b/.github/workflows/zxcron-extended-test-suite.yaml index 205169daef71..20057643f658 100644 --- a/.github/workflows/zxcron-extended-test-suite.yaml +++ b/.github/workflows/zxcron-extended-test-suite.yaml @@ -64,16 +64,31 @@ jobs: - name: Check for tags id: check-tags-exist run: | - XTS_COMMIT=$(git rev-list -n 1 "${XTS_CANDIDATE_TAG}") + # Check if the tag exists and if so grab its commit id + set +e + XTS_COMMIT=$(git rev-list -n 1 "${XTS_CANDIDATE_TAG}") >/dev/null 2>&1 + XTS_COMMIT_FOUND="${?}" + set -e + + # Cancel out if the tag does not exist + if [[ "${XTS_COMMIT_FOUND}" -ne 0 ]]; 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 BRANCH_ON_DEVELOP="${?}" set -e - if [[ -n "${XTS_COMMIT}" && "${BRANCH_ON_DEVELOP}" -eq 0 ]]; then + + # If the tag exists on the Develop Branch set the output variables as appropriate + # Otherwise cancel out + if [[ "${BRANCH_ON_DEVELOP}" -eq 0 ]]; then echo "xts-tag-exists=true" >> $GITHUB_OUTPUT echo "xts-tag-commit=${XTS_COMMIT}" >> $GITHUB_OUTPUT echo "### Commit has been tagged as an XTS-Candidate" >> $GITHUB_STEP_SUMMARY echo "xts-tag-commit=${XTS_COMMIT}" >> $GITHUB_STEP_SUMMARY + git push --delete origin "${XTS_CANDIDATE_TAG}" git tag -d "${XTS_CANDIDATE_TAG}" else @@ -152,14 +167,13 @@ jobs: name: Tag as XTS-Passing runs-on: network-node-linux-medium needs: -# - abbreviated-panel + - abbreviated-panel - extended-test-suite - fetch-xts-candidate -# - hedera-node-jrs-panel -# if: ${{ needs.abbreviated-panel.result == 'success' || -# needs.extended-test-suite.result == 'success' || -# needs.hedera-node-jrs-panel.result == 'success' }} - if: ${{ needs.extended-test-suite.result == 'success' }} + - hedera-node-jrs-panel + if: ${{ needs.abbreviated-panel.result == 'success' || + needs.extended-test-suite.result == 'success' || + needs.hedera-node-jrs-panel.result == 'success' }} steps: - name: Harden Runner uses: step-security/harden-runner@f086349bfa2bd1361f7909c78558e816508cdc10 # v2.8.0 diff --git a/.github/workflows/zxf-prepare-extended-test-suite.yaml b/.github/workflows/zxf-prepare-extended-test-suite.yaml index 80513acd4a2c..e3be9509ca48 100644 --- a/.github/workflows/zxf-prepare-extended-test-suite.yaml +++ b/.github/workflows/zxf-prepare-extended-test-suite.yaml @@ -82,17 +82,19 @@ jobs: # move the tag if successful - name: Tag Code and push run: | - XTS_COMMIT=$(git rev-list -n 1 "${XTS_CANDIDATE_TAG}") + # Check if the tag exists set +e - git branch --contains "${XTS_COMMIT}" | grep --quiet develop >/dev/null 2>&1 - BRANCH_ON_DEVELOP="${?}" + git rev-list -n 1 "${XTS_CANDIDATE_TAG}" >/dev/null 2>&1 + XTS_COMMIT_FOUND="${?}" set -e - if [[ -n "${XTS_COMMIT}" && "${BRANCH_ON_DEVELOP}" -eq 0 ]]; then + # Delete the tag if it does exist + if [[ "${XTS_COMMIT_FOUND}" -eq 0 ]]; then git push --delete origin "${XTS_CANDIDATE_TAG}" git tag -d "${XTS_CANDIDATE_TAG}" fi + # Create the new tag git tag --annotate "${XTS_CANDIDATE_TAG}" --message "chore: tagging commit for XTS promotion" git push --set-upstream origin --tags