Skip to content

Commit 2f9ba62

Browse files
yfgeclaude
andauthored
fix: workflow should only push git tags, not commit file changes (#29)
* fix: workflow should only push git tags, not commit file changes Key changes: - Remove cz bump --yes which modifies files (.cz.toml version) and creates commits - Use manual git tag creation instead of commitizen tag creation - Change from 'git push origin --follow-tags' to 'git push origin $NEW_VERSION' - Ensures ONLY the new tag is pushed, no file modifications or branch pushes This implements a pure git-tag-based versioning workflow: 1. Detect conventional commits since last tag 2. Determine new version number 3. Create ONLY a git tag (no file changes) 4. Push ONLY that specific tag No repository files are modified, maintaining clean git history while still enabling automated semantic versioning via tags. * fix: resolve shell injection and code duplication in workflow - Extract tag creation logic into reusable function - Fix shell injection by properly quoting variables - Improve code maintainability and security 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * fix: remove trailing whitespace from workflow file Address pre-commit hook failure by cleaning up whitespace 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 7c97f13 commit 2f9ba62

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

.github/workflows/publish.yml

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -165,49 +165,52 @@ jobs:
165165
echo "EOF"
166166
} >> $GITHUB_OUTPUT
167167
168-
# Create git tag with improved error handling
169-
echo "🏷️ Creating git tag..."
170-
TAG_CREATED=false
168+
# Create and push git tag (extracted function)
169+
create_and_push_tag() {
170+
local new_version="$1"
171+
local tag_created=false
171172
172-
if cz bump --yes 2>/dev/null; then
173-
echo "✅ Commitizen tag created successfully"
174-
TAG_CREATED=true
175-
else
176-
echo "⚠️ Commitizen bump failed, attempting manual tag creation..." >&2
173+
echo "🏷️ Creating git tag..."
177174
178175
# Check if tag already exists
179-
if git tag -l | grep -q "^$NEW_VERSION$"; then
180-
echo "⚠️ Tag $NEW_VERSION already exists, skipping creation"
181-
TAG_CREATED=true
176+
if git tag -l | grep -q "^${new_version}$"; then
177+
echo "⚠️ Tag ${new_version} already exists, skipping creation"
178+
tag_created=true
182179
else
183-
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo '1.0.0')
184-
if git tag "$NEW_VERSION" -m "bump: version $PREV_TAG → $NEW_VERSION" 2>/dev/null; then
185-
echo "✅ Manual tag created: $NEW_VERSION"
186-
TAG_CREATED=true
180+
local prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo '1.0.0')
181+
echo "📝 Creating tag ${new_version} from ${prev_tag}..."
182+
183+
if git tag "${new_version}" -m "bump: version ${prev_tag} → ${new_version}" 2>/dev/null; then
184+
echo "✅ Git tag created successfully: ${new_version}"
185+
tag_created=true
187186
else
188-
echo "❌ Failed to create tag $NEW_VERSION" >&2
189-
exit 1
187+
echo "❌ Failed to create tag ${new_version}" >&2
188+
return 1
190189
fi
191190
fi
192-
fi
193191
194-
# Push tags with retry mechanism
195-
if [ "$TAG_CREATED" = true ]; then
196-
echo "🚀 Pushing tags to remote..."
197-
for i in {1..3}; do
198-
if git push origin --follow-tags; then
199-
echo "✅ Tags pushed successfully"
200-
break
201-
else
202-
echo "⚠️ Push attempt $i failed, retrying..." >&2
203-
sleep $((i * 2))
204-
if [ $i -eq 3 ]; then
205-
echo "❌ Failed to push tags after 3 attempts" >&2
206-
exit 1
192+
# Push ONLY the new tag (no branch or file changes)
193+
if [ "$tag_created" = true ]; then
194+
echo "🚀 Pushing only the new tag to remote..."
195+
for i in {1..3}; do
196+
if git push origin "${new_version}"; then
197+
echo "✅ Tag ${new_version} pushed successfully"
198+
return 0
199+
else
200+
echo "⚠️ Tag push attempt $i failed, retrying..." >&2
201+
sleep $((i * 2))
202+
if [ $i -eq 3 ]; then
203+
echo "❌ Failed to push tag after 3 attempts" >&2
204+
return 1
205+
fi
207206
fi
208-
fi
209-
done
210-
fi
207+
done
208+
fi
209+
return 0
210+
}
211+
212+
# Call the extracted function with proper quoting
213+
create_and_push_tag "$NEW_VERSION"
211214
else
212215
echo "bump_needed=false" >> $GITHUB_OUTPUT
213216
echo "ℹ️ No version bump needed based on commit messages"

0 commit comments

Comments
 (0)