17
17
auto-publish :
18
18
if : github.event.pull_request.merged == true
19
19
runs-on : ubuntu-latest
20
-
20
+
21
21
steps :
22
22
- name : Checkout code
23
23
uses : actions/checkout@v4
29
29
run : |
30
30
corepack enable
31
31
yarn --version
32
-
32
+
33
33
# Always run yarn install to ensure lockfile exists and is up to date
34
34
echo "📦 Running yarn install..."
35
35
yarn install
48
48
run : |
49
49
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
50
50
echo "Branch name: $BRANCH_NAME"
51
-
51
+
52
52
# Simplified pattern that properly handles hyphens, underscores, and dots
53
53
if [[ $BRANCH_NAME =~ ^(feat|feature|fix|bugfix|break|breaking|hotfix|chore)/[a-zA-Z0-9._-]+$ ]]; then
54
54
echo "✅ Branch pattern accepted: $BRANCH_NAME"
@@ -69,17 +69,26 @@ jobs:
69
69
run : |
70
70
# Verify that package.json is well-formed
71
71
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
+ "
83
92
84
93
- name : Run quality checks
85
94
if : steps.validate-branch.outputs.should_publish == 'true'
89
98
echo "🔍 Running linter..."
90
99
yarn lint
91
100
fi
92
-
101
+
93
102
# Type checking
94
103
if yarn run --help | grep -q "type-check"; then
95
104
echo "🔍 Type checking..."
@@ -101,7 +110,7 @@ jobs:
101
110
run : |
102
111
echo "🧪 Running tests..."
103
112
yarn test:ci
104
-
113
+
105
114
# Check coverage if exists
106
115
if [ -f "coverage/lcov.info" ]; then
107
116
echo "📊 Coverage report generated"
@@ -112,7 +121,7 @@ jobs:
112
121
run : |
113
122
echo "🏗️ Building package..."
114
123
yarn dist
115
-
124
+
116
125
# Verify that the build generated files
117
126
if [ ! -d "dist" ] && [ ! -d "lib" ] && [ ! -d "build" ]; then
118
127
echo "❌ No build output found"
@@ -132,11 +141,11 @@ jobs:
132
141
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
133
142
PR_TITLE="${{ github.event.pull_request.title }}"
134
143
PR_BODY="${{ github.event.pull_request.body }}"
135
-
144
+
136
145
echo "🔍 Analyzing PR for version bump..."
137
146
echo "Branch: $BRANCH_NAME"
138
147
echo "Title: $PR_TITLE"
139
-
148
+
140
149
# 1. Check explicit breaking change markers
141
150
if echo "$PR_BODY" | grep -qi "BREAKING CHANGE:" || \
142
151
echo "$PR_TITLE" | grep -q "!" || \
@@ -146,14 +155,14 @@ jobs:
146
155
VERSION_TYPE="major"
147
156
REASON="Breaking change detected"
148
157
echo "💥 MAJOR: $REASON"
149
-
158
+
150
159
# 2. Check conventional commits in title
151
160
elif echo "$PR_TITLE" | grep -Eq "^(feat|feature)(\(.+\))?!:" || \
152
161
echo "$PR_TITLE" | grep -Eq "^(fix|bugfix)(\(.+\))?!:"; then
153
162
VERSION_TYPE="major"
154
163
REASON="Breaking change in conventional commit"
155
164
echo "💥 MAJOR: $REASON"
156
-
165
+
157
166
# 3. Check features (minor)
158
167
elif echo "$PR_TITLE" | grep -Eq "^(feat|feature)(\(.+\))?:" || \
159
168
[[ $BRANCH_NAME =~ ^feat/ ]] || \
@@ -162,25 +171,25 @@ jobs:
162
171
VERSION_TYPE="minor"
163
172
REASON="New feature detected"
164
173
echo "✨ MINOR: $REASON"
165
-
174
+
166
175
# 4. Check fixes and other changes (patch)
167
176
else
168
177
VERSION_TYPE="patch"
169
178
REASON="Bug fix or other changes"
170
179
echo "🐛 PATCH: $REASON"
171
180
fi
172
-
181
+
173
182
# Get current version
174
183
CURRENT_VERSION=$(node -p "require('./package.json').version")
175
184
echo "📦 Current version: $CURRENT_VERSION"
176
-
185
+
177
186
# Calculate new version
178
187
NEW_VERSION=$(node -e "
179
188
const semver = require('semver');
180
189
const current = '$CURRENT_VERSION';
181
190
console.log(semver.inc(current, '$VERSION_TYPE'));
182
191
")
183
-
192
+
184
193
echo "🚀 New version will be: $NEW_VERSION"
185
194
echo "🎯 Decision reason: $REASON"
186
195
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
@@ -193,13 +202,13 @@ jobs:
193
202
run : |
194
203
NEW_VERSION="${{ steps.version-bump.outputs.new_version }}"
195
204
PACKAGE_NAME=$(node -p "require('./package.json').name")
196
-
205
+
197
206
# Check if version already exists in NPM
198
207
if npm view "$PACKAGE_NAME@$NEW_VERSION" version 2>/dev/null; then
199
208
echo "❌ Version $NEW_VERSION already exists in NPM"
200
209
exit 1
201
210
fi
202
-
211
+
203
212
# Check if tag already exists
204
213
if git tag -l | grep -q "^v$NEW_VERSION$"; then
205
214
echo "❌ Tag v$NEW_VERSION already exists"
@@ -213,20 +222,20 @@ jobs:
213
222
VERSION_TYPE="${{ steps.version-bump.outputs.version_type }}"
214
223
BRANCH_NAME="${{ steps.validate-branch.outputs.branch_name }}"
215
224
REASON="${{ steps.version-bump.outputs.reason }}"
216
-
225
+
217
226
# Update package.json
218
227
npm version $NEW_VERSION --no-git-tag-version
219
-
228
+
220
229
# Commit and tag
221
230
git add package.json yarn.lock 2>/dev/null || git add package.json
222
231
git commit -m "chore(release): $NEW_VERSION
223
232
224
233
Released from: $BRANCH_NAME
225
234
Type: $VERSION_TYPE
226
235
Reason: $REASON
227
-
236
+
228
237
[skip ci]"
229
-
238
+
230
239
git tag "v$NEW_VERSION" -m "Release v$NEW_VERSION"
231
240
232
241
- name : Dry run publish (verification)
@@ -243,16 +252,16 @@ jobs:
243
252
run : |
244
253
NEW_VERSION="${{ steps.version-bump.outputs.new_version }}"
245
254
VERSION_TYPE="${{ steps.version-bump.outputs.version_type }}"
246
-
255
+
247
256
echo "📦 Publishing to NPM..."
248
-
257
+
249
258
if [[ "$VERSION_TYPE" == "major" ]]; then
250
259
echo "⚠️ Publishing MAJOR version $NEW_VERSION"
251
260
npm publish --access public --tag latest
252
261
else
253
262
npm publish --access public --tag latest
254
263
fi
255
-
264
+
256
265
echo "✅ Successfully published to NPM"
257
266
echo "published=true" >> $GITHUB_OUTPUT
258
267
env :
@@ -274,21 +283,21 @@ jobs:
274
283
name : Release v${{ steps.version-bump.outputs.new_version }}
275
284
body : |
276
285
## 🚀 Release v${{ steps.version-bump.outputs.new_version }}
277
-
286
+
278
287
**Type:** ${{ steps.version-bump.outputs.version_type }} release
279
288
**Branch:** `${{ steps.validate-branch.outputs.branch_name }}`
280
289
**Previous:** `${{ steps.version-bump.outputs.current_version }}`
281
-
290
+
282
291
### 📝 Changes
283
292
- ${{ github.event.pull_request.title }} (#${{ github.event.pull_request.number }})
284
-
293
+
285
294
### 📦 Installation
286
295
```bash
287
296
npm install @kubit-ui-web/react-components@${{ steps.version-bump.outputs.new_version }}
288
297
# or
289
298
yarn add @kubit-ui-web/react-components@${{ steps.version-bump.outputs.new_version }}
290
299
```
291
-
300
+
292
301
### 🔗 Links
293
302
- [NPM Package](https://www.npmjs.com/package/@kubit-ui-web/react-components/v/${{ steps.version-bump.outputs.new_version }})
294
303
- [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:
308
317
current_version: '${{ steps.version-bump.outputs.current_version }}'
309
318
};
310
319
const branchName = '${{ steps.validate-branch.outputs.branch_name }}';
311
-
320
+
312
321
const emoji = version_type === 'major' ? '💥' : version_type === 'minor' ? '✨' : '🐛';
313
-
322
+
314
323
const comment = `## ${emoji} Auto-publish Successful!
315
-
324
+
316
325
| Field | Value |
317
326
|-------|-------|
318
327
| **Branch** | \`${branchName}\` |
319
328
| **Type** | \`${version_type}\` |
320
329
| **Version** | \`${current_version}\` → \`${new_version}\` |
321
330
| **NPM** | [@kubit-ui-web/react-components@${new_version}](https://www.npmjs.com/package/@kubit-ui-web/react-components/v/${new_version}) |
322
-
331
+
323
332
### 📦 Installation
324
333
\`\`\`bash
325
334
npm install @kubit-ui-web/react-components@${new_version}
326
335
# or
327
336
yarn add @kubit-ui-web/react-components@${new_version}
328
337
\`\`\`
329
-
338
+
330
339
### ✅ Completed Steps
331
340
- [x] Quality checks passed
332
341
- [x] Tests passed
333
342
- [x] Build successful
334
343
- [x] Published to NPM
335
344
- [x] GitHub release created
336
345
- [x] Repository tagged
337
-
346
+
338
347
🎉 **Ready to use in production!**`;
339
-
348
+
340
349
await github.rest.issues.createComment({
341
350
issue_number: context.issue.number,
342
351
owner: context.repo.owner,
@@ -350,20 +359,20 @@ jobs:
350
359
with :
351
360
script : |
352
361
const comment = `## ❌ Auto-publish Failed
353
-
362
+
354
363
The automatic publication process failed. Please check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
355
-
364
+
356
365
### 🔧 Common Solutions
357
366
- Verify NPM_TOKEN is valid and has publish permissions
358
367
- Check if version already exists
359
368
- Ensure all tests pass locally
360
369
- Verify build process completes successfully
361
-
370
+
362
371
### 📞 Next Steps
363
372
1. Fix the issue based on the error logs
364
373
2. Create a new PR with the same changes
365
374
3. Or use manual publish workflow if urgent`;
366
-
375
+
367
376
await github.rest.issues.createComment({
368
377
issue_number: context.issue.number,
369
378
owner: context.repo.owner,
@@ -377,30 +386,30 @@ jobs:
377
386
with :
378
387
script : |
379
388
const branchName = '${{ github.event.pull_request.head.ref }}';
380
-
389
+
381
390
const comment = `## ℹ️ Auto-publish Skipped
382
-
391
+
383
392
Branch \`${branchName}\` doesn't match required patterns for auto-publishing.
384
-
393
+
385
394
### 📋 Required Patterns
386
395
| Pattern | Version Bump | Detection Method |
387
396
|---------|--------------|------------------|
388
397
| \`feat/\*\` or \`feature/\*\` | **minor** | Branch prefix or PR title |
389
398
| \`fix/\*\` or \`bugfix/\*\` | **patch** | Branch prefix or default |
390
399
| \`break/\*\` or \`breaking/\*\` | **major** | Branch prefix |
391
400
| \`hotfix/\*\` or \`chore/\*\` | **patch** | Branch prefix |
392
-
401
+
393
402
### 🎯 Advanced Version Detection
394
403
- **MAJOR**: \`BREAKING CHANGE:\` in PR body, \`!\` in title, or \`[breaking]\` tag
395
404
- **MINOR**: \`feat:\` or \`feature:\` in PR title, or \`[feature]\` tag
396
405
- **PATCH**: Default for fixes and other changes
397
-
406
+
398
407
### 🚀 To Auto-publish
399
408
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
+
401
410
await github.rest.issues.createComment({
402
411
issue_number: context.issue.number,
403
412
owner: context.repo.owner,
404
413
repo: context.repo.repo,
405
414
body: comment
406
- });
415
+ });
0 commit comments