1
+
1
2
name : Auto Publish to NPM
2
3
4
+ # This workflow requires two secrets to be configured in the repository:
5
+ #
6
+ # 1. NPM_TOKEN: An NPM automation token for publishing packages
7
+ # - Go to npmjs.com → Profile → Access Tokens → Generate New Token
8
+ # - Select "Automation" type (bypasses 2FA)
9
+ # - Ensure it has publish permissions for your package
10
+ #
11
+ # 2. RELEASE_TOKEN: A GitHub Personal Access Token for bypassing branch protection
12
+ # - Go to github.com → Settings → Developer settings → Personal access tokens
13
+ # - Generate a "Classic" token with these permissions:
14
+ # - repo (Full control of private repositories)
15
+ # - workflow (Update GitHub Action workflows)
16
+ # - OR use Fine-grained PAT with "Contents: write" and "Pull requests: write"
17
+ # - If main branch is protected, ensure the token can bypass pull request requirements
18
+
3
19
on :
4
20
pull_request :
5
21
types : [closed]
23
39
uses : actions/checkout@v4
24
40
with :
25
41
fetch-depth : 0
26
- token : ${{ secrets.GITHUB_TOKEN }}
42
+ token : ${{ secrets.RELEASE_TOKEN || secrets. GITHUB_TOKEN }}
27
43
28
44
- name : Setup Yarn and generate lockfile
29
45
run : |
@@ -130,9 +146,19 @@ jobs:
130
146
- name : Configure Git
131
147
if : steps.validate-branch.outputs.should_publish == 'true'
132
148
run : |
149
+ # Configure git with release token for branch protection bypass
133
150
git config --local user.email "[email protected] "
134
151
git config --local user.name "Kubit Release Bot"
135
152
153
+ # Set up authentication for push operations
154
+ if [ -n "${{ secrets.RELEASE_TOKEN }}" ]; thenn
155
+ echo "🔐 Using RELEASE_TOKEN with branch protection bypass permissions"
156
+ git remote set-url origin https://x-access-token:${{ secrets.RELEASE_TOKEN }}@github.com/${{ github.repository }}.git
157
+ else
158
+ echo "⚠️ Using default GITHUB_TOKEN - may fail on protected branches"
159
+ echo "💡 Add RELEASE_TOKEN secret with 'Contents: write' and 'Pull requests: write' permissions"
160
+ fi
161
+
136
162
- name : Determine version bump (Enhanced)
137
163
if : steps.validate-branch.outputs.should_publish == 'true'
138
164
id : version-bump
@@ -254,7 +280,6 @@ jobs:
254
280
if : steps.validate-branch.outputs.should_publish == 'true'
255
281
run : |
256
282
echo "🔍 Performing dry run..."
257
- echo "ℹ️ Using NPM automation token (bypasses 2FA)"
258
283
npm publish --dry-run --access public
259
284
env :
260
285
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
@@ -267,7 +292,6 @@ jobs:
267
292
VERSION_TYPE="${{ steps.version-bump.outputs.version_type }}"
268
293
269
294
echo "📦 Publishing to NPM..."
270
- echo "🔐 Using NPM automation token (bypasses 2FA)"
271
295
272
296
if [[ "$VERSION_TYPE" == "major" ]]; then
273
297
echo "⚠️ Publishing MAJOR version $NEW_VERSION"
@@ -285,9 +309,22 @@ jobs:
285
309
if : steps.npm-publish.outputs.published == 'true'
286
310
run : |
287
311
echo "📤 Pushing changes to repository..."
288
- git push origin main
289
- git push origin --tags
290
- echo "✅ Changes pushed successfully"
312
+
313
+ if [ -n "${{ secrets.RELEASE_TOKEN }}" ]; then
314
+ echo "🔐 Using RELEASE_TOKEN to bypass branch protection"
315
+ git push origin main
316
+ git push origin --tags
317
+ echo "✅ Changes and tags pushed successfully to main"
318
+ else
319
+ echo "⚠️ Using GITHUB_TOKEN - attempting push (may fail on protected branches)"
320
+ if git push origin main && git push origin --tags; then
321
+ echo "✅ Changes and tags pushed successfully"
322
+ else
323
+ echo "❌ Push failed - likely due to branch protection rules"
324
+ echo "💡 Consider adding RELEASE_TOKEN secret with bypass permissions"
325
+ exit 1
326
+ fi
327
+ fi
291
328
292
329
- name : Create GitHub Release
293
330
if : steps.npm-publish.outputs.published == 'true'
@@ -378,22 +415,26 @@ jobs:
378
415
379
416
### 🔧 Common Solutions
380
417
- **NPM Token**: Verify NPM_TOKEN is valid and has publish permissions
381
- - **Automation Token**: Ensure you're using an NPM automation token (bypasses 2FA)
382
- - **Token Permissions**: Check that the token has publish permissions for this package
418
+ - **Release Token**: Add RELEASE_TOKEN secret to bypass branch protection rules
419
+ - **Token Permissions**: Check that tokens have correct permissions
383
420
- **Version Conflict**: Check if version already exists in NPM
384
421
- **Build Issues**: Ensure all tests pass locally and build completes successfully
385
422
386
- ### 🔐 NPM Token Requirements
387
- 1. **Type**: Must be an "Automation" token from npmjs.com
388
- 2. **Scope**: Should have access to publish the package
389
- 3. **Permissions**: Must have publish permissions
390
- 4. **Secret**: Should be stored as NPM_TOKEN in repository secrets
423
+ ### 🔐 Required Secrets Configuration
424
+ 1. **NPM_TOKEN**:
425
+ - Type: "Automation" token from npmjs.com
426
+ - Scope: Access to publish the package
427
+
428
+ 2. **RELEASE_TOKEN** (Required for protected branches):
429
+ - Type: Personal Access Token with bypass permissions
430
+ - Permissions: "Contents: write", "Pull requests: write"
431
+ - Special: "Bypass pull request requirements" if needed
391
432
392
433
### 📞 Next Steps
393
- 1. Verify NPM_TOKEN is an automation token with correct permissions
394
- 2. Check the error logs for specific authentication issues
395
- 3. Create a new PR with the same changes
396
- 4. Or use manual publish workflow if urgent `;
434
+ 1. **NPM Issues**: Verify NPM_TOKEN is an automation token
435
+ 2. **Branch Protection**: Add RELEASE_TOKEN secret with bypass permissions
436
+ 3. **Logs**: Check error logs for specific authentication issues
437
+ 4. **Manual Process**: Create a new PR if tokens can't be configured `;
397
438
398
439
await github.rest.issues.createComment({
399
440
issue_number: context.issue.number,
0 commit comments