Skip to content

Commit ce1fd90

Browse files
authored
chore(ci): retarget release tags after squash-merge before npm publish [WPB-23275] (#20490)
* chore(ci): retarget release tags after squash-merge before npm publish * update workflows
1 parent b1a432f commit ce1fd90

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

.github/workflows/pr-auto-merge.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ jobs:
2828
- name: Enable auto-merge
2929
if: ${{github.actor == 'otto-the-bot' || (github.actor == 'dependabot[bot]' && steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major') || (github.event.pull_request.labels && contains(github.event.pull_request.labels.*.name, 'publish-to-npm')) }}
3030
run: |
31-
if [[ "${{ github.event.pull_request.labels }}" == *publish-to-npm* ]]; then
32-
gh pr merge --auto --merge "$PR_URL"
33-
else
34-
gh pr merge --auto --squash "$PR_URL"
35-
fi
31+
gh pr merge --auto --squash "$PR_URL"
3632
env:
3733
GITHUB_TOKEN: ${{secrets.OTTO_THE_BOT_GH_TOKEN}}
3834
PR_URL: ${{github.event.pull_request.html_url}}

.github/workflows/publish-libraries-on-merge.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,54 @@ jobs:
2828
# if other PRs merge between trigger and job start
2929
ref: ${{ github.event.pull_request.merge_commit_sha }}
3030

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+
3179
- name: Setup Node.js
3280
uses: actions/setup-node@v6
3381
with:

.github/workflows/publish-libraries.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ jobs:
7777
--head "$RELEASE_BRANCH" \
7878
--title "chore(release): publish libraries [WPB-22420]" \
7979
--label "publish-to-npm" \
80-
--body "Automated release PR created by nx release. ⚠️ **Important:** Do NOT squash merge this PR. Use 'Merge commit' to preserve git tags."
80+
--body "Automated release PR created by nx release. ⚠️ **Important:** Squash-merge this PR (do not use 'Merge commit')."
8181
env:
8282
GITHUB_TOKEN: ${{ secrets.OTTO_THE_BOT_GH_TOKEN }}

0 commit comments

Comments
 (0)