Skip to content

Commit a9a8cbd

Browse files
nsheapsclaude
andcommitted
fix: use detached tag approach for versioned releases
Tag points to a commit NOT in main's history: - release-it handles changelog only (no tag, no push) - Push changelog to main - Create separate commit with embedded version - Tag that commit and push only the tag - Archive tarball from tag has embedded version - main always has __VERSION__ placeholder Co-Authored-By: Claude Code (User Settings, in: ${CLAUDE_PROJECT_DIR}) <noreply@anthropic.com>
1 parent 82128f9 commit a9a8cbd

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

.github/workflows/release.yaml

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,11 @@ jobs:
5252
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
5353
fi
5454
55-
- name: Embed version in script
56-
if: steps.next-version.outputs.will-release == 'true'
57-
run: |
58-
# Embed version before release-it commits, so the tagged commit has it
59-
sed -i -E 's/GIT_WT_VERSION="(__VERSION__|v[0-9]+\.[0-9]+\.[0-9]+)"/GIT_WT_VERSION="${{ steps.next-version.outputs.tag }}"/' bin/git-wt
60-
61-
- name: Run release-it
55+
- name: Run release-it for changelog
6256
id: release
6357
if: steps.next-version.outputs.will-release == 'true'
6458
run: |
65-
# Run release-it to bump version, update changelog, commit, and tag
66-
# The embedded version will be included in the tagged commit
59+
# release-it updates changelog and commits (no tag, no push)
6760
if yarn release-it --ci; then
6861
echo "released=true" >> "$GITHUB_OUTPUT"
6962
echo "version=${{ steps.next-version.outputs.version }}" >> "$GITHUB_OUTPUT"
@@ -73,14 +66,48 @@ jobs:
7366
echo "released=false" >> "$GITHUB_OUTPUT"
7467
fi
7568
76-
- name: Reset version to placeholder
69+
- name: Push changelog to main
70+
if: steps.release.outputs.released == 'true'
71+
run: git push origin main
72+
73+
- name: Create tagged release commit
7774
if: steps.release.outputs.released == 'true'
7875
run: |
79-
# Reset to __VERSION__ so main branch stays clean
80-
sed -i -E 's/GIT_WT_VERSION="v[0-9]+\.[0-9]+\.[0-9]+"/GIT_WT_VERSION="__VERSION__"/' bin/git-wt
76+
TAG="${{ steps.release.outputs.tag }}"
77+
78+
# Embed version in script
79+
sed -i -E 's/GIT_WT_VERSION="(__VERSION__|v[0-9]+\.[0-9]+\.[0-9]+)"/GIT_WT_VERSION="'"$TAG"'"/' bin/git-wt
80+
81+
# Commit with embedded version (this commit will NOT be on main)
8182
git add bin/git-wt
82-
git commit -m "chore: reset version placeholder [skip ci]"
83-
git push
83+
git commit -m "release: $TAG"
84+
85+
# Tag this commit
86+
git tag -a "$TAG" -m "Release $TAG"
87+
88+
# Push ONLY the tag (the commit stays detached from main)
89+
git push origin "$TAG"
90+
91+
# Reset local main back to before the embedded version commit
92+
# This leaves main clean with __VERSION__
93+
git reset --hard HEAD~1
94+
95+
- name: Create GitHub release
96+
if: steps.release.outputs.released == 'true'
97+
run: |
98+
TAG="${{ steps.release.outputs.tag }}"
99+
100+
# Checkout the tagged commit to get bin/git-wt with embedded version
101+
git checkout "$TAG" -- bin/git-wt
102+
103+
# Create release with the versioned script as asset
104+
gh release create "$TAG" \
105+
bin/git-wt \
106+
--title "$TAG" \
107+
--generate-notes
108+
109+
# Restore bin/git-wt to __VERSION__ (from main)
110+
git checkout HEAD -- bin/git-wt
84111
85112
update-homebrew:
86113
if: needs.release.outputs.released == 'true'

.release-it.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
{
2-
"hooks": {
3-
"before:git:commit": "git reset HEAD bin/git-wt"
4-
},
52
"git": {
3+
"commit": true,
64
"commitMessage": "chore: release v${version} [skip ci]",
7-
"tagName": "v${version}",
8-
"tagAnnotation": "Release v${version}",
5+
"tag": false,
6+
"push": false,
97
"requireCleanWorkingDir": false,
108
"getLatestTagFromAllRefs": true
119
},
1210
"github": {
13-
"release": true,
14-
"autoGenerate": true,
15-
"assets": ["bin/git-wt"]
11+
"release": false
1612
},
1713
"npm": false,
1814
"plugins": {

0 commit comments

Comments
 (0)