@anolilab/semantic-release-pnpm 3.0.0-alpha.1 → 3.0.0-alpha.2
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/CHANGELOG.md +16 -0
- package/README.md +53 -14
- package/dist/index.js +108 -27
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## @anolilab/semantic-release-pnpm [3.0.0-alpha.2](https://github.com/anolilab/semantic-release/compare/@anolilab/semantic-release-pnpm@3.0.0-alpha.1...@anolilab/semantic-release-pnpm@3.0.0-alpha.2) (2025-10-21)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* enhance npm authentication and trusted publishing support ([ccd056a](https://github.com/anolilab/semantic-release/commit/ccd056a02432b988fdcc79401d71182a433c4e97))
|
|
6
|
+
* update dependencies in pnpm-lock.yaml and pnpm-workspace.yaml ([001fd47](https://github.com/anolilab/semantic-release/commit/001fd4722fa6ba02c4d9479522ee2cb6f3d4067e))
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* update package manager and dependencies across multiple configurations ([07a4e0b](https://github.com/anolilab/semantic-release/commit/07a4e0be0c8ba0b8fc79f5d922bb62f60db38350))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Dependencies
|
|
14
|
+
|
|
15
|
+
* **@anolilab/rc:** upgraded to 3.0.0-alpha.2
|
|
16
|
+
|
|
1
17
|
## @anolilab/semantic-release-pnpm [3.0.0-alpha.1](https://github.com/anolilab/semantic-release/compare/@anolilab/semantic-release-pnpm@2.0.4...@anolilab/semantic-release-pnpm@3.0.0-alpha.1) (2025-10-14)
|
|
2
18
|
|
|
3
19
|
### ⚠ BREAKING CHANGES
|
package/README.md
CHANGED
|
@@ -62,29 +62,28 @@ The plugin can be configured in the [**semantic-release** configuration file](ht
|
|
|
62
62
|
|
|
63
63
|
### npm registry authentication
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
#### Official Registry
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
When publishing to the [official registry](https://registry.npmjs.org/), it is recommended to publish with authentication intended for automation:
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
- For improved security, and since access tokens have recently had their [maximum lifetimes restricted](https://github.blog/changelog/2025-09-29-strengthening-npm-security-important-changes-to-authentication-and-token-management/),
|
|
70
|
+
[trusted publishing](https://docs.npmjs.com/trusted-publishers) is recommended when publishing from a [supported CI provider](https://docs.npmjs.com/trusted-publishers#supported-cicd-providers)
|
|
71
|
+
- [Granular access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website) are recommended when publishing from a CI provider that is not supported by npm for trusted publishing, and can be set via [environment variables](#environment-variables).
|
|
72
|
+
Because these access tokens expire, rotation will need to be accounted for in this scenario.
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Provenance applies specifically to publishing, so our recommendation is to configure under `publishConfig` within the `package.json`.
|
|
74
|
+
> [!NOTE]
|
|
75
|
+
> When using trusted publishing, provenance attestations are automatically generated for your packages without requiring provenance to be explicitly enabled.
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
##### Trusted publishing from GitHub Actions
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
to be enabled on the job:
|
|
79
|
+
To leverage trusted publishing and publish with provenance from GitHub Actions, the `id-token: write` permission is required to be enabled on the job:
|
|
81
80
|
|
|
82
81
|
```yaml
|
|
83
82
|
permissions:
|
|
84
|
-
id-token: write # to enable use of OIDC for npm provenance
|
|
83
|
+
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
85
84
|
```
|
|
86
85
|
|
|
87
|
-
It's worth noting that if you are using semantic-release to its fullest with a GitHub release, GitHub comments,
|
|
86
|
+
It's also worth noting that if you are using semantic-release to its fullest with a GitHub release, GitHub comments,
|
|
88
87
|
and other features, then [more permissions are required](https://github.com/semantic-release/github#github-authentication) to be enabled on this job:
|
|
89
88
|
|
|
90
89
|
```yaml
|
|
@@ -92,11 +91,51 @@ permissions:
|
|
|
92
91
|
contents: write # to be able to publish a GitHub release
|
|
93
92
|
issues: write # to be able to comment on released issues
|
|
94
93
|
pull-requests: write # to be able to comment on released pull requests
|
|
95
|
-
id-token: write # to enable use of OIDC for npm provenance
|
|
94
|
+
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
|
96
95
|
```
|
|
97
96
|
|
|
98
97
|
Refer to the [GitHub Actions recipe for npm package provenance](https://semantic-release.gitbook.io/semantic-release/recipes/ci-configurations/github-actions#.github-workflows-release.yml-configuration-for-node-projects) for the full CI job's YAML code example.
|
|
99
98
|
|
|
99
|
+
##### Trusted publishing for GitLab Pipelines
|
|
100
|
+
|
|
101
|
+
To leverage trusted publishing and publish with provenance from GitLab Pipelines, `NPM_ID_TOKEN` needs to be added as an entry under `id_tokens` in the job definition with an audience of `npm:registry.npmjs.org`:
|
|
102
|
+
|
|
103
|
+
```yaml
|
|
104
|
+
id_tokens:
|
|
105
|
+
NPM_ID_TOKEN:
|
|
106
|
+
aud: "npm:registry.npmjs.org"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
See the [npm documentation for more details about configuring pipeline details](https://docs.npmjs.com/trusted-publishers#gitlab-cicd-configuration)
|
|
110
|
+
|
|
111
|
+
##### Unsupported CI providers
|
|
112
|
+
|
|
113
|
+
Token authentication is **required** and can be set via [environment variables](#environment-variables).
|
|
114
|
+
[Granular access tokens](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-granular-access-tokens-on-the-website) are recommended in this scenario, since trusted publishing is not available from all CI providers.
|
|
115
|
+
Because these access tokens expire, rotation will need to be accounted for in your process.
|
|
116
|
+
|
|
117
|
+
#### Alternative Registries
|
|
118
|
+
|
|
119
|
+
Token authentication is **required** and can be set via [environment variables](#environment-variables).
|
|
120
|
+
See the documentation for your registry for details on how to create a token for automation.
|
|
121
|
+
|
|
122
|
+
### npm provenance
|
|
123
|
+
|
|
124
|
+
When using trusted publishing to the official npm registry, provenance attestations are automatically generated for your packages without requiring provenance to be explicitly enabled.
|
|
125
|
+
|
|
126
|
+
For alternative registries or when using token-based authentication, provenance can be configured through the [other configuration options exposed by npm](https://docs.npmjs.com/generating-provenance-statements#using-third-party-package-publishing-tools).
|
|
127
|
+
Provenance applies specifically to publishing, so configure it under `publishConfig` within the `package.json`:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"publishConfig": {
|
|
132
|
+
"registry": "https://registry.npmjs.org/",
|
|
133
|
+
"tag": "latest",
|
|
134
|
+
"provenance": true
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
100
139
|
### Environment variables
|
|
101
140
|
|
|
102
141
|
| Variable | Description |
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { rc } from '@anolilab/rc';
|
|
|
27
27
|
import normalizeUrl from 'normalize-url';
|
|
28
28
|
import { findPackageJson, getPackageManagerVersion } from '@visulima/package';
|
|
29
29
|
import SemanticReleaseError from '@semantic-release/error';
|
|
30
|
+
import envCi from 'env-ci';
|
|
30
31
|
const {
|
|
31
32
|
stringify
|
|
32
33
|
} = __cjs_require("ini");
|
|
@@ -57,10 +58,12 @@ const getNpmrcPath = (cwd, environment) => {
|
|
|
57
58
|
return npmrcPath;
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
const
|
|
61
|
+
const OFFICIAL_REGISTRY = "https://registry.npmjs.org/";
|
|
62
|
+
const GITHUB_ACTIONS_PROVIDER_NAME = "GitHub Actions";
|
|
63
|
+
const GITLAB_PIPELINES_PROVIDER_NAME = "GitLab CI/CD";
|
|
61
64
|
|
|
62
65
|
const getRegistryUrl = (scope, npmrc) => {
|
|
63
|
-
let url =
|
|
66
|
+
let url = OFFICIAL_REGISTRY;
|
|
64
67
|
if (npmrc) {
|
|
65
68
|
const registryUrl = npmrc[`${scope}:registry`] ?? npmrc.registry;
|
|
66
69
|
if (registryUrl) {
|
|
@@ -74,11 +77,11 @@ const getRegistry = ({ name, publishConfig: { registry } = {} }, { cwd, env }) =
|
|
|
74
77
|
rc("npm", {
|
|
75
78
|
config: env.NPM_CONFIG_USERCONFIG ?? resolve(cwd, ".npmrc"),
|
|
76
79
|
cwd,
|
|
77
|
-
defaults: { registry:
|
|
80
|
+
defaults: { registry: OFFICIAL_REGISTRY }
|
|
78
81
|
}).config
|
|
79
82
|
);
|
|
80
83
|
|
|
81
|
-
const getReleaseInfo = ({ name }, { env: { DEFAULT_NPM_REGISTRY =
|
|
84
|
+
const getReleaseInfo = ({ name }, { env: { DEFAULT_NPM_REGISTRY = OFFICIAL_REGISTRY }, nextRelease: { version } }, distributionTag, registry) => {
|
|
82
85
|
return {
|
|
83
86
|
channel: distributionTag,
|
|
84
87
|
name: `pnpm package (@${distributionTag} dist-tag)`,
|
|
@@ -211,6 +214,15 @@ Your configuration for the \`branches\` option is \`${branches.join(",")}\`.`,
|
|
|
211
214
|
message: "Invalid `branches` option."
|
|
212
215
|
};
|
|
213
216
|
},
|
|
217
|
+
EINVALIDNPMAUTH: ({ registry }) => {
|
|
218
|
+
return {
|
|
219
|
+
details: `The [authentication required to publish](${linkify(
|
|
220
|
+
"README.md#npm-registry-authentication"
|
|
221
|
+
)}) configured in the \`NPM_TOKEN\` environment variable must be a valid [token](https://docs.npmjs.com/getting-started/working_with_tokens) allowed to publish to the registry \`${String(registry)}\`.
|
|
222
|
+
Please make sure to set the \`NPM_TOKEN\` environment variable in your CI with the exact value of the npm token.`,
|
|
223
|
+
message: "Invalid npm authentication."
|
|
224
|
+
};
|
|
225
|
+
},
|
|
214
226
|
EINVALIDNPMPUBLISH: ({ npmPublish }) => {
|
|
215
227
|
return {
|
|
216
228
|
details: `The [npmPublish option](${linkify("README.md#npmpublish")}) option, if defined, must be a \`Boolean\`.
|
|
@@ -223,8 +235,7 @@ Your configuration for the \`npmPublish\` option is \`${String(npmPublish)}\`.`,
|
|
|
223
235
|
details: `The [npm token](${linkify(
|
|
224
236
|
"README.md#npm-registry-authentication"
|
|
225
237
|
)}) configured in the \`NPM_TOKEN\` environment variable must be a valid [token](https://docs.npmjs.com/getting-started/working_with_tokens) allowing to publish to the registry \`${String(registry)}\`.
|
|
226
|
-
|
|
227
|
-
Please make sure to set the \`NPM_TOKEN\` environment variable in your CI with the exact value of the npm token.`,
|
|
238
|
+
Please verify your authentication configuration.`,
|
|
228
239
|
message: "Invalid npm token."
|
|
229
240
|
};
|
|
230
241
|
},
|
|
@@ -261,10 +272,10 @@ Your configuration for the \`tarballDir\` option is \`${String(tarballDir)}\`.`,
|
|
|
261
272
|
},
|
|
262
273
|
ENONPMTOKEN: ({ registry }) => {
|
|
263
274
|
return {
|
|
264
|
-
details: `
|
|
275
|
+
details: `When not publishing through [trusted publishing](https://docs.npmjs.com/trusted-publishers), an [npm token](${linkify(
|
|
265
276
|
"README.md#npm-registry-authentication"
|
|
266
277
|
)}) must be created and set in the \`NPM_TOKEN\` environment variable on your CI environment.
|
|
267
|
-
Please make sure to create an [npm token](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) and
|
|
278
|
+
Please make sure to create an [npm token](https://docs.npmjs.com/getting-started/working_with_tokens#how-to-create-new-tokens) and set it in the \`NPM_TOKEN\` environment variable on your CI environment. The token must allow publishing to the registry \`${registry}\`.`,
|
|
268
279
|
message: "No npm token specified."
|
|
269
280
|
};
|
|
270
281
|
},
|
|
@@ -318,6 +329,66 @@ const getPackage = async ({ pkgRoot }, { cwd }) => {
|
|
|
318
329
|
}
|
|
319
330
|
};
|
|
320
331
|
|
|
332
|
+
const exchangeIdToken = async (idToken, packageName, logger) => {
|
|
333
|
+
const response = await fetch(`${OFFICIAL_REGISTRY}-/npm/v1/oidc/token/exchange/package/${encodeURIComponent(packageName)}`, {
|
|
334
|
+
headers: { Authorization: `Bearer ${idToken}` },
|
|
335
|
+
method: "POST"
|
|
336
|
+
});
|
|
337
|
+
const responseBody = await response.json();
|
|
338
|
+
if (response.ok) {
|
|
339
|
+
logger.log("OIDC token exchange with the npm registry succeeded");
|
|
340
|
+
return responseBody.token;
|
|
341
|
+
}
|
|
342
|
+
logger.log(`OIDC token exchange with the npm registry failed: ${response.status} ${responseBody.message}`);
|
|
343
|
+
return void 0;
|
|
344
|
+
};
|
|
345
|
+
const exchangeGithubActionsToken = async (packageName, logger) => {
|
|
346
|
+
let idToken;
|
|
347
|
+
logger.log("Verifying OIDC context for publishing from GitHub Actions");
|
|
348
|
+
try {
|
|
349
|
+
const { getIDToken } = await import('@actions/core');
|
|
350
|
+
idToken = await getIDToken("npm:registry.npmjs.org");
|
|
351
|
+
} catch (error) {
|
|
352
|
+
logger.log(`Retrieval of GitHub Actions OIDC token failed: ${error.message}`);
|
|
353
|
+
logger.log("Have you granted the `id-token: write` permission to this workflow?");
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
if (!idToken) {
|
|
357
|
+
return void 0;
|
|
358
|
+
}
|
|
359
|
+
return exchangeIdToken(idToken, packageName, logger);
|
|
360
|
+
};
|
|
361
|
+
const exchangeGitlabPipelinesToken = async (packageName, logger) => {
|
|
362
|
+
const idToken = process.env.NPM_ID_TOKEN;
|
|
363
|
+
logger.log("Verifying OIDC context for publishing from GitLab Pipelines");
|
|
364
|
+
if (!idToken) {
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
return exchangeIdToken(idToken, packageName, logger);
|
|
368
|
+
};
|
|
369
|
+
const tokenExchange = (pkg, { logger }) => {
|
|
370
|
+
const { name: ciProviderName } = envCi();
|
|
371
|
+
if (GITHUB_ACTIONS_PROVIDER_NAME === ciProviderName) {
|
|
372
|
+
return exchangeGithubActionsToken(pkg.name, logger);
|
|
373
|
+
}
|
|
374
|
+
if (GITLAB_PIPELINES_PROVIDER_NAME === ciProviderName) {
|
|
375
|
+
return exchangeGitlabPipelinesToken(pkg.name, logger);
|
|
376
|
+
}
|
|
377
|
+
return Promise.resolve(void 0);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const oidcContext = async (registry, pkg, context) => {
|
|
381
|
+
if (OFFICIAL_REGISTRY !== registry) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
try {
|
|
385
|
+
const token = await tokenExchange({ name: pkg.name ?? "" }, context);
|
|
386
|
+
return !!token;
|
|
387
|
+
} catch {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
321
392
|
const nerfDart = (url) => {
|
|
322
393
|
const parsed = new URL(url);
|
|
323
394
|
const from = `${parsed.protocol}//${parsed.host}${parsed.pathname}`;
|
|
@@ -330,7 +401,7 @@ const setNpmrcAuth = async (npmrc, registry, { cwd, env: { NPM_CONFIG_USERCONFIG
|
|
|
330
401
|
const { config, files } = rc("npm", {
|
|
331
402
|
config: NPM_CONFIG_USERCONFIG ?? resolve(cwd, ".npmrc"),
|
|
332
403
|
cwd,
|
|
333
|
-
defaults: { registry:
|
|
404
|
+
defaults: { registry: OFFICIAL_REGISTRY }
|
|
334
405
|
});
|
|
335
406
|
if (Array.isArray(files)) {
|
|
336
407
|
logger.log("Reading npm config from %s", files.join(", "));
|
|
@@ -354,33 +425,43 @@ email = \${NPM_EMAIL}`);
|
|
|
354
425
|
}
|
|
355
426
|
};
|
|
356
427
|
|
|
357
|
-
const
|
|
428
|
+
const verifyAuthContextAgainstRegistry = async (npmrc, registry, context) => {
|
|
358
429
|
const {
|
|
359
430
|
cwd,
|
|
360
|
-
env: {
|
|
431
|
+
env: { ...environment },
|
|
361
432
|
logger,
|
|
362
433
|
stderr,
|
|
363
434
|
stdout
|
|
364
435
|
} = context;
|
|
436
|
+
try {
|
|
437
|
+
logger.log(`Running "pnpm whoami" to verify authentication on registry "${registry}"`);
|
|
438
|
+
const whoamiResult = await execa("pnpm", ["whoami", "--userconfig", npmrc, "--registry", registry], {
|
|
439
|
+
cwd,
|
|
440
|
+
env: environment,
|
|
441
|
+
preferLocal: true
|
|
442
|
+
});
|
|
443
|
+
if (whoamiResult.stdout) {
|
|
444
|
+
stdout.write(whoamiResult.stdout);
|
|
445
|
+
}
|
|
446
|
+
if (whoamiResult.stderr) {
|
|
447
|
+
stderr.write(whoamiResult.stderr);
|
|
448
|
+
}
|
|
449
|
+
} catch {
|
|
450
|
+
const semanticError = getError("EINVALIDNPMTOKEN", { registry });
|
|
451
|
+
throw new AggregateError([semanticError], semanticError.message);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
const verifyAuth = async (npmrc, package_, context, pkgRoot) => {
|
|
365
455
|
const registry = getRegistry(package_, context);
|
|
456
|
+
if (package_.name && await oidcContext(registry, package_, context)) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
366
459
|
await setNpmrcAuth(npmrc, registry, context);
|
|
460
|
+
const {
|
|
461
|
+
env: { DEFAULT_NPM_REGISTRY = OFFICIAL_REGISTRY }
|
|
462
|
+
} = context;
|
|
367
463
|
if (normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY)) {
|
|
368
|
-
|
|
369
|
-
logger.log(`Running "pnpm whoami" to verify authentication on registry "${registry}"`);
|
|
370
|
-
const whoamiResult = execa("pnpm", ["whoami", "--userconfig", npmrc, "--registry", registry], {
|
|
371
|
-
cwd,
|
|
372
|
-
env: environment,
|
|
373
|
-
preferLocal: true
|
|
374
|
-
});
|
|
375
|
-
whoamiResult.stdout.pipe(stdout, { end: false });
|
|
376
|
-
whoamiResult.stderr.pipe(stderr, { end: false });
|
|
377
|
-
await whoamiResult;
|
|
378
|
-
} catch {
|
|
379
|
-
const semanticError = getError("EINVALIDNPMTOKEN", { registry });
|
|
380
|
-
throw new AggregateError([semanticError], semanticError.message);
|
|
381
|
-
}
|
|
382
|
-
} else {
|
|
383
|
-
logger.log(`Skipping authentication verification for non-default registry "${registry}"`);
|
|
464
|
+
await verifyAuthContextAgainstRegistry(npmrc, registry, context);
|
|
384
465
|
}
|
|
385
466
|
};
|
|
386
467
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anolilab/semantic-release-pnpm",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.2",
|
|
4
4
|
"description": "Semantic-release plugin to publish a npm package with pnpm.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -46,11 +46,13 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@
|
|
49
|
+
"@actions/core": "^1.11.1",
|
|
50
|
+
"@anolilab/rc": "3.0.0-alpha.2",
|
|
50
51
|
"@semantic-release/error": "^4.0.0",
|
|
51
|
-
"@visulima/fs": "^
|
|
52
|
-
"@visulima/package": "^4.
|
|
53
|
-
"@visulima/path": "^
|
|
52
|
+
"@visulima/fs": "^4.0.2",
|
|
53
|
+
"@visulima/package": "^4.1.2",
|
|
54
|
+
"@visulima/path": "^2.0.1",
|
|
55
|
+
"env-ci": "^11.2.0",
|
|
54
56
|
"execa": "^9.6.0",
|
|
55
57
|
"ini": "^5.0.0",
|
|
56
58
|
"normalize-url": "^8.1.0",
|