Skip to content

Commit b2d9cfc

Browse files
author
strausr
committed
fix(release): ensure v1.0.0-beta.1 is visible to semantic-release
- Fetch notes in Setup git branch so existing semantic-release notes are available - Add step to move v1.0.0-beta.1 into main history when tag exists but "git tag --merged main" omits it (e.g. after rebase); push only when not dry run - Add note step: always overwrite note with -f, use set -e, push note only when not dry run Fixes semantic-release trying to re-create v1.0.0-beta.1 (tag already exists).
1 parent 066ca30 commit b2d9cfc

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
- name: Setup git branch
5959
run: |
6060
git fetch --all --tags --force
61+
git fetch origin '+refs/notes/*:refs/notes/*' || true
6162
git checkout -B main
6263
git branch --set-upstream-to=origin/main main
6364
@@ -85,18 +86,42 @@ jobs:
8586
git config user.name "github-actions[bot]"
8687
git config user.email "github-actions[bot]@users.noreply.github.com"
8788
89+
- name: Ensure v1.0.0-beta.1 is in main history
90+
run: |
91+
set -e
92+
# semantic-release uses "git tag --merged main"; if the tag points to a commit not in main, it is ignored.
93+
if ! git rev-parse --verify v1.0.0-beta.1 >/dev/null 2>&1; then exit 0; fi
94+
if git tag --merged main | grep -qx v1.0.0-beta.1; then
95+
echo "v1.0.0-beta.1 is already in main history."
96+
exit 0
97+
fi
98+
# Tag exists but is not merged into main; move it to the release commit so semantic-release sees it.
99+
RELEASE_COMMIT=$(git log main -1 --format=%H --grep="chore(release): 1.0.0-beta.1" 2>/dev/null || true)
100+
if [ -z "$RELEASE_COMMIT" ]; then
101+
RELEASE_COMMIT=$(git merge-base main origin/master 2>/dev/null || git rev-parse HEAD~1)
102+
fi
103+
git tag -d v1.0.0-beta.1 2>/dev/null || true
104+
git tag -a v1.0.0-beta.1 "$RELEASE_COMMIT" -m "chore: 1.0.0-beta.1"
105+
if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then
106+
git push origin v1.0.0-beta.1 --force
107+
fi
108+
echo "Moved v1.0.0-beta.1 to $RELEASE_COMMIT so it is in main history."
109+
88110
- name: Add semantic-release note to v1.0.0-beta.1 if missing
89111
run: |
112+
set -e
90113
# Existing v1.0.0-beta.1 tag has no git note, so semantic-release ignores it and tries to re-release it.
91114
# Add the note so it is treated as last release and the next version is 1.0.0-beta.2.
92-
if git rev-parse --verify v1.0.0-beta.1 >/dev/null 2>&1; then
93-
if ! git notes --ref semantic-release-v1.0.0-beta.1 show v1.0.0-beta.1 >/dev/null 2>&1; then
94-
git notes --ref semantic-release-v1.0.0-beta.1 add -f -m '{"channels":["beta"]}' v1.0.0-beta.1
95-
if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then
96-
git push origin refs/notes/semantic-release-v1.0.0-beta.1
97-
fi
98-
fi
115+
if ! git rev-parse --verify v1.0.0-beta.1 >/dev/null 2>&1; then
116+
echo "Tag v1.0.0-beta.1 not found, skipping note step."
117+
exit 0
118+
fi
119+
# Always ensure the note exists (-f overwrites); required for get-last-release to see this tag on main.
120+
git notes --ref semantic-release-v1.0.0-beta.1 add -f -m '{"channels":["beta"]}' v1.0.0-beta.1
121+
if [ "${{ github.event.inputs.dry_run }}" != "true" ]; then
122+
git push origin refs/notes/semantic-release-v1.0.0-beta.1
99123
fi
124+
echo "Added semantic-release note to v1.0.0-beta.1"
100125
101126
- name: Create initial tag if needed
102127
if: github.event.inputs.dry_run != 'true'

0 commit comments

Comments
 (0)