A local-first multi-agent app development platform, built on PenguinHarness
fix(ci,release): pre-flight npm before publishing, and publish by manifest (#742)
Yaowei Zhengb31ebbad96e7
diff --git a/.agents/skills/penguin-harness-dev/reference/release.md b/.agents/skills/penguin-harness-dev/reference/release.mdindex 667dc208..46da49cc 100644--- a/.agents/skills/penguin-harness-dev/reference/release.md+++ b/.agents/skills/penguin-harness-dev/reference/release.md@@ -36,6 +36,19 @@ Two bugs, and the second is the one to remember:The lesson under both: **a green CI that builds differently from the release proves nothing aboutthe release.** When the two diverge, the divergence is the defect.+### A package npm has never seen cannot be published by the release++npm's trusted publishing is configured **per package**. A name that does not exist yet has no+configuration, so the OIDC token exchange 404s, and the release job carries no fallback credential+— the first publish of a new name needs a person with npm rights, done once, before the tag.++0.2.13 cost a run to learn this: company mode brought `@penguinharness/agent-company`, plugins+publish in directory order, it sorts first, and the job died on it before `core`, `server` or `cli`+were reached.++`node scripts/check-publishable.mjs --registry` lists the names that need it; the `npm packaging`+CI job runs it on every pull request and warns. **Read that warning before tagging.**+## Order1. Branch `release/<version>` off `main`, in a worktree.diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 75554b5c..9f090437 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -81,8 +81,11 @@ jobs:steps:- uses: actions/checkout@v5- uses: ./.github/actions/setup- - name: A published package depends on nothing private- run: node scripts/check-publishable.mjs+ # --registry also asks npm which published names do not exist yet. A new package is+ # legitimate, so that is a warning rather than a failure -- but it has to be seen before the+ # tag, because the release's OIDC exchange cannot create a name npm has never seen.+ - name: A published package depends on nothing private, and names that need a first publish+ run: node scripts/check-publishable.mjs --registry- name: Build the whole workspace, as the release doesrun: pnpm -r build# The release stages two things into the package directories before it publishes: the rootdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 8d45f34b..2403a1cb 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -621,6 +621,14 @@ jobs:# rather than its exit code -- for a missing version of an existing package, older npm exits 0 and# newer npm exits 1, but the output is non-empty only when the version exists. Re-running the tag# after a mid-chain failure (e.g. Trusted Publisher not configured yet) picks up where it left off.+ # Before anything is published: every name this job will push must already exist on npm, or+ # be one the run can create. npm's trusted publishing is configured per package, so a name npm+ # has never seen cannot be published here at all -- and the loop would find that out partway+ # through, having already published everything alphabetically before it. 0.2.13 lost a run to+ # exactly that. Fail here instead, naming what needs a first publish by hand.+ - name: Every package this publishes already exists on npm+ run: node scripts/check-publishable.mjs --registry --strict+- name: Publish to npmrun: |TAG="${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}"@@ -636,7 +644,16 @@ jobs:# The @penguinharness/* plugin packages go first: core declares them as workspace:*# deps, rewritten to their versions at publish time, so they must exist first.for dir in plugins/*/; do- name="@penguinharness/$(basename "$dir")"+ # Read the name and the private flag out of the manifest rather than building a name+ # from the directory: plugins/sandbox-* are @prismshadow/penguin-plugin-sandbox-* and+ # private, so a derived name queries a package that does not exist and filters to+ # nothing. Publishing is driven by what each package says it is.+ name="$(node -p "require('./$dir/package.json').name")"+ private="$(node -p "require('./$dir/package.json').private === true")"+ if [ "$private" = "true" ]; then+ echo "$name is private, not published."+ continue+ fiif [ -n "$(npm view "$name@$V" version 2>/dev/null || true)" ]; thenecho "$name@$V already on the registry, skipping."continuediff --git a/scripts/check-publishable.mjs b/scripts/check-publishable.mjsindex c3d88748..1d3d5da7 100755--- a/scripts/check-publishable.mjs+++ b/scripts/check-publishable.mjs@@ -12,8 +12,22 @@* This is the shape that broke the 0.2.12 release: `packages/server` took `@prismshadow/penguin-hmr`* — private, and bundled — as a runtime dependency.*- * Usage: node scripts/check-publishable.mjs+ * With `--registry`, it additionally asks npm which of the packages a release publishes do not+ * exist there yet. That is not a defect — a new plugin has to be new once — but it is the one+ * thing the release cannot do on its own: npm's trusted publishing is configured per package, a+ * name that does not exist has no configuration, and the OIDC token exchange 404s. The release+ * job carries no fallback credential, so the first publish of a new name needs a human. Finding+ * that out from a warning on a pull request costs nothing; finding it out from the release run+ * costs a version number, which is what 0.2.13 cost.+ *+ * `--strict` turns that warning into a failure. CI warns, because adding a package is+ * legitimate and blocking every such pull request would be the wrong trade; the release+ * pre-flight fails, because the release genuinely cannot publish a name npm has never seen+ * and finding out mid-loop costs a version number.+ *+ * Usage: node scripts/check-publishable.mjs [--registry] [--strict]*/+import { execFileSync } from "node:child_process";import { readdirSync, readFileSync } from "node:fs";import path from "node:path";@@ -52,6 +66,61 @@ if (problems.length > 0) {for (const p of problems) console.error(` ${p}`);process.exit(1);}+const publishable = [...workspace.values()].filter((p) => !p.private).length;console.log(- `publishable packages: ${[...workspace.values()].filter((p) => !p.private).length} publishable, none depends on a private workspace package`,+ `publishable packages: ${publishable} publishable, none depends on a private workspace package`,);++if (!process.argv.includes("--registry")) process.exit(0);++// Everything the release publishes: the non-private packages above, plus every plugin — the+// release loops `plugins/*/` and publishes each as `@penguinharness/<dir>`.+// Read each plugin's own name and private flag rather than deriving a name from its directory:+// `plugins/sandbox-*` are `@prismshadow/penguin-plugin-sandbox-*` and private, so a name built+// from the directory names a package that does not exist and never will.+const pluginNames = [];+for (const entry of readdirSync(path.join(root, "plugins"), { withFileTypes: true })) {+ if (!entry.isDirectory()) continue;+ try {+ const pkg = read(path.join(root, "plugins", entry.name, "package.json"));+ if (pkg.name && pkg.private !== true) pluginNames.push(pkg.name);+ } catch {+ // Not a package directory.+ }+}++const names = [+ ...[...workspace.entries()].filter(([, p]) => !p.private).map(([name]) => name),+ ...pluginNames,+].sort();++const missing = [];+for (const name of names) {+ try {+ execFileSync("npm", ["view", name, "name"], { stdio: ["ignore", "ignore", "ignore"] });+ } catch {+ missing.push(name);+ }+}++if (missing.length > 0) {+ const list = missing.join(", ");+ const strict = process.argv.includes("--strict");+ const say = strict ? console.error : console.log;+ say(+ `${strict ? "" : "::warning::"}${missing.length} package(s) have never been published: ${list}. ` ++ `npm trusted publishing is configured per package, so the release's OIDC exchange cannot ` ++ `create a name that does not exist yet and will fail on the first one it reaches. ` ++ `Publish each once by hand (or give it a trusted publisher) BEFORE tagging.`,+ );+ say(`first publish needed: ${list}`);+ if (strict) {+ console.error(+ "Publish each once by hand with credentials that may create it, then re-run. The release " ++ "cannot do this itself.",+ );+ process.exit(1);+ }+} else {+ console.log(`registry: all ${names.length} published names already exist`);+}