1717 auto-publish :
1818 if : github.event.pull_request.merged == true
1919 runs-on : ubuntu-latest
20-
20+
2121 steps :
2222 - name : Checkout code
2323 uses : actions/checkout@v4
2929 run : |
3030 corepack enable
3131 yarn --version
32-
32+
3333 # Always run yarn install to ensure lockfile exists and is up to date
3434 echo "📦 Running yarn install..."
3535 yarn install
4848 run : |
4949 BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
5050 echo "Branch name: $BRANCH_NAME"
51-
51+
5252 # Simplified pattern that properly handles hyphens, underscores, and dots
5353 if [[ $BRANCH_NAME =~ ^(feat|feature|fix|bugfix|break|breaking|hotfix|chore)/[a-zA-Z0-9._-]+$ ]]; then
5454 echo "✅ Branch pattern accepted: $BRANCH_NAME"
@@ -69,17 +69,26 @@ jobs:
6969 run : |
7070 # Verify that package.json is well-formed
7171 node -e "console.log('Package name:', require('./package.json').name)"
72-
73- # Verify that required scripts exist
74- if ! yarn run --help | grep -q "test:ci"; then
75- echo "❌ Missing test:ci script in package.json"
76- exit 1
77- fi
78-
79- if ! yarn run --help | grep -q "dist"; then
80- echo "❌ Missing dist script in package.json"
81- exit 1
82- fi
72+
73+ # Verify that required scripts exist using Node.js
74+ node -e "
75+ const pkg = require('./package.json');
76+ const scripts = pkg.scripts || {};
77+
78+ if (!scripts['test:ci']) {
79+ console.error('❌ Missing test:ci script in package.json');
80+ process.exit(1);
81+ }
82+
83+ if (!scripts['dist']) {
84+ console.error('❌ Missing dist script in package.json');
85+ process.exit(1);
86+ }
87+
88+ console.log('✅ Required scripts found:');
89+ console.log(' - test:ci:', scripts['test:ci']);
90+ console.log(' - dist:', scripts['dist']);
91+ "
8392
8493 - name : Run quality checks
8594 if : steps.validate-branch.outputs.should_publish == 'true'
8998 echo "🔍 Running linter..."
9099 yarn lint
91100 fi
92-
101+
93102 # Type checking
94103 if yarn run --help | grep -q "type-check"; then
95104 echo "🔍 Type checking..."
@@ -101,7 +110,7 @@ jobs:
101110 run : |
102111 echo "🧪 Running tests..."
103112 yarn test:ci
104-
113+
105114 # Check coverage if exists
106115 if [ -f "coverage/lcov.info" ]; then
107116 echo "📊 Coverage report generated"
@@ -112,7 +121,7 @@ jobs:
112121 run : |
113122 echo "🏗️ Building package..."
114123 yarn dist
115-
124+
116125 # Verify that the build generated files
117126 if [ ! -d "dist" ] && [ ! -d "lib" ] && [ ! -d "build" ]; then
118127 echo "❌ No build output found"
@@ -132,11 +141,11 @@ jobs:
132141 BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
133142 PR_TITLE="${{ github.event.pull_request.title }}"
134143 PR_BODY="${{ github.event.pull_request.body }}"
135-
144+
136145 echo "🔍 Analyzing PR for version bump..."
137146 echo "Branch: $BRANCH_NAME"
138147 echo "Title: $PR_TITLE"
139-
148+
140149 # 1. Check explicit breaking change markers
141150 if echo "$PR_BODY" | grep -qi "BREAKING CHANGE:" || \
142151 echo "$PR_TITLE" | grep -q "!" || \
@@ -146,14 +155,14 @@ jobs:
146155 VERSION_TYPE="major"
147156 REASON="Breaking change detected"
148157 echo "💥 MAJOR: $REASON"
149-
158+
150159 # 2. Check conventional commits in title
151160 elif echo "$PR_TITLE" | grep -Eq "^(feat|feature)(\(.+\))?!:" || \
152161 echo "$PR_TITLE" | grep -Eq "^(fix|bugfix)(\(.+\))?!:"; then
153162 VERSION_TYPE="major"
154163 REASON="Breaking change in conventional commit"
155164 echo "💥 MAJOR: $REASON"
156-
165+
157166 # 3. Check features (minor)
158167 elif echo "$PR_TITLE" | grep -Eq "^(feat|feature)(\(.+\))?:" || \
159168 [[ $BRANCH_NAME =~ ^feat/ ]] || \
@@ -162,25 +171,25 @@ jobs:
162171 VERSION_TYPE="minor"
163172 REASON="New feature detected"
164173 echo "✨ MINOR: $REASON"
165-
174+
166175 # 4. Check fixes and other changes (patch)
167176 else
168177 VERSION_TYPE="patch"
169178 REASON="Bug fix or other changes"
170179 echo "🐛 PATCH: $REASON"
171180 fi
172-
181+
173182 # Get current version
174183 CURRENT_VERSION=$(node -p "require('./package.json').version")
175184 echo "📦 Current version: $CURRENT_VERSION"
176-
185+
177186 # Calculate new version
178187 NEW_VERSION=$(node -e "
179188 const semver = require('semver');
180189 const current = '$CURRENT_VERSION';
181190 console.log(semver.inc(current, '$VERSION_TYPE'));
182191 ")
183-
192+
184193 echo "🚀 New version will be: $NEW_VERSION"
185194 echo "🎯 Decision reason: $REASON"
186195 echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
@@ -193,13 +202,13 @@ jobs:
193202 run : |
194203 NEW_VERSION="${{ steps.version-bump.outputs.new_version }}"
195204 PACKAGE_NAME=$(node -p "require('./package.json').name")
196-
205+
197206 # Check if version already exists in NPM
198207 if npm view "$PACKAGE_NAME@$NEW_VERSION" version 2>/dev/null; then
199208 echo "❌ Version $NEW_VERSION already exists in NPM"
200209 exit 1
201210 fi
202-
211+
203212 # Check if tag already exists
204213 if git tag -l | grep -q "^v$NEW_VERSION$"; then
205214 echo "❌ Tag v$NEW_VERSION already exists"
@@ -213,20 +222,20 @@ jobs:
213222 VERSION_TYPE="${{ steps.version-bump.outputs.version_type }}"
214223 BRANCH_NAME="${{ steps.validate-branch.outputs.branch_name }}"
215224 REASON="${{ steps.version-bump.outputs.reason }}"
216-
225+
217226 # Update package.json
218227 npm version $NEW_VERSION --no-git-tag-version
219-
228+
220229 # Commit and tag
221230 git add package.json yarn.lock 2>/dev/null || git add package.json
222231 git commit -m "chore(release): $NEW_VERSION
223232
224233 Released from: $BRANCH_NAME
225234 Type: $VERSION_TYPE
226235 Reason: $REASON
227-
236+
228237 [skip ci]"
229-
238+
230239 git tag "v$NEW_VERSION" -m "Release v$NEW_VERSION"
231240
232241 - name : Dry run publish (verification)
@@ -243,16 +252,16 @@ jobs:
243252 run : |
244253 NEW_VERSION="${{ steps.version-bump.outputs.new_version }}"
245254 VERSION_TYPE="${{ steps.version-bump.outputs.version_type }}"
246-
255+
247256 echo "📦 Publishing to NPM..."
248-
257+
249258 if [[ "$VERSION_TYPE" == "major" ]]; then
250259 echo "⚠️ Publishing MAJOR version $NEW_VERSION"
251260 npm publish --access public --tag latest
252261 else
253262 npm publish --access public --tag latest
254263 fi
255-
264+
256265 echo "✅ Successfully published to NPM"
257266 echo "published=true" >> $GITHUB_OUTPUT
258267 env :
@@ -274,21 +283,21 @@ jobs:
274283 name : Release v${{ steps.version-bump.outputs.new_version }}
275284 body : |
276285 ## 🚀 Release v${{ steps.version-bump.outputs.new_version }}
277-
286+
278287 **Type:** ${{ steps.version-bump.outputs.version_type }} release
279288 **Branch:** `${{ steps.validate-branch.outputs.branch_name }}`
280289 **Previous:** `${{ steps.version-bump.outputs.current_version }}`
281-
290+
282291 ### 📝 Changes
283292 - ${{ github.event.pull_request.title }} (#${{ github.event.pull_request.number }})
284-
293+
285294 ### 📦 Installation
286295 ```bash
287296 npm install @kubit-ui-web/react-components@${{ steps.version-bump.outputs.new_version }}
288297 # or
289298 yarn add @kubit-ui-web/react-components@${{ steps.version-bump.outputs.new_version }}
290299 ```
291-
300+
292301 ### 🔗 Links
293302 - [NPM Package](https://www.npmjs.com/package/@kubit-ui-web/react-components/v/${{ steps.version-bump.outputs.new_version }})
294303 - [Full Changelog](https://github.com/${{ github.repository }}/compare/v${{ steps.version-bump.outputs.current_version }}...v${{ steps.version-bump.outputs.new_version }})
@@ -308,35 +317,35 @@ jobs:
308317 current_version: '${{ steps.version-bump.outputs.current_version }}'
309318 };
310319 const branchName = '${{ steps.validate-branch.outputs.branch_name }}';
311-
320+
312321 const emoji = version_type === 'major' ? '💥' : version_type === 'minor' ? '✨' : '🐛';
313-
322+
314323 const comment = `## ${emoji} Auto-publish Successful!
315-
324+
316325 | Field | Value |
317326 |-------|-------|
318327 | **Branch** | \`${branchName}\` |
319328 | **Type** | \`${version_type}\` |
320329 | **Version** | \`${current_version}\` → \`${new_version}\` |
321330 | **NPM** | [@kubit-ui-web/react-components@${new_version}](https://www.npmjs.com/package/@kubit-ui-web/react-components/v/${new_version}) |
322-
331+
323332 ### 📦 Installation
324333 \`\`\`bash
325334 npm install @kubit-ui-web/react-components@${new_version}
326335 # or
327336 yarn add @kubit-ui-web/react-components@${new_version}
328337 \`\`\`
329-
338+
330339 ### ✅ Completed Steps
331340 - [x] Quality checks passed
332341 - [x] Tests passed
333342 - [x] Build successful
334343 - [x] Published to NPM
335344 - [x] GitHub release created
336345 - [x] Repository tagged
337-
346+
338347 🎉 **Ready to use in production!**`;
339-
348+
340349 await github.rest.issues.createComment({
341350 issue_number: context.issue.number,
342351 owner: context.repo.owner,
@@ -350,20 +359,20 @@ jobs:
350359 with :
351360 script : |
352361 const comment = `## ❌ Auto-publish Failed
353-
362+
354363 The automatic publication process failed. Please check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
355-
364+
356365 ### 🔧 Common Solutions
357366 - Verify NPM_TOKEN is valid and has publish permissions
358367 - Check if version already exists
359368 - Ensure all tests pass locally
360369 - Verify build process completes successfully
361-
370+
362371 ### 📞 Next Steps
363372 1. Fix the issue based on the error logs
364373 2. Create a new PR with the same changes
365374 3. Or use manual publish workflow if urgent`;
366-
375+
367376 await github.rest.issues.createComment({
368377 issue_number: context.issue.number,
369378 owner: context.repo.owner,
@@ -377,30 +386,30 @@ jobs:
377386 with :
378387 script : |
379388 const branchName = '${{ github.event.pull_request.head.ref }}';
380-
389+
381390 const comment = `## ℹ️ Auto-publish Skipped
382-
391+
383392 Branch \`${branchName}\` doesn't match required patterns for auto-publishing.
384-
393+
385394 ### 📋 Required Patterns
386395 | Pattern | Version Bump | Detection Method |
387396 |---------|--------------|------------------|
388397 | \`feat/\*\` or \`feature/\*\` | **minor** | Branch prefix or PR title |
389398 | \`fix/\*\` or \`bugfix/\*\` | **patch** | Branch prefix or default |
390399 | \`break/\*\` or \`breaking/\*\` | **major** | Branch prefix |
391400 | \`hotfix/\*\` or \`chore/\*\` | **patch** | Branch prefix |
392-
401+
393402 ### 🎯 Advanced Version Detection
394403 - **MAJOR**: \`BREAKING CHANGE:\` in PR body, \`!\` in title, or \`[breaking]\` tag
395404 - **MINOR**: \`feat:\` or \`feature:\` in PR title, or \`[feature]\` tag
396405 - **PATCH**: Default for fixes and other changes
397-
406+
398407 ### 🚀 To Auto-publish
399408 Create a new PR from a branch with the appropriate prefix, or use the [manual publish workflow](https://github.com/${{ github.repository }}/actions/workflows/manual-publish.yml).`;
400-
409+
401410 await github.rest.issues.createComment({
402411 issue_number: context.issue.number,
403412 owner: context.repo.owner,
404413 repo: context.repo.repo,
405414 body: comment
406- });
415+ });
0 commit comments