fix(ci): stop a failed publish from reporting as a successful release
Two bugs in one line, both silent, both found in review before anything shipped.
**The pipe swallowed the exit status.** `deno publish | tee` reports the status
of the last command in the pipeline, and that is `tee`, which always succeeds.
GitHub's default shell is `bash -e` *without* `pipefail`, so a failed publish
would have been a green step — and the workflow would have gone on to cut a
GitHub release for it. Demonstrated rather than assumed:
bash -e -c 'false | tee /dev/null' -> exit 0
bash -eo pipefail -c 'false | tee /dev/null' -> exit 1
Naming `shell: bash` gets `-eo pipefail`.
**And the log was going to be empty anyway.** deno's logger is env_logger,
whose default target is stderr, so the `Successfully published` lines never
reach stdout. Measured against a real `deno publish`: 0 lines on stdout, all of
them on stderr. So `--notes` would have found nothing and announced that nothing
shipped, on every successful release. `2>&1` fixes it.
The second bug is the reason for the third change: `--notes` now refuses a log
carrying neither marker instead of reporting it as "nothing was published". A log
this script cannot read and a release where nothing shipped are indistinguishable
from the text, and guessing wrong is silent in the direction that matters. Now it
fails and says to check the redirect and the pipeline.
Verified all three paths: an empty log exits 1, an all-skipped log renders the
"already on JSR" line and exits 0, and a real publish log renders per-package
sections.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
2 files changed
+29
-1
No files matched your search
@@ -64,8 +64,21 @@ jobs:
|
||||
# No token: OIDC exchanges the workflow's id-token, which is also what attaches provenance.
|
||||
# `tee` because the release body is built from what this actually did rather than from a guess
|
||||
# about what it would do.
|
||||
#
|
||||
# Two details in this one line, both of which produce a *silently wrong* release when missed:
|
||||
#
|
||||
# `shell: bash` — the default shell here is `bash -e`, without `pipefail`, so a pipeline
|
||||
# reports the exit status of its LAST command. That is `tee`, which always
|
||||
# succeeds. A failed publish would have been reported as a green step, and
|
||||
# a GitHub release created for it. Naming the shell gets `-eo pipefail`.
|
||||
#
|
||||
# `2>&1` — deno's logger is env_logger, whose default target is stderr, so every
|
||||
# "Successfully published" line goes there. Measured: a publish writes 0
|
||||
# lines to stdout and all of them to stderr. Without this the log is empty
|
||||
# and the release notes say nothing shipped while three packages did.
|
||||
- name: Publish
|
||||
run: deno publish | tee /tmp/publish.log
|
||||
shell: bash
|
||||
run: deno publish 2>&1 | tee /tmp/publish.log
|
||||
|
||||
- name: Release notes
|
||||
run: node scripts/release.mjs --notes /tmp/publish.log "$GITHUB_REF_NAME" > /tmp/notes.md
|
||||
|
||||
@@ -96,6 +96,21 @@ function notes(logPath, tag) {
|
||||
const shipped = [...plain.matchAll(/Successfully published (@[^@\s]+\/[^@\s]+)@(\S+)/g)]
|
||||
.map(([, name, version]) => ({ name, version }));
|
||||
|
||||
// A log carrying neither marker is not "nothing was published" — it is a log this script cannot
|
||||
// read, and the two are indistinguishable from the text alone. Saying nothing shipped when three
|
||||
// packages did is the worse failure, and it is silent, so refuse instead of guessing.
|
||||
//
|
||||
// This is not hypothetical: the first version of this workflow piped only stdout, while deno logs
|
||||
// to stderr, so every successful release would have produced an empty log and a release body
|
||||
// announcing that nothing happened.
|
||||
if (shipped.length === 0 && !/already published/.test(plain)) {
|
||||
throw new Error(
|
||||
`${logPath} contains neither "Successfully published" nor "already published". ` +
|
||||
'Either the publish did not run, or its output is not being captured — check that the step ' +
|
||||
'redirects stderr (deno logs there) and that the pipeline uses pipefail.',
|
||||
);
|
||||
}
|
||||
|
||||
if (shipped.length === 0) {
|
||||
return `No package versions were published by \`${tag}\` — every version in the workspace was already on JSR.`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user