|
28 | 28 | # if other PRs merge between trigger and job start |
29 | 29 | ref: ${{ github.event.pull_request.merge_commit_sha }} |
30 | 30 |
|
| 31 | + - name: Retarget release tags to squash merge commit |
| 32 | + if: github.event_name == 'pull_request' |
| 33 | + env: |
| 34 | + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} |
| 35 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 36 | + run: | |
| 37 | + set -euo pipefail |
| 38 | +
|
| 39 | + echo "🔧 Retargeting release tags from PR head to merge commit" |
| 40 | + echo "PR_HEAD_SHA=$PR_HEAD_SHA" |
| 41 | + echo "MERGE_SHA=$MERGE_SHA" |
| 42 | +
|
| 43 | + git fetch --force --tags origin |
| 44 | +
|
| 45 | + # Tags are created on the PR branch commit. After squash-merge, that commit is no longer on dev, |
| 46 | + # so we force-move those tags to the squash merge commit. |
| 47 | + ALL_POINTS_AT="$(git tag --points-at "$PR_HEAD_SHA" || true)" |
| 48 | + if [ -z "$ALL_POINTS_AT" ]; then |
| 49 | + echo "❌ No git tags found pointing at PR head commit ($PR_HEAD_SHA)." |
| 50 | + echo "This likely means the release workflow didn't create/push tags for this PR. Aborting publish." |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + # Only retarget tags matching the expected {lib}@{version} shape. |
| 55 | + TAGS_TO_MOVE="$(printf '%s\n' "$ALL_POINTS_AT" | grep -E '^[A-Za-z0-9._-]+@[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$' || true)" |
| 56 | + if [ -z "$TAGS_TO_MOVE" ]; then |
| 57 | + echo "❌ Tags pointing at PR head exist, but none match the {lib}@{version} pattern. Aborting publish." |
| 58 | + echo "Tags found:" |
| 59 | + printf '%s\n' "$ALL_POINTS_AT" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "📌 Tags to retarget:" |
| 64 | + printf '%s\n' "$TAGS_TO_MOVE" |
| 65 | +
|
| 66 | + while IFS= read -r tag; do |
| 67 | + [ -n "$tag" ] || continue |
| 68 | +
|
| 69 | + old_sha="$(git rev-parse "$tag^{commit}")" |
| 70 | + git tag -f "$tag" "$MERGE_SHA" |
| 71 | + new_sha="$(git rev-parse "$tag^{commit}")" |
| 72 | +
|
| 73 | + echo "🔁 $tag: $old_sha -> $new_sha" |
| 74 | +
|
| 75 | + # Force-push the updated tag ref. |
| 76 | + git push origin -f "refs/tags/$tag" |
| 77 | + done <<< "$TAGS_TO_MOVE" |
| 78 | +
|
31 | 79 | - name: Setup Node.js |
32 | 80 | uses: actions/setup-node@v6 |
33 | 81 | with: |
|
0 commit comments