@@ -73,32 +73,61 @@ jobs:
7373 git config --local user.email "action@github.com"
7474 git config --local user.name "GitHub Action"
7575
76- - name : Check if release is needed
77- id : check_release
76+ - name : Determine version bump type
77+ id : bump_type
78+ run : |
79+ # Get the last commit message
80+ COMMIT_MSG=$(git log -1 --pretty=%B)
81+ echo "Commit message: $COMMIT_MSG"
82+
83+ # Determine bump type based on commit message
84+ if echo "$COMMIT_MSG" | grep -iq "BREAKING CHANGE\|major:"; then
85+ echo "type=major" >> $GITHUB_OUTPUT
86+ echo "Detected MAJOR version bump"
87+ elif echo "$COMMIT_MSG" | grep -iq "feat:\|feature:\|minor:"; then
88+ echo "type=minor" >> $GITHUB_OUTPUT
89+ echo "Detected MINOR version bump"
90+ else
91+ echo "type=patch" >> $GITHUB_OUTPUT
92+ echo "Detected PATCH version bump"
93+ fi
94+
95+ - name : Check if version already bumped
96+ id : check_version
7897 run : |
79- # Get the version from the merged package.json
8098 CURRENT_VERSION=$(node -p "require('./package.json').version")
81- echo "Version in package.json is $CURRENT_VERSION"
99+ echo "Current version: $CURRENT_VERSION"
82100
83- # Check if a git tag for this version already exists
101+ # Check if tag already exists
84102 if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
85- echo "Tag v$CURRENT_VERSION already exists. Skipping release. "
86- echo "skip =true" >> $GITHUB_OUTPUT
103+ echo "Tag v$CURRENT_VERSION already exists"
104+ echo "needs_bump =true" >> $GITHUB_OUTPUT
87105 else
88- echo "Tag v$CURRENT_VERSION does not exist. Proceeding with release. "
89- echo "skip =false" >> $GITHUB_OUTPUT
106+ echo "Tag v$CURRENT_VERSION does not exist"
107+ echo "needs_bump =false" >> $GITHUB_OUTPUT
90108 echo "VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
91109 fi
92110
111+ - name : Bump version in package.json
112+ if : steps.check_version.outputs.needs_bump == 'true'
113+ run : |
114+ pnpm version ${{ steps.bump_type.outputs.type }} -m "chore: release v%s [skip ci]"
115+ NEW_VERSION=$(node -p "require('./package.json').version")
116+ echo "VERSION=$NEW_VERSION" >> $GITHUB_ENV
117+ echo "Bumped to version $NEW_VERSION"
118+
119+ - name : Push version bump commit
120+ if : steps.check_version.outputs.needs_bump == 'true'
121+ run : |
122+ git push origin main
123+
93124 - name : Create and push tag
94- if : steps.check_release.outputs.skip == 'false'
95125 run : |
96126 git tag v${{ env.VERSION }}
97127 git push origin v${{ env.VERSION }}
98128 echo "Created and pushed tag v${{ env.VERSION }}"
99129
100130 - name : Generate changelog and update file
101- if : steps.check_release.outputs.skip == 'false'
102131 run : |
103132 # Install changelog generator
104133 npm install -g auto-changelog
@@ -130,7 +159,6 @@ jobs:
130159 git push origin main
131160
132161 - name : Create GitHub Release
133- if : steps.check_release.outputs.skip == 'false'
134162 id : create_release
135163 uses : actions/create-release@v1
136164 env :
@@ -143,13 +171,11 @@ jobs:
143171 prerelease : false
144172
145173 - name : Publish to NPM
146- if : steps.check_release.outputs.skip == 'false'
147174 run : pnpm publish --access public --no-git-checks
148175 env :
149176 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
150177
151178 - name : Success notification
152- if : steps.check_release.outputs.skip == 'false'
153179 run : |
154180 echo "🎉 Successfully released v${{ env.VERSION }}"
155181 echo "📦 NPM: https://www.npmjs.com/package/vite-plugin-component-debugger"
0 commit comments