Skip to content

Commit 8cb1bed

Browse files
committed
fix(release): create tag after commit amend to prevent tag drift
1 parent 813b6e8 commit 8cb1bed

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

scripts/prepare-release.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,10 @@ COMMIT_MESSAGE="release: prepare ${VERSION}"
207207
git commit -m "$COMMIT_MESSAGE"
208208
echo -e "${GREEN}Created commit: $COMMIT_MESSAGE${NC}"
209209

210-
# Create annotated tag
211-
echo -e "${YELLOW}Creating git tag ${VERSION}...${NC}"
212-
git tag -a "$VERSION" -m "Go ContextForge SDK $VERSION"
213-
echo -e "${GREEN}Created annotated tag: $VERSION${NC}"
214-
215-
# Check for GoReleaser and GITHUB_TOKEN
210+
# Check for GoReleaser and GITHUB_TOKEN (before creating tag)
216211
if ! command -v goreleaser &> /dev/null; then
217212
echo -e "${RED}Error: goreleaser is not installed${NC}"
218213
echo -e "${YELLOW}Install with: go install github.com/goreleaser/goreleaser/v2@latest${NC}"
219-
git tag -d "$VERSION"
220214
git reset --hard HEAD~1
221215
exit 1
222216
fi
@@ -229,8 +223,7 @@ if [ -z "$GITHUB_TOKEN" ]; then
229223
echo -e "${YELLOW}Continue anyway? Release will fail but you can retry later. (y/N)${NC}"
230224
read -r response
231225
if [[ ! "$response" =~ ^[Yy]$ ]]; then
232-
echo -e "${YELLOW}Undoing tag and commit...${NC}"
233-
git tag -d "$VERSION"
226+
echo -e "${YELLOW}Undoing commit...${NC}"
234227
git reset --hard HEAD~1
235228
exit 1
236229
fi
@@ -240,8 +233,7 @@ fi
240233
echo -e "${YELLOW}Running GoReleaser...${NC}"
241234
if ! goreleaser release --clean; then
242235
echo -e "${RED}Error: GoReleaser failed${NC}"
243-
echo -e "${YELLOW}Undoing tag and commit...${NC}"
244-
git tag -d "$VERSION"
236+
echo -e "${YELLOW}Undoing commit...${NC}"
245237
git reset --hard HEAD~1
246238
exit 1
247239
fi
@@ -252,8 +244,7 @@ echo -e "${GREEN}GoReleaser completed successfully!${NC}"
252244
echo -e "${YELLOW}Merging changelog...${NC}"
253245
if ! merge_changelog "$VERSION"; then
254246
echo -e "${RED}Error: Changelog merge failed${NC}"
255-
echo -e "${YELLOW}Undoing tag and commit...${NC}"
256-
git tag -d "$VERSION"
247+
echo -e "${YELLOW}Undoing commit...${NC}"
257248
git reset --hard HEAD~1
258249
exit 1
259250
fi
@@ -265,6 +256,11 @@ git add CHANGELOG.md
265256
git commit --amend --no-edit
266257
echo -e "${GREEN}Updated release commit with changelog${NC}"
267258

259+
# Create annotated tag (after commit is amended so tag points to final commit)
260+
echo -e "${YELLOW}Creating git tag ${VERSION}...${NC}"
261+
git tag -a "$VERSION" -m "Go ContextForge SDK $VERSION"
262+
echo -e "${GREEN}Created annotated tag: $VERSION${NC}"
263+
268264
# Display next steps
269265
echo ""
270266
echo -e "${GREEN}========================================${NC}"
@@ -287,8 +283,9 @@ echo " https://github.com/leefowlercu/go-contextforge/releases"
287283
echo ""
288284
echo "3. If changes needed:"
289285
echo " - Edit CHANGELOG.md locally and/or release notes on GitHub"
290-
echo " - Amend commit: git add CHANGELOG.md && git commit --amend --no-edit"
291-
echo " - Update tag: git tag -fa $VERSION -m \"Go ContextForge SDK $VERSION\""
286+
echo " - Amend commit and update tag:"
287+
echo " git add CHANGELOG.md && git commit --amend --no-edit"
288+
echo " git tag -fa $VERSION -m \"Go ContextForge SDK $VERSION\""
292289
echo " - OR undo completely: git tag -d $VERSION && git reset --hard HEAD~1"
293290
echo ""
294291
echo "4. When ready to publish:"

0 commit comments

Comments
 (0)