@jonmilner/local-ci 0.3.2 → 0.3.3
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 +1 -1
- package/dist/release.js +21 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ exec pnpm exec local-ci pre-push "$@"
|
|
|
28
28
|
2. At the merge commit (or the default branch, with no changesets pending), it runs `local-ci status`, then `pnpm release` with the npm token, then pushes the tags `changeset publish` created.
|
|
29
29
|
3. It checks each published `name@version` with `npm view`, waiting up to 5 minutes in all for the registry to list them. A timeout or `npm view` error here exits non-zero, but the publish already ran: check with the `npm view` command the error gives before rerunning.
|
|
30
30
|
|
|
31
|
-
A failure after the push closes the PR and deletes `release/<short-sha>`; Ctrl-C (SIGINT), SIGTERM, SIGHUP (closing the terminal) or Ctrl-\\ (SIGQUIT) stops the running step (killing `pnpm release` and the publish it started), does the same cleanup, then exits 128 + the signal number, e.g. 130 for Ctrl-C (a second signal exits at once, killing the publish outright). A run killed outright leaves its temp worktree and local branch, which the next run removes; its PR and remote branch stay open for you to close. Step 2 runs even with no changesets pending, so a rerun after a failed publish finishes the job. With nothing pending and every version already on npm it prints `nothing to release`. The repo needs changesets and a root `release` script (for example `pnpm build && changeset publish`). The npm token comes from the macOS Keychain (service `local-ci-npm`) and is passed only in `pnpm release`'s environment, never written to `.npmrc` or logged; see [npm publish token](../../docs/new-machine.md#npm-publish-token).
|
|
31
|
+
A failure after the push closes the PR and deletes `release/<short-sha>`; Ctrl-C (SIGINT), SIGTERM, SIGHUP (closing the terminal) or Ctrl-\\ (SIGQUIT) stops the running step (killing `pnpm release` and the publish it started), does the same cleanup, then exits 128 + the signal number, e.g. 130 for Ctrl-C (a second signal exits at once, killing the publish outright). A run killed outright leaves its temp worktree and local branch, which the next run removes; its PR and remote branch stay open for you to close. Step 2 runs even with no changesets pending, so a rerun after a failed publish finishes the job. If npm refuses the publish because it already has the version (a rerun while the registry still lags), it says so with the `npm view` command to check, instead of blaming the token; rerun once npm lists it. With nothing pending and every version already on npm it prints `nothing to release`. The repo needs changesets and a root `release` script (for example `pnpm build && changeset publish`). The npm token comes from the macOS Keychain (service `local-ci-npm`) and is passed only in `pnpm release`'s environment, never written to `.npmrc` or logged; see [npm publish token](../../docs/new-machine.md#npm-publish-token).
|
|
32
32
|
|
|
33
33
|
## Check command
|
|
34
34
|
|
package/dist/release.js
CHANGED
|
@@ -16,6 +16,8 @@ const TEMP_PREFIX = "local-ci-release-";
|
|
|
16
16
|
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
|
|
17
17
|
// What npm and pnpm print when the registry rejects the token, or wants an OTP it can't bypass.
|
|
18
18
|
const AUTH_ERROR = /\b(?:E401|E403|EOTP|ERR_PNPM_OTP_NON_INTERACTIVE|401 Unauthorized|403 Forbidden)\b/;
|
|
19
|
+
// What npm prints when the version is already on the registry. It comes with an E403, so it is checked before AUTH_ERROR.
|
|
20
|
+
const PUBLISH_OVER = /cannot publish over the previously published version/;
|
|
19
21
|
const id = ({ name, version }) => `${name}@${version}`;
|
|
20
22
|
function alive(pid) {
|
|
21
23
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
@@ -113,8 +115,15 @@ function run(file, args, cwd) {
|
|
|
113
115
|
throw new Error(`${file} ${args.join(" ")} failed (${cause})`);
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
+
/** The hint for checking each package on npm by hand. */
|
|
119
|
+
const npmView = (packages) => packages.length
|
|
120
|
+
? `check with: ${packages.map((pkg) => `npm view ${id(pkg)} version`).join("; ")}`
|
|
121
|
+
: "check with: npm view <name>@<version> version";
|
|
122
|
+
/**
|
|
123
|
+
* Runs `pnpm release` with the token in its env only, teeing its output to spot a rejected token
|
|
124
|
+
* or a version npm already has. `packages` are the ones it should publish, for the hints.
|
|
125
|
+
*/
|
|
126
|
+
function publish(dir, token, packages, signal) {
|
|
118
127
|
return new Promise((resolve, reject) => {
|
|
119
128
|
const child = spawn("pnpm", ["release"], {
|
|
120
129
|
cwd: dir,
|
|
@@ -147,15 +156,18 @@ function publish(dir, token, signal) {
|
|
|
147
156
|
process.off("exit", kill);
|
|
148
157
|
};
|
|
149
158
|
let authError = false;
|
|
159
|
+
let publishOver = false;
|
|
150
160
|
const tee = (stream, sink) => {
|
|
151
161
|
// Keep a tail so a match split across chunks is still seen.
|
|
152
162
|
let tail = "";
|
|
153
163
|
stream.on("data", (chunk) => {
|
|
154
164
|
sink.write(chunk);
|
|
155
165
|
const text = tail + chunk.toString();
|
|
166
|
+
if (PUBLISH_OVER.test(text))
|
|
167
|
+
publishOver = true;
|
|
156
168
|
if (AUTH_ERROR.test(text))
|
|
157
169
|
authError = true;
|
|
158
|
-
tail = text.slice(-
|
|
170
|
+
tail = text.slice(-64);
|
|
159
171
|
});
|
|
160
172
|
};
|
|
161
173
|
tee(child.stdout, process.stdout);
|
|
@@ -171,9 +183,11 @@ function publish(dir, token, signal) {
|
|
|
171
183
|
kill();
|
|
172
184
|
if (code === 0)
|
|
173
185
|
return resolve();
|
|
174
|
-
reject(new Error(
|
|
175
|
-
? `npm
|
|
176
|
-
:
|
|
186
|
+
reject(new Error(publishOver
|
|
187
|
+
? `npm already has a version this run tried to publish, so it refused to publish over it; the registry may still be catching up on an earlier publish. Rerun once npm lists it; ${npmView(packages)}`
|
|
188
|
+
: authError
|
|
189
|
+
? `npm rejected the token in the Keychain (service ${TOKEN_SERVICE}); it may have expired or lack "bypass 2FA". Rotate it: ${SETUP_DOC}`
|
|
190
|
+
: `pnpm release failed (${code === null ? killed : `exit ${code}`})`));
|
|
177
191
|
});
|
|
178
192
|
});
|
|
179
193
|
}
|
|
@@ -394,7 +408,7 @@ export async function release(exec, context) {
|
|
|
394
408
|
await stepRun(process.execPath, [context.cli, "status"], dir);
|
|
395
409
|
await live();
|
|
396
410
|
log(`publishing ${packages.map(id).join(", ") || "nothing new"}`);
|
|
397
|
-
await track(publish(dir, token, abort.signal));
|
|
411
|
+
await track(publish(dir, token, packages, abort.signal));
|
|
398
412
|
// Every current version, so a tag an earlier half-failed run left unpushed goes too.
|
|
399
413
|
await pushTags(stepGit, stepRun, dir, await publicPackages(step, dir));
|
|
400
414
|
if (packages.length)
|