gh-setup-git-identity 0.8.0 → 0.8.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/.github/workflows/release.yml +31 -0
- package/CHANGELOG.md +12 -0
- package/README.md +22 -8
- package/docs/case-studies/issue-32/README.md +162 -0
- package/docs/case-studies/issue-32/raw-logs/bun-add-command-stream-2.0.0-no-toolchain.txt +47 -0
- package/docs/case-studies/issue-32/raw-logs/bun-add-command-stream-2.4.0-no-toolchain.txt +10 -0
- package/docs/case-studies/issue-32/raw-logs/ci-run-37733836425-release-failed.txt +252 -0
- package/docs/case-studies/issue-32/raw-logs/command-stream-exit-codes.txt +4 -0
- package/docs/case-studies/issue-32/raw-logs/dry-run-fixed-publish-fails.txt +91 -0
- package/docs/case-studies/issue-32/raw-logs/dry-run-main-publish-fails.txt +81 -0
- package/docs/case-studies/issue-32/raw-logs/dry-run-rerun-after-fix.txt +195 -0
- package/docs/case-studies/issue-32/raw-logs/dry-run-rerun-before-fix.txt +198 -0
- package/docs/case-studies/issue-32/raw-logs/npm-registry-facts.txt +28 -0
- package/docs/case-studies/issue-32/raw-logs/setup-npm-fixed-node20.txt +8 -0
- package/docs/case-studies/issue-32/raw-logs/setup-npm-main-node20.txt +12 -0
- package/docs/case-studies/issue-34/README.md +53 -0
- package/docs/case-studies/issue-34/raw-logs/email-endpoint-headers.txt +5 -0
- package/docs/case-studies/issue-34/raw-logs/gh-2.102.0-scope-hint.txt +13 -0
- package/docs/case-studies/issue-34/raw-logs/gh-2.105.0-scope-hint.txt +13 -0
- package/docs/case-studies/issue-34/raw-logs/issue-report.txt +46 -0
- package/docs/case-studies/issue-34/raw-logs/prepared-pr-changeset-check.txt +3 -0
- package/docs/case-studies/issue-34/raw-logs/regression-after.txt +19 -0
- package/docs/case-studies/issue-34/raw-logs/regression-before.txt +22 -0
- package/experiments/issue-32-command-stream-exit-codes.mjs +27 -0
- package/experiments/issue-32-pinned-helpers.mjs +27 -0
- package/experiments/issue-32-release-dry-run.sh +66 -0
- package/experiments/issue-34-gh-scope-hint.mjs +68 -0
- package/package.json +1 -1
- package/scripts/changeset-version.mjs +8 -4
- package/scripts/create-github-release.mjs +8 -5
- package/scripts/create-manual-changeset.mjs +4 -5
- package/scripts/format-github-release.mjs +5 -5
- package/scripts/format-release-notes.mjs +5 -5
- package/scripts/instant-version-bump.mjs +8 -5
- package/scripts/publish-to-npm.mjs +18 -12
- package/scripts/release-deps.mjs +21 -0
- package/scripts/report-release-failure.mjs +143 -0
- package/scripts/setup-npm.mjs +80 -27
- package/scripts/version-and-commit.mjs +22 -5
- package/src/cli.js +43 -61
- package/src/index.js +88 -13
- package/test/cli.test.js +257 -0
- package/test/index.test.js +0 -17
- package/test/release-scripts.test.js +232 -0
|
@@ -13,13 +13,17 @@
|
|
|
13
13
|
* - command-stream: Modern shell command execution with streaming support
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import { USE_M_URL, COMMAND_STREAM } from './release-deps.mjs';
|
|
17
|
+
|
|
16
18
|
// Load use-m dynamically
|
|
17
|
-
const { use } = eval(
|
|
18
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
19
|
-
);
|
|
19
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
20
20
|
|
|
21
21
|
// Import command-stream for shell command execution
|
|
22
|
-
const {
|
|
22
|
+
const { $, shell } = await use(COMMAND_STREAM);
|
|
23
|
+
|
|
24
|
+
// Reject on a non-zero exit code. By default `await $` resolves, so a failed
|
|
25
|
+
// command would be reported as a success (issue #32).
|
|
26
|
+
shell.errexit(true);
|
|
23
27
|
|
|
24
28
|
try {
|
|
25
29
|
console.log('Running changeset version...');
|
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { readFileSync } from 'fs';
|
|
16
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
16
17
|
|
|
17
18
|
// Load use-m dynamically
|
|
18
|
-
const { use } = eval(
|
|
19
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
20
|
-
);
|
|
19
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
21
20
|
|
|
22
21
|
// Import link-foundation libraries
|
|
23
|
-
const {
|
|
24
|
-
const { makeConfig } = await use(
|
|
22
|
+
const { $, shell } = await use(COMMAND_STREAM);
|
|
23
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
24
|
+
|
|
25
|
+
// Reject on a non-zero exit code. By default `await $` resolves, so a failed
|
|
26
|
+
// command would be reported as a success (issue #32).
|
|
27
|
+
shell.errexit(true);
|
|
25
28
|
|
|
26
29
|
// Parse CLI arguments using lino-arguments
|
|
27
30
|
// Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
|
|
@@ -12,15 +12,14 @@
|
|
|
12
12
|
|
|
13
13
|
import { writeFileSync } from 'fs';
|
|
14
14
|
import { randomBytes } from 'crypto';
|
|
15
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
15
16
|
|
|
16
17
|
// Load use-m dynamically
|
|
17
|
-
const { use } = eval(
|
|
18
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
19
|
-
);
|
|
18
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
20
19
|
|
|
21
20
|
// Import link-foundation libraries
|
|
22
|
-
const { $ } = await use(
|
|
23
|
-
const { makeConfig } = await use(
|
|
21
|
+
const { $ } = await use(COMMAND_STREAM);
|
|
22
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
24
23
|
|
|
25
24
|
// Parse CLI arguments using lino-arguments
|
|
26
25
|
const config = makeConfig({
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
* - lino-arguments: Unified configuration from CLI args, env vars, and .lenv files
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
17
|
+
|
|
16
18
|
// Load use-m dynamically
|
|
17
|
-
const { use } = eval(
|
|
18
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
19
|
-
);
|
|
19
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
20
20
|
|
|
21
21
|
// Import link-foundation libraries
|
|
22
|
-
const { $ } = await use(
|
|
23
|
-
const { makeConfig } = await use(
|
|
22
|
+
const { $ } = await use(COMMAND_STREAM);
|
|
23
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
24
24
|
|
|
25
25
|
// Parse CLI arguments using lino-arguments
|
|
26
26
|
// Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
* Note: Uses --release-version instead of --version to avoid conflict with yargs' built-in --version flag.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
25
|
+
|
|
24
26
|
// Load use-m dynamically
|
|
25
|
-
const { use } = eval(
|
|
26
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
27
|
-
);
|
|
27
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
28
28
|
|
|
29
29
|
// Import link-foundation libraries
|
|
30
|
-
const { $ } = await use(
|
|
31
|
-
const { makeConfig } = await use(
|
|
30
|
+
const { $ } = await use(COMMAND_STREAM);
|
|
31
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
32
32
|
|
|
33
33
|
// Parse CLI arguments using lino-arguments
|
|
34
34
|
// Note: Using --release-version instead of --version to avoid conflict with yargs' built-in --version flag
|
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { readFileSync, writeFileSync } from 'fs';
|
|
16
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
16
17
|
|
|
17
18
|
// Load use-m dynamically
|
|
18
|
-
const { use } = eval(
|
|
19
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
20
|
-
);
|
|
19
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
21
20
|
|
|
22
21
|
// Import link-foundation libraries
|
|
23
|
-
const {
|
|
24
|
-
const { makeConfig } = await use(
|
|
22
|
+
const { $, shell } = await use(COMMAND_STREAM);
|
|
23
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
24
|
+
|
|
25
|
+
// Reject on a non-zero exit code. By default `await $` resolves, so a failed
|
|
26
|
+
// command would be reported as a success (issue #32).
|
|
27
|
+
shell.errexit(true);
|
|
25
28
|
|
|
26
29
|
// Parse CLI arguments using lino-arguments
|
|
27
30
|
const config = makeConfig({
|
|
@@ -12,15 +12,18 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { readFileSync, appendFileSync } from 'fs';
|
|
15
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
15
16
|
|
|
16
17
|
// Load use-m dynamically
|
|
17
|
-
const { use } = eval(
|
|
18
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
19
|
-
);
|
|
18
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
20
19
|
|
|
21
20
|
// Import link-foundation libraries
|
|
22
|
-
const {
|
|
23
|
-
const { makeConfig } = await use(
|
|
21
|
+
const { $, shell } = await use(COMMAND_STREAM);
|
|
22
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
23
|
+
|
|
24
|
+
// Reject on a non-zero exit code. By default `await $` resolves, so a failed
|
|
25
|
+
// command would be reported as a success (issue #32).
|
|
26
|
+
shell.errexit(true);
|
|
24
27
|
|
|
25
28
|
// Parse CLI arguments using lino-arguments
|
|
26
29
|
const config = makeConfig({
|
|
@@ -72,14 +75,17 @@ async function main() {
|
|
|
72
75
|
console.log(
|
|
73
76
|
`Checking if version ${currentVersion} is already published...`
|
|
74
77
|
);
|
|
75
|
-
const checkResult =
|
|
76
|
-
await $`npm view "gh-setup-git-identity@${currentVersion}" version`.run({
|
|
77
|
-
capture: true,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// command-stream returns { code: 0 } on success, { code: 1 } on failure (e.g., E404)
|
|
81
78
|
// Exit code 0 means version exists, non-zero means version not found
|
|
82
|
-
|
|
79
|
+
// (e.g., E404). With errexit on, a non-zero exit code rejects.
|
|
80
|
+
const isPublished =
|
|
81
|
+
await $`npm view "gh-setup-git-identity@${currentVersion}" version`
|
|
82
|
+
.run({ capture: true })
|
|
83
|
+
.then(
|
|
84
|
+
() => true,
|
|
85
|
+
() => false
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (isPublished) {
|
|
83
89
|
console.log(`Version ${currentVersion} is already published to npm`);
|
|
84
90
|
setOutput('published', 'true');
|
|
85
91
|
setOutput('published_version', currentVersion);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pinned versions of the helpers that the release scripts load through use-m.
|
|
3
|
+
*
|
|
4
|
+
* The release scripts used to load `use-m`, `command-stream` and
|
|
5
|
+
* `lino-arguments` at `latest`. On 2026-10-08, command-stream 2.0.0 made
|
|
6
|
+
* `node-pty` a hard dependency. Its native build failed on the runner, so the
|
|
7
|
+
* release on main stopped before it published anything (issue #32). Pinning
|
|
8
|
+
* the versions here means that a new upstream release cannot break publishing.
|
|
9
|
+
* A version bump becomes a reviewed change that goes through PR CI.
|
|
10
|
+
*
|
|
11
|
+
* Bump these versions deliberately, in a pull request.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** use-m loader, fetched from the CDN by every release script. */
|
|
15
|
+
export const USE_M_URL = 'https://unpkg.com/use-m@8.16.4/use.js';
|
|
16
|
+
|
|
17
|
+
/** command-stream 2.0.1+ declares node-pty as optional (command-stream#218). */
|
|
18
|
+
export const COMMAND_STREAM = 'command-stream@2.4.0';
|
|
19
|
+
|
|
20
|
+
/** The lino-arguments line used by the last successful release (0.8.0). */
|
|
21
|
+
export const LINO_ARGUMENTS = 'lino-arguments@0.2.5';
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Report a failed release on main by opening a GitHub issue, or by commenting
|
|
5
|
+
* on the open one, so that a merged fix does not sit unpublished unnoticed.
|
|
6
|
+
*
|
|
7
|
+
* In issue #32 the release for a merged fix failed on 2026-10-08. Nobody
|
|
8
|
+
* noticed, and npm `latest` stayed on the broken version for two weeks.
|
|
9
|
+
*
|
|
10
|
+
* This script deliberately loads no helpers (no use-m, no command-stream):
|
|
11
|
+
* it must keep working when loading those helpers is what broke the release.
|
|
12
|
+
*
|
|
13
|
+
* Environment:
|
|
14
|
+
* GH_TOKEN token with `issues: write`
|
|
15
|
+
* GITHUB_REPOSITORY owner/repo
|
|
16
|
+
* GITHUB_SERVER_URL, GITHUB_RUN_ID, GITHUB_SHA, GITHUB_EVENT_NAME
|
|
17
|
+
* JOB_RESULTS JSON object of job name -> result, e.g. {"release":"failure"}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { execFileSync } from 'node:child_process';
|
|
21
|
+
import { appendFileSync } from 'node:fs';
|
|
22
|
+
import { resolve } from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
|
|
25
|
+
export const ISSUE_TITLE = 'Release on main failed';
|
|
26
|
+
|
|
27
|
+
export function failedJobs(jobResults) {
|
|
28
|
+
return Object.entries(jobResults)
|
|
29
|
+
.filter(([, result]) => result === 'failure' || result === 'cancelled')
|
|
30
|
+
.map(([job]) => job);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function buildReport({
|
|
34
|
+
repository,
|
|
35
|
+
serverUrl = 'https://github.com',
|
|
36
|
+
runId,
|
|
37
|
+
sha,
|
|
38
|
+
eventName,
|
|
39
|
+
jobResults,
|
|
40
|
+
}) {
|
|
41
|
+
const runUrl = `${serverUrl}/${repository}/actions/runs/${runId}`;
|
|
42
|
+
const failed = failedJobs(jobResults);
|
|
43
|
+
const rows = Object.entries(jobResults)
|
|
44
|
+
.map(([job, result]) => `| \`${job}\` | ${result} |`)
|
|
45
|
+
.join('\n');
|
|
46
|
+
|
|
47
|
+
return [
|
|
48
|
+
`The release workflow on \`main\` did not finish: ${runUrl}`,
|
|
49
|
+
'',
|
|
50
|
+
`- Commit: ${sha}`,
|
|
51
|
+
`- Event: \`${eventName}\``,
|
|
52
|
+
`- Failed jobs: ${failed.map((job) => `\`${job}\``).join(', ') || 'none'}`,
|
|
53
|
+
'',
|
|
54
|
+
'| Job | Result |',
|
|
55
|
+
'| --- | --- |',
|
|
56
|
+
rows,
|
|
57
|
+
'',
|
|
58
|
+
'Changes merged since the last release may not be published to npm.',
|
|
59
|
+
'Fix the cause, then re-run the failed jobs:',
|
|
60
|
+
'',
|
|
61
|
+
'```sh',
|
|
62
|
+
`gh run rerun ${runId} --failed --repo ${repository}`,
|
|
63
|
+
'```',
|
|
64
|
+
'',
|
|
65
|
+
'Close this issue once the release is published.',
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function gh(args) {
|
|
70
|
+
return execFileSync('gh', args, { encoding: 'utf8' }).trim();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function reportReleaseFailure({ env = process.env, run = gh } = {}) {
|
|
74
|
+
const repository = env.GITHUB_REPOSITORY;
|
|
75
|
+
const body = buildReport({
|
|
76
|
+
repository,
|
|
77
|
+
serverUrl: env.GITHUB_SERVER_URL,
|
|
78
|
+
runId: env.GITHUB_RUN_ID,
|
|
79
|
+
sha: env.GITHUB_SHA,
|
|
80
|
+
eventName: env.GITHUB_EVENT_NAME,
|
|
81
|
+
jobResults: JSON.parse(env.JOB_RESULTS || '{}'),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const existing = run([
|
|
85
|
+
'issue',
|
|
86
|
+
'list',
|
|
87
|
+
'--repo',
|
|
88
|
+
repository,
|
|
89
|
+
'--state',
|
|
90
|
+
'open',
|
|
91
|
+
'--search',
|
|
92
|
+
`"${ISSUE_TITLE}" in:title`,
|
|
93
|
+
'--json',
|
|
94
|
+
'number,title',
|
|
95
|
+
'--jq',
|
|
96
|
+
`map(select(.title == "${ISSUE_TITLE}")) | .[0].number // empty`,
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
const url = existing
|
|
100
|
+
? run([
|
|
101
|
+
'issue',
|
|
102
|
+
'comment',
|
|
103
|
+
existing,
|
|
104
|
+
'--repo',
|
|
105
|
+
repository,
|
|
106
|
+
'--body',
|
|
107
|
+
body,
|
|
108
|
+
])
|
|
109
|
+
: run([
|
|
110
|
+
'issue',
|
|
111
|
+
'create',
|
|
112
|
+
'--repo',
|
|
113
|
+
repository,
|
|
114
|
+
'--title',
|
|
115
|
+
ISSUE_TITLE,
|
|
116
|
+
'--body',
|
|
117
|
+
body,
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
return { url, body, existing: Boolean(existing) };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isMainModule() {
|
|
124
|
+
return process.argv[1]
|
|
125
|
+
? resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
126
|
+
: false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (isMainModule()) {
|
|
130
|
+
try {
|
|
131
|
+
const { url, body } = reportReleaseFailure();
|
|
132
|
+
console.log(`::error::Release on main failed, reported at ${url}`);
|
|
133
|
+
if (process.env.GITHUB_STEP_SUMMARY) {
|
|
134
|
+
appendFileSync(
|
|
135
|
+
process.env.GITHUB_STEP_SUMMARY,
|
|
136
|
+
`## Release failed\n\n${body}\n\nReported at ${url}\n`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error('Error reporting release failure:', error.message);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
}
|
package/scripts/setup-npm.mjs
CHANGED
|
@@ -5,33 +5,86 @@
|
|
|
5
5
|
* npm trusted publishing requires npm >= 11.5.1
|
|
6
6
|
* Node.js 20.x ships with npm 10.x, so we need to update
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* This script deliberately loads no helpers (no use-m, no command-stream).
|
|
9
|
+
* Before, it installed command-stream@latest only to run `npm install`. When
|
|
10
|
+
* command-stream 2.0.0 made node-pty a hard dependency, that install failed
|
|
11
|
+
* and the release on main stopped before publishing (issue #32).
|
|
12
|
+
*
|
|
13
|
+
* npm is pinned to major 11, not `latest`. npm 12 requires Node.js
|
|
14
|
+
* ^22.22.2 || ^24.15.0 || >=26, so `npm install -g npm@latest` fails with
|
|
15
|
+
* EBADENGINE on the Node.js 20.x that the release jobs use.
|
|
11
16
|
*/
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
import { execFileSync } from 'node:child_process';
|
|
19
|
+
import { resolve } from 'node:path';
|
|
20
|
+
import { fileURLToPath } from 'node:url';
|
|
21
|
+
|
|
22
|
+
export const NPM_MIN_VERSION = '11.5.1';
|
|
23
|
+
export const NPM_INSTALL_SPEC = 'npm@11';
|
|
24
|
+
|
|
25
|
+
export function parseVersion(version) {
|
|
26
|
+
const match = String(version)
|
|
27
|
+
.trim()
|
|
28
|
+
.match(/^v?(\d+)\.(\d+)\.(\d+)/);
|
|
29
|
+
if (!match) {
|
|
30
|
+
throw new Error(`Invalid semantic version: ${version}`);
|
|
31
|
+
}
|
|
32
|
+
return match.slice(1, 4).map(Number);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function isVersionAtLeast(version, minimumVersion) {
|
|
36
|
+
const left = parseVersion(version);
|
|
37
|
+
const right = parseVersion(minimumVersion);
|
|
38
|
+
for (let i = 0; i < 3; i++) {
|
|
39
|
+
if (left[i] !== right[i]) {
|
|
40
|
+
return left[i] > right[i];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function isSupportedNpmVersion(version) {
|
|
47
|
+
return isVersionAtLeast(version, NPM_MIN_VERSION);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function npm(args, options = {}) {
|
|
51
|
+
return execFileSync('npm', args, { encoding: 'utf8', ...options });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function setupNpm({ run = npm, log = console.log } = {}) {
|
|
55
|
+
const currentVersion = run(['--version']).trim();
|
|
56
|
+
log(`Current npm version: ${currentVersion}`);
|
|
57
|
+
|
|
58
|
+
if (isSupportedNpmVersion(currentVersion)) {
|
|
59
|
+
log('npm already supports OIDC trusted publishing, skipping update');
|
|
60
|
+
return currentVersion;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log(`Installing ${NPM_INSTALL_SPEC}...`);
|
|
64
|
+
run(['install', '-g', NPM_INSTALL_SPEC], { stdio: 'inherit' });
|
|
65
|
+
|
|
66
|
+
const updatedVersion = run(['--version']).trim();
|
|
67
|
+
log(`Updated npm version: ${updatedVersion}`);
|
|
68
|
+
|
|
69
|
+
if (!isSupportedNpmVersion(updatedVersion)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`npm ${updatedVersion} does not support OIDC trusted publishing (need >= ${NPM_MIN_VERSION})`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return updatedVersion;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isMainModule() {
|
|
78
|
+
return process.argv[1]
|
|
79
|
+
? resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
80
|
+
: false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (isMainModule()) {
|
|
84
|
+
try {
|
|
85
|
+
setupNpm();
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.error('Error updating npm:', error.message);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
37
90
|
}
|
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { readFileSync, appendFileSync, readdirSync } from 'fs';
|
|
16
|
+
import { USE_M_URL, COMMAND_STREAM, LINO_ARGUMENTS } from './release-deps.mjs';
|
|
16
17
|
|
|
17
18
|
// Load use-m dynamically
|
|
18
|
-
const { use } = eval(
|
|
19
|
-
await (await fetch('https://unpkg.com/use-m/use.js')).text()
|
|
20
|
-
);
|
|
19
|
+
const { use } = eval(await (await fetch(USE_M_URL)).text());
|
|
21
20
|
|
|
22
21
|
// Import link-foundation libraries
|
|
23
|
-
const {
|
|
24
|
-
const { makeConfig } = await use(
|
|
22
|
+
const { $, shell } = await use(COMMAND_STREAM);
|
|
23
|
+
const { makeConfig } = await use(LINO_ARGUMENTS);
|
|
24
|
+
|
|
25
|
+
// Reject on a non-zero exit code. By default `await $` resolves, so a failed
|
|
26
|
+
// command would be reported as a success (issue #32).
|
|
27
|
+
shell.errexit(true);
|
|
25
28
|
|
|
26
29
|
// Parse CLI arguments using lino-arguments
|
|
27
30
|
const config = makeConfig({
|
|
@@ -177,6 +180,20 @@ async function main() {
|
|
|
177
180
|
} else {
|
|
178
181
|
console.log('Rebasing on remote main to incorporate changes...');
|
|
179
182
|
await $`git rebase origin/main`;
|
|
183
|
+
|
|
184
|
+
// A re-run after a failed publish: the version commit on remote main
|
|
185
|
+
// already consumed the changesets. Report the version as released, so
|
|
186
|
+
// the publish step runs and publishes it if it is missing from npm.
|
|
187
|
+
if (mode === 'changeset' && countChangesets() === 0) {
|
|
188
|
+
const version = await getVersion();
|
|
189
|
+
console.log(
|
|
190
|
+
`Remote main already consumed the changesets (version ${version}).`
|
|
191
|
+
);
|
|
192
|
+
setOutput('version_committed', 'false');
|
|
193
|
+
setOutput('already_released', 'true');
|
|
194
|
+
setOutput('new_version', version);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
180
197
|
}
|
|
181
198
|
}
|
|
182
199
|
|