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.
Files changed (44) hide show
  1. package/.github/workflows/release.yml +31 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +22 -8
  4. package/docs/case-studies/issue-32/README.md +162 -0
  5. package/docs/case-studies/issue-32/raw-logs/bun-add-command-stream-2.0.0-no-toolchain.txt +47 -0
  6. package/docs/case-studies/issue-32/raw-logs/bun-add-command-stream-2.4.0-no-toolchain.txt +10 -0
  7. package/docs/case-studies/issue-32/raw-logs/ci-run-37733836425-release-failed.txt +252 -0
  8. package/docs/case-studies/issue-32/raw-logs/command-stream-exit-codes.txt +4 -0
  9. package/docs/case-studies/issue-32/raw-logs/dry-run-fixed-publish-fails.txt +91 -0
  10. package/docs/case-studies/issue-32/raw-logs/dry-run-main-publish-fails.txt +81 -0
  11. package/docs/case-studies/issue-32/raw-logs/dry-run-rerun-after-fix.txt +195 -0
  12. package/docs/case-studies/issue-32/raw-logs/dry-run-rerun-before-fix.txt +198 -0
  13. package/docs/case-studies/issue-32/raw-logs/npm-registry-facts.txt +28 -0
  14. package/docs/case-studies/issue-32/raw-logs/setup-npm-fixed-node20.txt +8 -0
  15. package/docs/case-studies/issue-32/raw-logs/setup-npm-main-node20.txt +12 -0
  16. package/docs/case-studies/issue-34/README.md +53 -0
  17. package/docs/case-studies/issue-34/raw-logs/email-endpoint-headers.txt +5 -0
  18. package/docs/case-studies/issue-34/raw-logs/gh-2.102.0-scope-hint.txt +13 -0
  19. package/docs/case-studies/issue-34/raw-logs/gh-2.105.0-scope-hint.txt +13 -0
  20. package/docs/case-studies/issue-34/raw-logs/issue-report.txt +46 -0
  21. package/docs/case-studies/issue-34/raw-logs/prepared-pr-changeset-check.txt +3 -0
  22. package/docs/case-studies/issue-34/raw-logs/regression-after.txt +19 -0
  23. package/docs/case-studies/issue-34/raw-logs/regression-before.txt +22 -0
  24. package/experiments/issue-32-command-stream-exit-codes.mjs +27 -0
  25. package/experiments/issue-32-pinned-helpers.mjs +27 -0
  26. package/experiments/issue-32-release-dry-run.sh +66 -0
  27. package/experiments/issue-34-gh-scope-hint.mjs +68 -0
  28. package/package.json +1 -1
  29. package/scripts/changeset-version.mjs +8 -4
  30. package/scripts/create-github-release.mjs +8 -5
  31. package/scripts/create-manual-changeset.mjs +4 -5
  32. package/scripts/format-github-release.mjs +5 -5
  33. package/scripts/format-release-notes.mjs +5 -5
  34. package/scripts/instant-version-bump.mjs +8 -5
  35. package/scripts/publish-to-npm.mjs +18 -12
  36. package/scripts/release-deps.mjs +21 -0
  37. package/scripts/report-release-failure.mjs +143 -0
  38. package/scripts/setup-npm.mjs +80 -27
  39. package/scripts/version-and-commit.mjs +22 -5
  40. package/src/cli.js +43 -61
  41. package/src/index.js +88 -13
  42. package/test/cli.test.js +257 -0
  43. package/test/index.test.js +0 -17
  44. package/test/release-scripts.test.js +232 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Regression tests for the release scripts (issue #32)
3
+ *
4
+ * The release on main failed because scripts/setup-npm.mjs installed
5
+ * command-stream@latest through use-m. command-stream 2.0.0 made node-pty a
6
+ * hard dependency, and its native build failed on the runner. These tests
7
+ * work offline: they check the pins and the npm setup logic, and do not load
8
+ * any helper.
9
+ */
10
+
11
+ import { test, assert } from 'test-anywhere';
12
+ import { readFileSync, readdirSync } from 'node:fs';
13
+ import { fileURLToPath } from 'node:url';
14
+
15
+ import {
16
+ USE_M_URL,
17
+ COMMAND_STREAM,
18
+ LINO_ARGUMENTS,
19
+ } from '../scripts/release-deps.mjs';
20
+ import {
21
+ NPM_INSTALL_SPEC,
22
+ NPM_MIN_VERSION,
23
+ isSupportedNpmVersion,
24
+ setupNpm,
25
+ } from '../scripts/setup-npm.mjs';
26
+ import {
27
+ ISSUE_TITLE,
28
+ buildReport,
29
+ failedJobs,
30
+ reportReleaseFailure,
31
+ } from '../scripts/report-release-failure.mjs';
32
+
33
+ const scriptsDir = fileURLToPath(new URL('../scripts/', import.meta.url));
34
+ const workflowPath = fileURLToPath(
35
+ new URL('../.github/workflows/release.yml', import.meta.url)
36
+ );
37
+ const scripts = readdirSync(scriptsDir)
38
+ .filter((file) => file.endsWith('.mjs'))
39
+ .map((file) => ({
40
+ file,
41
+ source: readFileSync(`${scriptsDir}${file}`, 'utf8'),
42
+ }));
43
+ const exactVersion = /@\d+\.\d+\.\d+$/;
44
+
45
+ test('release helpers are pinned to exact versions', () => {
46
+ assert.match(USE_M_URL, /^https:\/\/unpkg\.com\/use-m@\d+\.\d+\.\d+\/use\.js$/);
47
+ assert.match(COMMAND_STREAM, /^command-stream@/);
48
+ assert.match(COMMAND_STREAM, exactVersion);
49
+ assert.match(LINO_ARGUMENTS, /^lino-arguments@/);
50
+ assert.match(LINO_ARGUMENTS, exactVersion);
51
+ });
52
+
53
+ test('command-stream is pinned to 2.0.1+, where node-pty is optional', () => {
54
+ const [major, minor, patch] = COMMAND_STREAM.split('@')[1]
55
+ .split('.')
56
+ .map(Number);
57
+ assert.ok(
58
+ major > 2 || (major === 2 && (minor > 0 || patch >= 1)),
59
+ `${COMMAND_STREAM} must not be 2.0.0, which requires node-pty`
60
+ );
61
+ });
62
+
63
+ test('release scripts load helpers only through the pinned versions', () => {
64
+ for (const { file, source } of scripts) {
65
+ assert.ok(
66
+ !source.includes('unpkg.com/use-m/use.js'),
67
+ `${file} loads an unpinned use-m`
68
+ );
69
+ for (const [, specifier] of source.matchAll(/\buse\(\s*['"`]([^'"`]+)/g)) {
70
+ assert.match(
71
+ specifier,
72
+ exactVersion,
73
+ `${file} loads ${specifier} without an exact version`
74
+ );
75
+ }
76
+ }
77
+ });
78
+
79
+ test('setup-npm.mjs loads no helpers and does not install npm@latest', () => {
80
+ const { source } = scripts.find(({ file }) => file === 'setup-npm.mjs');
81
+ assert.ok(!source.includes('fetch('), 'setup-npm.mjs must not fetch use-m');
82
+ assert.ok(!source.includes('use('), 'setup-npm.mjs must not call use()');
83
+ assert.ok(!source.includes('$`'), 'setup-npm.mjs must not use command-stream');
84
+ assert.equal(NPM_INSTALL_SPEC, 'npm@11');
85
+ });
86
+
87
+ test('release-path scripts reject on a non-zero exit code', () => {
88
+ const releasePath = [
89
+ 'changeset-version.mjs',
90
+ 'create-github-release.mjs',
91
+ 'instant-version-bump.mjs',
92
+ 'publish-to-npm.mjs',
93
+ 'version-and-commit.mjs',
94
+ ];
95
+ for (const name of releasePath) {
96
+ const { source } = scripts.find(({ file }) => file === name);
97
+ assert.ok(
98
+ source.includes('shell.errexit(true)'),
99
+ `${name} must enable errexit`
100
+ );
101
+ }
102
+ });
103
+
104
+ function fakeNpm(versions) {
105
+ const calls = [];
106
+ const run = (args) => {
107
+ calls.push(args.join(' '));
108
+ if (args[0] === '--version') {
109
+ return `${versions.shift()}\n`;
110
+ }
111
+ return '';
112
+ };
113
+ return { run, calls };
114
+ }
115
+
116
+ test('isSupportedNpmVersion requires npm >= 11.5.1', () => {
117
+ assert.equal(NPM_MIN_VERSION, '11.5.1');
118
+ assert.equal(isSupportedNpmVersion('10.8.2'), false);
119
+ assert.equal(isSupportedNpmVersion('11.5.0'), false);
120
+ assert.equal(isSupportedNpmVersion('11.5.1'), true);
121
+ assert.equal(isSupportedNpmVersion('11.21.1'), true);
122
+ assert.equal(isSupportedNpmVersion('12.2.1'), true);
123
+ });
124
+
125
+ test('setupNpm installs npm@11 over the npm 10 bundled with Node.js 20', () => {
126
+ const { run, calls } = fakeNpm(['10.8.2', '11.21.1']);
127
+ assert.equal(setupNpm({ run, log: () => {} }), '11.21.1');
128
+ assert.deepEqual(calls, ['--version', 'install -g npm@11', '--version']);
129
+ });
130
+
131
+ test('setupNpm skips the install when npm already supports OIDC', () => {
132
+ const { run, calls } = fakeNpm(['11.6.2']);
133
+ assert.equal(setupNpm({ run, log: () => {} }), '11.6.2');
134
+ assert.deepEqual(calls, ['--version']);
135
+ });
136
+
137
+ test('setupNpm fails when npm is still too old after the install', () => {
138
+ // A plain re-run did this on main: `npm install -g npm@latest` failed with
139
+ // EBADENGINE, npm stayed on 10.8.2, and the step still exited 0.
140
+ const { run } = fakeNpm(['10.8.2', '10.8.2']);
141
+ assert.throws(() => setupNpm({ run, log: () => {} }));
142
+ });
143
+
144
+ test('setupNpm fails when the npm install command fails', () => {
145
+ const run = (args) => {
146
+ if (args[0] === '--version') {
147
+ return '10.8.2\n';
148
+ }
149
+ throw new Error('npm error code EBADENGINE');
150
+ };
151
+ assert.throws(() => setupNpm({ run, log: () => {} }));
152
+ });
153
+
154
+ const jobResults = {
155
+ lint: 'success',
156
+ test: 'success',
157
+ release: 'failure',
158
+ 'instant-release': 'skipped',
159
+ };
160
+ const env = {
161
+ GITHUB_REPOSITORY: 'link-foundation/gh-setup-git-identity',
162
+ GITHUB_SERVER_URL: 'https://github.com',
163
+ GITHUB_RUN_ID: '37733836425',
164
+ GITHUB_SHA: '3eb61a03876aa15750512cf9e96e9dc847ce231f',
165
+ GITHUB_EVENT_NAME: 'push',
166
+ JOB_RESULTS: JSON.stringify(jobResults),
167
+ };
168
+
169
+ test('release failure report names the run and the failed jobs', () => {
170
+ assert.deepEqual(failedJobs(jobResults), ['release']);
171
+ const body = buildReport({
172
+ repository: env.GITHUB_REPOSITORY,
173
+ runId: env.GITHUB_RUN_ID,
174
+ sha: env.GITHUB_SHA,
175
+ eventName: 'push',
176
+ jobResults,
177
+ });
178
+ assert.includes(
179
+ body,
180
+ 'https://github.com/link-foundation/gh-setup-git-identity/actions/runs/37733836425'
181
+ );
182
+ assert.includes(body, 'Failed jobs: `release`');
183
+ assert.includes(body, 'gh run rerun 37733836425 --failed');
184
+ });
185
+
186
+ test('release failure opens an issue when none is open', () => {
187
+ const calls = [];
188
+ const run = (args) => {
189
+ calls.push(args);
190
+ return args[1] === 'create' ? 'https://github.com/x/y/issues/1' : '';
191
+ };
192
+ const result = reportReleaseFailure({ env, run });
193
+ assert.equal(result.existing, false);
194
+ assert.equal(result.url, 'https://github.com/x/y/issues/1');
195
+ assert.deepEqual(calls.map((args) => args.slice(0, 2)), [
196
+ ['issue', 'list'],
197
+ ['issue', 'create'],
198
+ ]);
199
+ assert.ok(calls[1].includes(ISSUE_TITLE));
200
+ });
201
+
202
+ test('release failure comments on the open issue instead of a duplicate', () => {
203
+ const calls = [];
204
+ const run = (args) => {
205
+ calls.push(args);
206
+ return args[1] === 'list' ? '7' : 'https://github.com/x/y/issues/7#c';
207
+ };
208
+ const result = reportReleaseFailure({ env, run });
209
+ assert.equal(result.existing, true);
210
+ assert.deepEqual(calls[1].slice(0, 3), ['issue', 'comment', '7']);
211
+ });
212
+
213
+ test('release workflow reports failed releases on main', () => {
214
+ const workflow = readFileSync(workflowPath, 'utf8');
215
+ assert.includes(workflow, 'report-release-failure:');
216
+ assert.includes(workflow, 'issues: write');
217
+ assert.includes(workflow, "needs.release.result == 'failure'");
218
+ assert.includes(workflow, "needs.instant-release.result == 'failure'");
219
+ assert.includes(workflow, 'bun scripts/report-release-failure.mjs');
220
+ });
221
+
222
+ test('a re-run after a failed publish still reaches the publish step', () => {
223
+ // The version commit on main already consumed the changesets, so the
224
+ // rebase leaves none. Without already_released, the publish step was
225
+ // skipped. See experiments/issue-32-release-dry-run.sh.
226
+ const { source } = scripts.find(({ file }) => file === 'version-and-commit.mjs');
227
+ const afterRebase = source.slice(source.indexOf('await $`git rebase origin/main`'));
228
+ assert.match(
229
+ afterRebase,
230
+ /countChangesets\(\) === 0\) \{[\s\S]*?setOutput\('already_released', 'true'\)/
231
+ );
232
+ });