@codfish/actions 0.0.0-PR-58--24ced07
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.
- package/README.md +283 -0
- package/bin/generate-docs.js +432 -0
- package/comment/README.md +82 -0
- package/comment/action.yml +102 -0
- package/npm-publish-pr/README.md +424 -0
- package/npm-publish-pr/action.yml +362 -0
- package/package.json +57 -0
- package/setup-node-and-install/README.md +184 -0
- package/setup-node-and-install/action.yml +228 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
# npm-publish-pr
|
|
2
|
+
|
|
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
|
+
|
|
8
|
+
**Key Features:**
|
|
9
|
+
|
|
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
|
|
13
|
+
- Automatic PR version generation
|
|
14
|
+
- Publishes to registry with `pr` tag
|
|
15
|
+
- Automatic PR commenting with version info
|
|
16
|
+
- No git history modification
|
|
17
|
+
|
|
18
|
+
<!-- DOCTOC SKIP -->
|
|
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
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
See [action.yml](action.yml).
|
|
77
|
+
|
|
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
|
+
```
|
|
128
|
+
|
|
129
|
+
### Tarball Mode (Secure for pull_request_target)
|
|
130
|
+
|
|
131
|
+
For `pull_request_target` workflows, use tarball mode to prevent execution of malicious lifecycle scripts from untrusted
|
|
132
|
+
PRs:
|
|
133
|
+
|
|
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
|
|
168
|
+
```
|
|
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
|
+
|
|
173
|
+
### Disable PR Comments
|
|
174
|
+
|
|
175
|
+
```yml
|
|
176
|
+
- uses: codfish/actions/npm-pr-version@v3
|
|
177
|
+
with:
|
|
178
|
+
npm-token: ${{ secrets.NPM_TOKEN }}
|
|
179
|
+
comment: false
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Custom Comment Tag
|
|
183
|
+
|
|
184
|
+
```yml
|
|
185
|
+
- uses: codfish/actions/npm-pr-version@v3
|
|
186
|
+
with:
|
|
187
|
+
npm-token: ${{ secrets.NPM_TOKEN }}
|
|
188
|
+
comment-tag: my-custom-tag
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Complete Workflow Example
|
|
192
|
+
|
|
193
|
+
### With OIDC (Recommended)
|
|
194
|
+
|
|
195
|
+
```yml
|
|
196
|
+
name: PR Package Testing
|
|
197
|
+
|
|
198
|
+
on: pull_request_target
|
|
199
|
+
|
|
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
|
|
227
|
+
|
|
228
|
+
jobs:
|
|
229
|
+
publish-pr-package:
|
|
230
|
+
runs-on: ubuntu-latest
|
|
231
|
+
|
|
232
|
+
permissions:
|
|
233
|
+
contents: read
|
|
234
|
+
pull-requests: write
|
|
235
|
+
|
|
236
|
+
steps:
|
|
237
|
+
- uses: actions/checkout@v6
|
|
238
|
+
|
|
239
|
+
- uses: codfish/actions/setup-node-and-install@v3
|
|
240
|
+
|
|
241
|
+
- name: Build package
|
|
242
|
+
run: npm run build
|
|
243
|
+
|
|
244
|
+
- name: Publish PR package
|
|
245
|
+
uses: codfish/actions/npm-pr-version@v3
|
|
246
|
+
with:
|
|
247
|
+
npm-token: ${{ secrets.NPM_TOKEN }}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Testing Downstream
|
|
251
|
+
|
|
252
|
+
After the action runs, you can install the PR version in downstream projects:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
npm install my-package@0.0.0-PR-123--abc1234
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The package is published under the `pr` tag, so it won't interfere with your regular releases.
|
|
259
|
+
|
|
260
|
+
## Inputs
|
|
261
|
+
|
|
262
|
+
<!-- start inputs -->
|
|
263
|
+
|
|
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` |
|
|
270
|
+
|
|
271
|
+
<!-- end inputs -->
|
|
272
|
+
|
|
273
|
+
## Authentication Modes
|
|
274
|
+
|
|
275
|
+
### OIDC Trusted Publishing (Recommended)
|
|
276
|
+
|
|
277
|
+
When `npm-token` is not provided, the action uses OIDC trusted publishing:
|
|
278
|
+
|
|
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:
|
|
288
|
+
|
|
289
|
+
- **npm**: Uses `npm publish --access public --tag pr`
|
|
290
|
+
- **yarn**: Uses `yarn publish --access public --tag pr --new-version {version} --no-git-tag-version`
|
|
291
|
+
- **pnpm**: Uses `pnpm publish --access public --tag pr`
|
|
292
|
+
|
|
293
|
+
Detection is based on lockfile presence:
|
|
294
|
+
|
|
295
|
+
- `yarn.lock` → yarn
|
|
296
|
+
- `pnpm-lock.yaml` → pnpm
|
|
297
|
+
- `package-lock.json` or no lockfile → npm
|
|
298
|
+
|
|
299
|
+
## Outputs
|
|
300
|
+
|
|
301
|
+
<!-- start outputs -->
|
|
302
|
+
|
|
303
|
+
| Output | Description |
|
|
304
|
+
| --------------- | --------------------------------------------------------------------- |
|
|
305
|
+
| `version` | Generated PR-specific version number (0.0.0-PR-{number}--{short-sha}) |
|
|
306
|
+
| `package-name` | Package name from package.json |
|
|
307
|
+
| `error-message` | Error message if publish fails |
|
|
308
|
+
|
|
309
|
+
<!-- end outputs -->
|
|
310
|
+
|
|
311
|
+
## Version Format
|
|
312
|
+
|
|
313
|
+
Published versions follow the pattern: `0.0.0-PR-{pr-number}--{short-sha}`
|
|
314
|
+
|
|
315
|
+
Examples:
|
|
316
|
+
|
|
317
|
+
- `0.0.0-PR-123--abc1234` (PR #123, commit abc1234)
|
|
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
|