66 paths :
77 - " package.json"
88 workflow_dispatch :
9+ # Allow manual trigger for testing
910
1011permissions :
1112 contents : write
@@ -25,22 +26,58 @@ jobs:
2526 - name : Check version change
2627 id : version_check
2728 run : |
29+ # Debug information
30+ echo "=== DEBUG INFO ==="
31+ echo "Event name: ${{ github.event_name }}"
32+ echo "Ref: ${{ github.ref }}"
33+ echo "Repository: ${{ github.repository }}"
34+
2835 # Get current version from package.json
2936 CURRENT_VERSION=$(node -p "require('./package.json').version")
3037 echo "Current version: $CURRENT_VERSION"
3138
3239 # Get previous version from git history
33- git fetch origin main
34- PREVIOUS_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync(0)).version")
35- echo "Previous version: $PREVIOUS_VERSION"
40+ echo "=== FETCHING GIT HISTORY ==="
41+ git fetch origin main || echo "No remote main branch yet"
42+
43+ # Debug git status
44+ echo "=== GIT STATUS ==="
45+ git log --oneline -5 || echo "No git history available"
46+
47+ # Try to get previous version from git history
48+ PREVIOUS_VERSION=""
49+ echo "=== CHECKING PREVIOUS PACKAGE.JSON ==="
50+ if git show origin/main:package.json >/dev/null 2>&1; then
51+ PREVIOUS_VERSION=$(git show origin/main:package.json | node -p "JSON.parse(require('fs').readFileSync(0)).version")
52+ echo "Previous version: $PREVIOUS_VERSION"
53+ else
54+ echo "No previous version found in git history"
55+ # Check if this is the first commit by looking for existing tags
56+ echo "=== CHECKING EXISTING TAGS ==="
57+ if git describe --tags --abbrev=0 >/dev/null 2>&1; then
58+ # There are existing tags, so this is not the first release
59+ echo "Found existing tags, but no previous package.json version"
60+ echo "changed=false" >> $GITHUB_OUTPUT
61+ exit 0
62+ else
63+ echo "No existing tags found - this might be the first release"
64+ # For first release, we'll create a tag if there are no tags at all
65+ PREVIOUS_VERSION=""
66+ fi
67+ fi
3668
3769 # Compare versions
38- if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
39- echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
70+ echo "=== VERSION COMPARISON ==="
71+ if [ -z "$PREVIOUS_VERSION" ] || [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
72+ if [ -n "$PREVIOUS_VERSION" ]; then
73+ echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
74+ else
75+ echo "Creating first release with version $CURRENT_VERSION"
76+ fi
4077 echo "changed=true" >> $GITHUB_OUTPUT
4178 echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
4279 else
43- echo "Version unchanged"
80+ echo "Version unchanged ($CURRENT_VERSION) "
4481 echo "changed=false" >> $GITHUB_OUTPUT
4582 fi
4683
4986 if : needs.check-version.outputs.version_changed == 'true'
5087 runs-on : ubuntu-latest
5188 steps :
89+ - name : Debug outputs
90+ run : |
91+ echo "Version changed: ${{ needs.check-version.outputs.version_changed }}"
92+ echo "New version: ${{ needs.check-version.outputs.new_version }}"
93+
5294 - name : Checkout
5395 uses : actions/checkout@v4
5496 with :
@@ -93,10 +135,20 @@ jobs:
93135 - name : Create Git Tag
94136 run : |
95137 VERSION="${{ needs.check-version.outputs.new_version }}"
138+ echo "Creating tag for version: v$VERSION"
139+
96140 git config user.name "github-actions[bot]"
97141 git config user.email "github-actions[bot]@users.noreply.github.com"
98- git tag -a "v$VERSION" -m "Release version $VERSION"
99- git push origin "v$VERSION"
142+
143+ # Check if tag already exists
144+ if git rev-parse "v$VERSION" >/dev/null 2>&1; then
145+ echo "Tag v$VERSION already exists, skipping tag creation"
146+ else
147+ echo "Creating tag v$VERSION"
148+ git tag -a "v$VERSION" -m "Release version $VERSION"
149+ echo "Pushing tag to origin"
150+ git push origin "v$VERSION" || echo "Failed to push tag - this might be expected in some cases"
151+ fi
100152
101153 - name : Create GitHub Release
102154 uses : actions/create-release@v1
0 commit comments