Skip to content

Commit cf4ccaf

Browse files
committed
ci(scripts): refine tag handling in publish script
- Separate tag recreation into a dedicated function. - Ensure tags pointing to HEAD are preserved and reapplied after commit amendments. - Clean up temporary files after processing.
1 parent 9750df3 commit cf4ccaf

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

scripts/publish.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,28 @@ create_github_release() {
4343
# Function to move tags to current HEAD
4444
move_tags_to_head() {
4545
echo "Moving tags to current HEAD..."
46-
# Get all tags pointing to the previous commit
47-
PREV_COMMIT=$(git rev-parse HEAD^)
48-
TAGS_TO_MOVE=$(git tag --points-at "$PREV_COMMIT" 2>/dev/null || true)
46+
# Get all tags pointing to HEAD (before we amend)
47+
TAGS_TO_MOVE=$(git tag --points-at HEAD 2>/dev/null || true)
4948

5049
if [ ! -z "$TAGS_TO_MOVE" ]; then
50+
echo "Tags found on current commit: $TAGS_TO_MOVE"
51+
# Store tags to recreate them after amending
52+
echo "$TAGS_TO_MOVE" > /tmp/tags_to_move_$$
53+
fi
54+
}
55+
56+
# Function to recreate tags after amending
57+
recreate_tags() {
58+
if [ -f "/tmp/tags_to_move_$$" ]; then
59+
TAGS_TO_MOVE=$(cat /tmp/tags_to_move_$$)
5160
for tag in $TAGS_TO_MOVE; do
52-
echo "Moving tag $tag to HEAD"
53-
git tag -f "$tag" HEAD
61+
echo "Recreating tag $tag on amended HEAD"
62+
# Delete the old tag locally
63+
git tag -d "$tag"
64+
# Create it again pointing to current HEAD
65+
git tag "$tag" HEAD
5466
done
67+
rm -f /tmp/tags_to_move_$$
5568
fi
5669
}
5770

@@ -76,12 +89,16 @@ if git diff-tree --no-commit-id --name-only -r HEAD | grep -q "package-lock.json
7689
# Check for both staged and unstaged changes
7790
if ! git diff --quiet || ! git diff --staged --quiet; then
7891
echo "Changes detected, amending commit..."
92+
93+
# Save tags before amending
94+
move_tags_to_head
95+
7996
git add -A
8097
# Amend the last commit instead of creating a new one
8198
git commit --amend --no-edit
8299

83-
# Move tags from the old commit to the amended commit
84-
move_tags_to_head
100+
# Recreate tags on the amended commit
101+
recreate_tags
85102

86103
echo "Pushing amended commit..."
87104
git push origin HEAD:master

0 commit comments

Comments
 (0)