summaryrefslogtreecommitdiff
path: root/.github
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-05-11 01:30:15 +0300
committerGitHub <noreply@github.com>2026-05-11 01:30:15 +0300
commit0aeb97df8a9c25de7ddca93b508c3840d7634789 (patch)
tree68c5ad8388bbb10bb94c9cd0590382657df9c13e /.github
parentae0e3cb965935e03173721eefb86c1576b70dda9 (diff)
parentc8969d1fdeb2af54076d7a6006da374c5bb8c106 (diff)
downloadvyos-documentation-0aeb97df8a9c25de7ddca93b508c3840d7634789.tar.gz
vyos-documentation-0aeb97df8a9c25de7ddca93b508c3840d7634789.zip
Merge pull request #1966 from vyos/yuriy/backport-update-version-tags-1958-sagitta
ci: backport update-version-tags hardening to sagitta (rolls up #1953 + #1958)
Diffstat (limited to '.github')
-rw-r--r--.github/workflows/update-version-tags.yml86
1 files changed, 71 insertions, 15 deletions
diff --git a/.github/workflows/update-version-tags.yml b/.github/workflows/update-version-tags.yml
index 9cefef61..8a5b838f 100644
--- a/.github/workflows/update-version-tags.yml
+++ b/.github/workflows/update-version-tags.yml
@@ -14,19 +14,16 @@ on:
permissions:
contents: write
-concurrency:
- group: version-tag-${{ github.ref_name }}
- cancel-in-progress: true
-
jobs:
- retag:
+ check_head:
runs-on: ubuntu-latest
+ outputs:
+ is_current: ${{ steps.head_check.outputs.is_current }}
+ tag: ${{ steps.branch_tag.outputs.tag }}
steps:
- - name: Move version tag to pushed SHA
+ - name: Resolve version tag for branch
+ id: branch_tag
env:
- GH_TOKEN: ${{ github.token }}
- REPO: ${{ github.repository }}
- SHA: ${{ github.sha }}
BRANCH: ${{ github.ref_name }}
run: |
set -euo pipefail
@@ -36,11 +33,70 @@ jobs:
sagitta) TAG=1.4 ;;
*) echo "Unexpected branch: $BRANCH" >&2; exit 1 ;;
esac
+ echo "tag=$TAG" >> "$GITHUB_OUTPUT"
+
+ - name: Check event SHA matches current branch HEAD
+ id: head_check
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ SHA: ${{ github.sha }}
+ BRANCH: ${{ github.ref_name }}
+ run: |
+ set -euo pipefail
+ HEAD_SHA="$(gh api "repos/$REPO/branches/$BRANCH" --jq '.commit.sha')"
+ if [ "$HEAD_SHA" != "$SHA" ]; then
+ echo "Skipping stale run: event SHA=$SHA, current $BRANCH HEAD=$HEAD_SHA"
+ echo "is_current=false" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+
+ echo "is_current=true" >> "$GITHUB_OUTPUT"
+
+ retag:
+ needs: check_head
+ if: needs.check_head.outputs.is_current == 'true'
+ runs-on: ubuntu-latest
+ concurrency:
+ # Per-branch job concurrency serializes tag moves while letting stale
+ # re-runs exit before they contend for the single pending slot.
+ group: version-tag-${{ github.ref_name }}
+ cancel-in-progress: false
+ steps:
+ - name: Move version tag to pushed SHA
+ env:
+ GH_TOKEN: ${{ github.token }}
+ REPO: ${{ github.repository }}
+ SHA: ${{ github.sha }}
+ BRANCH: ${{ github.ref_name }}
+ TAG: ${{ needs.check_head.outputs.tag }}
+ run: |
+ set -euo pipefail
+
+ # Re-validate HEAD inside retag too: GitHub's "Re-run failed jobs"
+ # can re-execute retag in isolation without re-running check_head,
+ # and the branch HEAD may have advanced since the original run.
+ # Without this guard, a re-run of just retag would PATCH the tag
+ # to a stale github.sha.
+ HEAD_SHA="$(gh api "repos/$REPO/branches/$BRANCH" --jq '.commit.sha')"
+ if [ "$HEAD_SHA" != "$SHA" ]; then
+ echo "Skipping stale retag: event SHA=$SHA, current $BRANCH HEAD=$HEAD_SHA"
+ exit 0
+ fi
+
echo "Pointing tag '$TAG' at $SHA (branch $BRANCH)"
- if gh api "repos/$REPO/git/ref/tags/$TAG" >/dev/null 2>&1; then
- gh api -X PATCH "repos/$REPO/git/refs/tags/$TAG" \
- -f sha="$SHA" -F force=true
- else
- gh api -X POST "repos/$REPO/git/refs" \
- -f ref="refs/tags/$TAG" -f sha="$SHA"
+
+ # PATCH the tag if it exists; create on 404; fail loud on any other
+ # gh-api error (auth, rate-limit, 5xx) instead of silently falling
+ # through to POST.
+ patch_err=""
+ if ! patch_err="$(gh api -X PATCH "repos/$REPO/git/refs/tags/$TAG" \
+ -f sha="$SHA" -F force=true 2>&1)"; then
+ if grep -q "HTTP 404" <<<"$patch_err"; then
+ gh api -X POST "repos/$REPO/git/refs" \
+ -f ref="refs/tags/$TAG" -f sha="$SHA"
+ else
+ echo "$patch_err" >&2
+ exit 1
+ fi
fi