@codfish/actions 2.0.1 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +135 -64
  2. package/bin/generate-docs.js +10 -10
  3. package/comment/README.md +9 -9
  4. package/comment/action.yml +3 -3
  5. package/npm-publish-pr/README.md +319 -40
  6. package/npm-publish-pr/action.yml +271 -87
  7. package/package.json +19 -14
  8. package/setup-node-and-install/README.md +77 -34
  9. package/setup-node-and-install/action.yml +36 -3
  10. package/.github/codeql-config.yml +0 -21
  11. package/.github/dependabot.yml +0 -35
  12. package/.github/workflows/claude-code-review.yml +0 -43
  13. package/.github/workflows/claude.yml +0 -38
  14. package/.github/workflows/release.yml +0 -48
  15. package/.github/workflows/security.yml +0 -103
  16. package/.github/workflows/update-docs.yml +0 -38
  17. package/.github/workflows/validate.yml +0 -210
  18. package/.husky/pre-commit +0 -1
  19. package/.nvmrc +0 -1
  20. package/AGENT.md +0 -149
  21. package/CLAUDE.md +0 -3
  22. package/CONTRIBUTING.md +0 -316
  23. package/SECURITY.md +0 -208
  24. package/eslint.config.js +0 -8
  25. package/tests/fixtures/.node-version +0 -1
  26. package/tests/fixtures/.nvmrc +0 -1
  27. package/tests/fixtures/lockfiles/package-lock.json +0 -12
  28. package/tests/fixtures/lockfiles/pnpm-lock.yaml +0 -9
  29. package/tests/fixtures/lockfiles/yarn.lock +0 -7
  30. package/tests/fixtures/package-json/minimal.json +0 -4
  31. package/tests/fixtures/package-json/scoped.json +0 -6
  32. package/tests/fixtures/package-json/valid.json +0 -13
  33. package/tests/integration/comment/basic.bats +0 -95
  34. package/tests/integration/npm-pr-version/basic.bats +0 -438
  35. package/tests/integration/setup-node-and-install/basic.bats +0 -638
  36. package/tests/scripts/test-helpers.sh +0 -113
  37. package/tests/scripts/test-runner.sh +0 -115
@@ -1,13 +1,15 @@
1
1
  # npm-publish-pr
2
2
 
3
- Publishes packages with PR-specific version numbers for testing in downstream applications before merging. Automatically
4
- detects your package manager (npm, yarn, or pnpm) and uses the appropriate publish command. The action generates
5
- versions in the format `0.0.0-PR-{number}--{short-sha}` and automatically comments on the pull request with the
6
- published version.
3
+ Publishes packages with PR-specific version numbers for testing in downstream applications before merging. Supports both
4
+ **OIDC trusted publishing** (recommended) and token-based authentication. Automatically detects your package manager
5
+ (npm, yarn, or pnpm) for token-based publishing. The action generates versions in the format
6
+ `0.0.0-PR-{number}--{short-sha}` and automatically comments on the pull request with the published version.
7
7
 
8
8
  **Key Features:**
9
9
 
10
- - Automatic package manager detection (npm/yarn/pnpm)
10
+ - **OIDC trusted publishing** support (no secrets required for public packages!)
11
+ - Token-based authentication fallback for private packages
12
+ - Automatic package manager detection (npm/yarn/pnpm) for token mode
11
13
  - Automatic PR version generation
12
14
  - Publishes to registry with `pr` tag
13
15
  - Automatic PR commenting with version info
@@ -15,75 +17,234 @@ published version.
15
17
 
16
18
  <!-- DOCTOC SKIP -->
17
19
 
20
+ ## Migrating to OIDC Trusted Publishing
21
+
22
+ If you're currently using token-based authentication (`npm-token`), migrating to OIDC is recommended for public
23
+ packages. OIDC provides better security, automatic provenance attestations, and eliminates the need to manage npm
24
+ tokens.
25
+
26
+ ### Requirements
27
+
28
+ 1. **Public package** - OIDC trusted publishing only works with public repos & npm packages
29
+ 2. **npm 11.5.1+** - Required for OIDC support
30
+ - ✅ **Automatic**: Use `setup-node-and-install@v3` and it handles the npm upgrade for you
31
+ - 🔧 **Manual**: Run `npm install -g npm@^11.5.1` before publishing
32
+ 3. **Configure trusted publisher on npmjs.com** - One-time setup per package
33
+ 4. **Update workflow permissions** - Add `id-token: write` to your workflow
34
+
35
+ ### Migration Steps
36
+
37
+ 1. **Configure trusted publisher on npmjs.com:**
38
+ - Go to https://www.npmjs.com/package/YOUR-PACKAGE/access
39
+ - Click "Add trusted publisher"
40
+ - Fill in:
41
+ - Provider: `GitHub Actions`
42
+ - Organization/User: `your-github-username`
43
+ - Repository: `your-repo-name`
44
+ - Workflow: `<file>.yml` (exact filename, not the workflow `name`!)
45
+ - Environment: Leave blank (unless using GitHub environments)
46
+
47
+ 2. **Update your workflow:**
48
+
49
+ ```diff
50
+ on: pull_request_target
51
+
52
+ jobs:
53
+ publish:
54
+ runs-on: ubuntu-latest
55
+
56
+ + permissions:
57
+ + contents: read
58
+ + id-token: write
59
+ + pull-requests: write
60
+
61
+ steps:
62
+ + # Use v3 for automatic npm 11.5.1+ upgrade
63
+ + - uses: codfish/actions/setup-node-and-install@v3
64
+ +
65
+ - uses: codfish/actions/npm-pr-version@v3
66
+ - with:
67
+ - npm-token: ${{ secrets.NPM_TOKEN }}
68
+ ```
69
+
70
+ 3. **Test on a PR** - Create a test PR to verify OIDC publishing works
71
+
72
+ 4. **Remove npm token** - Once confirmed working, you can delete the `NPM_TOKEN` secret
73
+
18
74
  ## Usage
19
75
 
20
76
  See [action.yml](action.yml).
21
77
 
22
- ```yaml
23
- steps:
24
- - uses: actions/checkout@v5
78
+ ### OIDC Trusted Publishing (Recommended for Public Packages)
79
+
80
+ No npm token required! Just configure your package on npmjs.com for trusted publishing.
81
+
82
+ ```yml
83
+ on: pull_request
84
+
85
+ jobs:
86
+ publish:
87
+ permissions:
88
+ id-token: write
89
+ pull-requests: write
90
+
91
+ steps:
92
+ - uses: actions/checkout@v6
93
+
94
+ - uses: codfish/actions/setup-node-and-install@v3
95
+ with:
96
+ node-version: lts/*
97
+
98
+ - run: npm run build
99
+
100
+ - uses: codfish/actions/npm-pr-version@v3
101
+ ```
102
+
103
+ > **Note:** `setup-node-and-install@v3` automatically upgrades npm to v11 (required for OIDC).
104
+
105
+ ### Token-Based Authentication (For Private Packages)
106
+
107
+ ```yml
108
+ on: pull_request
109
+
110
+ jobs:
111
+ publish:
112
+ permissions:
113
+ pull-requests: write
114
+
115
+ steps:
116
+ - uses: actions/checkout@v6
117
+
118
+ - uses: codfish/actions/setup-node-and-install@v3
119
+ with:
120
+ node-version: lts/*
121
+
122
+ - run: npm run build
123
+
124
+ - uses: codfish/actions/npm-pr-version@v3
125
+ with:
126
+ npm-token: ${{ secrets.NPM_TOKEN }}
127
+ ```
25
128
 
26
- - uses: codfish/actions/setup-node-and-install@v2
27
- with:
28
- node-version: lts/*
129
+ ### Tarball Mode (Secure for pull_request_target)
29
130
 
30
- - run: npm run build
131
+ For `pull_request_target` workflows, use tarball mode to prevent execution of malicious lifecycle scripts from untrusted
132
+ PRs:
31
133
 
32
- - uses: codfish/actions/npm-pr-version@v2
33
- with:
34
- npm-token: ${{ secrets.NPM_TOKEN }}
35
- github-token: ${{ secrets.GITHUB_TOKEN }}
134
+ ```yml
135
+ on: pull_request_target
136
+
137
+ jobs:
138
+ build:
139
+ runs-on: ubuntu-latest
140
+ steps:
141
+ - uses: actions/checkout@v6
142
+ with:
143
+ ref: ${{ github.event.pull_request.head.sha }}
144
+
145
+ - uses: codfish/actions/setup-node-and-install@v3
146
+ - run: npm run build
147
+ - run: npm pack
148
+
149
+ - uses: actions/upload-artifact@v4
150
+ with:
151
+ name: package-tarball
152
+ path: '*.tgz'
153
+
154
+ publish:
155
+ needs: build
156
+ runs-on: ubuntu-latest
157
+ permissions:
158
+ id-token: write
159
+ pull-requests: write
160
+ steps:
161
+ - uses: actions/download-artifact@v4
162
+ with:
163
+ name: package-tarball
164
+
165
+ - uses: codfish/actions/npm-pr-version@v3
166
+ with:
167
+ tarball: '*.tgz' # Publishes with --ignore-scripts
36
168
  ```
37
169
 
170
+ > **Security:** Tarball mode automatically uses `--ignore-scripts` to prevent lifecycle script execution. See
171
+ > [SECURITY.md](../SECURITY.md#npm-publishing-npm-pr-version) for complete security considerations.
172
+
38
173
  ### Disable PR Comments
39
174
 
40
- ```yaml
41
- - uses: codfish/actions/npm-pr-version@v2
175
+ ```yml
176
+ - uses: codfish/actions/npm-pr-version@v3
42
177
  with:
43
178
  npm-token: ${{ secrets.NPM_TOKEN }}
44
- github-token: ${{ secrets.GITHUB_TOKEN }}
45
179
  comment: false
46
180
  ```
47
181
 
48
182
  ### Custom Comment Tag
49
183
 
50
- ```yaml
51
- - uses: codfish/actions/npm-pr-version@v2
184
+ ```yml
185
+ - uses: codfish/actions/npm-pr-version@v3
52
186
  with:
53
187
  npm-token: ${{ secrets.NPM_TOKEN }}
54
- github-token: ${{ secrets.GITHUB_TOKEN }}
55
188
  comment-tag: my-custom-tag
56
189
  ```
57
190
 
58
191
  ## Complete Workflow Example
59
192
 
60
- ```yaml
193
+ ### With OIDC (Recommended)
194
+
195
+ ```yml
61
196
  name: PR Package Testing
62
197
 
63
198
  on: pull_request_target
64
199
 
65
- permissions:
66
- contents: write
67
- pull-requests: write
200
+ jobs:
201
+ publish-pr-package:
202
+ runs-on: ubuntu-latest
203
+
204
+ permissions:
205
+ contents: read
206
+ id-token: write
207
+ pull-requests: write
208
+
209
+ steps:
210
+ - uses: actions/checkout@v6
211
+
212
+ - uses: codfish/actions/setup-node-and-install@v3
213
+
214
+ - name: Build package
215
+ run: npm run build
216
+
217
+ - name: Publish PR package
218
+ uses: codfish/actions/npm-pr-version@v3
219
+ ```
220
+
221
+ ### With Token (Private Packages)
222
+
223
+ ```yml
224
+ name: PR Package Testing
225
+
226
+ on: pull_request_target
68
227
 
69
228
  jobs:
70
229
  publish-pr-package:
71
230
  runs-on: ubuntu-latest
231
+
232
+ permissions:
233
+ contents: read
234
+ pull-requests: write
235
+
72
236
  steps:
73
- - uses: actions/checkout@v5
237
+ - uses: actions/checkout@v6
74
238
 
75
- - uses: codfish/actions/setup-node-and-install@v2
76
- with:
77
- node-version: 'lts/*'
239
+ - uses: codfish/actions/setup-node-and-install@v3
78
240
 
79
241
  - name: Build package
80
242
  run: npm run build
81
243
 
82
244
  - name: Publish PR package
83
- uses: codfish/actions/npm-pr-version@v2
245
+ uses: codfish/actions/npm-pr-version@v3
84
246
  with:
85
247
  npm-token: ${{ secrets.NPM_TOKEN }}
86
- github-token: ${{ secrets.GITHUB_TOKEN }}
87
248
  ```
88
249
 
89
250
  ## Testing Downstream
@@ -100,18 +261,30 @@ The package is published under the `pr` tag, so it won't interfere with your reg
100
261
 
101
262
  <!-- start inputs -->
102
263
 
103
- | Input | Description | Required | Default |
104
- | -------------- | ----------------------------------------------------------------------------------- | -------- | ---------------- |
105
- | `npm-token` | Registry authentication token with publish permissions (works with npm/yarn/pnpm) | Yes | - |
106
- | `github-token` | GitHub token with pull request comment permissions (typically secrets.GITHUB_TOKEN) | Yes | - |
107
- | `comment` | Whether to comment on the PR with the published version (true/false) | No | `true` |
108
- | `comment-tag` | Tag to use for PR comments (for comment identification and updates) | No | `npm-publish-pr` |
264
+ | Input | Description | Required | Default |
265
+ | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------- |
266
+ | `npm-token` | Registry authentication token with publish permissions. If not provided, OIDC trusted publishing will be used. | No | - |
267
+ | `tarball` | Path to pre-built tarball to publish (e.g., '\*.tgz'). When provided, publishes the tarball with --ignore-scripts for security. Recommended for pull_request_target workflows to prevent execution of malicious lifecycle scripts. | No | - |
268
+ | `comment` | Whether to comment on the PR with the published version (true/false) | No | `true` |
269
+ | `comment-tag` | Tag to use for PR comments (for comment identification and updates) | No | `npm-publish-pr` |
109
270
 
110
271
  <!-- end inputs -->
111
272
 
112
- ## Package Manager Support
273
+ ## Authentication Modes
274
+
275
+ ### OIDC Trusted Publishing (Recommended)
276
+
277
+ When `npm-token` is not provided, the action uses OIDC trusted publishing:
113
278
 
114
- The action automatically detects your package manager and uses the appropriate publish command:
279
+ - **Requires**: `id-token: write` permission in workflow
280
+ - **Works with**: Public packages only
281
+ - **Command**: Always uses `npm publish --access public --tag pr --provenance`
282
+ - **Benefits**: No secrets required, automatic provenance attestations
283
+ - **Setup**: Configure trusted publisher on npmjs.com (see [npm docs](https://docs.npmjs.com/trusted-publishers))
284
+
285
+ ### Token-Based Authentication
286
+
287
+ When `npm-token` is provided, the action detects your package manager:
115
288
 
116
289
  - **npm**: Uses `npm publish --access public --tag pr`
117
290
  - **yarn**: Uses `yarn publish --access public --tag pr --new-version {version} --no-git-tag-version`
@@ -143,3 +316,109 @@ Examples:
143
316
 
144
317
  - `0.0.0-PR-123--abc1234` (PR #123, commit abc1234)
145
318
  - `0.0.0-PR-456--def5678` (PR #456, commit def5678)
319
+
320
+ ## Troubleshooting
321
+
322
+ ### Error: "Access token expired or revoked" / 404 Not Found
323
+
324
+ This error typically occurs when using OIDC trusted publishing and indicates one of the following issues:
325
+
326
+ #### Missing `id-token: write` Permission
327
+
328
+ **Symptom:**
329
+
330
+ ```txt
331
+ npm notice Access token expired or revoked. Please try logging in again.
332
+ npm error code E404
333
+ npm error 404 Not Found - PUT https://registry.npmjs.org/@your-package
334
+ ```
335
+
336
+ **Solution:** Add `id-token: write` permission to your workflow:
337
+
338
+ ```yml
339
+ permissions:
340
+ id-token: write # REQUIRED for OIDC!
341
+ ```
342
+
343
+ Without this permission, GitHub cannot generate the OIDC token needed for npm trusted publishing.
344
+
345
+ #### Workflow Name Mismatch
346
+
347
+ **Symptom:** Same 404 error, but permissions are set correctly.
348
+
349
+ **Solution:** Verify your npm trusted publisher configuration matches exactly:
350
+
351
+ - Repository name is case-sensitive: `my-repo` ≠ `My-Repo`
352
+ - Workflow filename must be exact: `validate.yml` not `.github/workflows/validate.yml` or `Validate Code`
353
+ - Check at: https://www.npmjs.com/package/YOUR-PACKAGE/access
354
+
355
+ #### Publishing from a Fork
356
+
357
+ **Symptom:** 404 error when PR is from a forked repository.
358
+
359
+ **Solution:** OIDC tokens are not available for forked PRs. Add a condition to skip publishing:
360
+
361
+ ```yml
362
+ - uses: codfish/actions/npm-pr-version@v3
363
+ if: github.event.pull_request.head.repo.full_name == github.repository
364
+ ```
365
+
366
+ #### Private Package with OIDC
367
+
368
+ **Symptom:** 404 error on private package.
369
+
370
+ **Solution:** OIDC trusted publishing only works with **public packages**. For private packages, use token-based
371
+ authentication:
372
+
373
+ ```yml
374
+ - uses: codfish/actions/npm-pr-version@v3
375
+ with:
376
+ npm-token: ${{ secrets.NPM_TOKEN }}
377
+ ```
378
+
379
+ ### Error: npm version too old
380
+
381
+ **Symptom:**
382
+
383
+ ```txt
384
+ npm ERR! --provenance flag is not supported
385
+ ```
386
+
387
+ **Solution:** OIDC trusted publishing requires npm 11.5.1+. Use `setup-node-and-install@v3` which automatically upgrades
388
+ npm to v11 for you:
389
+
390
+ ```yml
391
+ - uses: codfish/actions/setup-node-and-install@v3
392
+ with:
393
+ node-version: lts/*
394
+ ```
395
+
396
+ This action will upgrade npm from whatever version comes with Node.js to v11 (pinned to `^11.5.1`), ensuring OIDC
397
+ compatibility.
398
+
399
+ **Manual alternative:** If not using the setup action, upgrade npm yourself:
400
+
401
+ ```yml
402
+ - run: npm install -g npm@^11.5.1
403
+ ```
404
+
405
+ ### Debugging OIDC Issues
406
+
407
+ To debug OIDC authentication issues, check the workflow logs for:
408
+
409
+ 1. **OIDC environment variables** - Should see:
410
+
411
+ ```txt
412
+ 🔐 Using OIDC trusted publishing (no npm-token provided)
413
+ ```
414
+
415
+ 2. **npm version** - Should be 11.5.1 or higher:
416
+
417
+ ```txt
418
+ npm version: 11.5.1
419
+ ```
420
+
421
+ 3. **Verify permissions** - Check workflow run permissions in GitHub UI
422
+
423
+ 4. **Check npm configuration** - Go to npmjs.com → Your Package → Publishing Access → Verify trusted publisher settings
424
+ match your workflow exactly