iterate.com / kernel

git clone https://git.iterate.com/repos/kernel

npm: a push to the mirror's main publishes iterate under main, with no approval

Misha's answer on the card build-and-validate-the-standalone-npm-publisher
(27 Nov 2026, 17:48 UTC): builds of main publish hands-free, as they did from
iterate/private, in the format 0.4.1-main.<commit date>-<sha>. The publish job
runs for a push to main, and latest follows main as before. A run that was
held back does not move the tag to an older commit's version.

Tests: none
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158EjAJiCEsoJzhkn5QhDmj

Jonas Templestein, 2026-11-27 17:49 UTC · 8926e82e30c026761bd671f539539c43d9ff2ca0 · parent 3c8c377

2 files changed

M .github/npm-publish.mjs
@@ -119,8 +119,7 @@
 
     const manifestPath = join(work, "packed/package/package.json");
     const { devDependencies: _d, ...manifest } = JSON.parse(readFileSync(manifestPath, "utf8"));
-    if (manifest.name !== name)
-      throw new Error(`${folder} holds ${manifest.name}, not ${name}`);
+    if (manifest.name !== name) throw new Error(`${folder} holds ${manifest.name}, not ${name}`);
     const version = versionAt({ version: manifest.version, distTag, committedAt, sha });
     writeFileSync(
       manifestPath,
@@ -200,6 +199,16 @@
       throw new Error(`${name}@${version} was not packed for the dist-tag ${distTag}`);
     const npm = await packumentOf(name);
     const last = await publishedAt(name, distTag, work);
+    // a run that was held back: the dist-tag names a later commit's version already. The date
+    // leads the version, so text order is commit order.
+    if (
+      last &&
+      last.version.startsWith(`${version.split("-")[0]}-${distTag}.`) &&
+      last.version > version
+    )
+      return await say(
+        `npm \`${distTag}\` names ${last.version}, which is later than ${version}: not published`,
+      );
     const unchanged = last && !differs(filesOf(join(work, "packed/package")), last.files);
     const has = Boolean(npm?.versions[version]);
     const names = unchanged ? last.version : version;
@@ -251,13 +260,9 @@
   const missing = await missingOnNpm(NAME, oidc);
   if (!missing) return await say(`npm is ready for this workflow to publish ${NAME}.`);
   await say(
-    [
-      `${missing.said}. As someone who may publish it:`,
-      "",
-      "```sh",
-      ...missing.setup,
-      "```",
-    ].join("\n"),
+    [`${missing.said}. As someone who may publish it:`, "", "```sh", ...missing.setup, "```"].join(
+      "\n",
+    ),
   );
   throw new Error(`npm is not ready for ${NAME}`);
 }
M .github/workflows/npm-publish.yml
@@ -4,8 +4,9 @@
 # publishing takes an OIDC token from GitHub's own runners alone. The package's settings on
 # npmjs.com name that repository, this file and the environment `npm`.
 #
-# A push to main packs the package and installs it, and publishes nothing. A dispatch on main names
-# what to do with main's tip:
+# A push to main publishes the package under the tag `main` and moves `latest` to it, when its
+# packed files changed, with no person: `0.4.1-main.<commit date>-<sha>` says that it is a build
+# of a commit and no release. A dispatch on main names something else to do with main's tip:
 #
 #   gh workflow run npm-publish.yml --repo iterate/kernel -f action=<dry-run | canary | main | check>
 #
@@ -14,9 +15,9 @@
 # installs passed, with no script of it run. `check` asks npm, as this workflow, whether the
 # package trusts it; it writes and removes the tag `npm-publish-check` and nothing else.
 #
-# `publish` and `check` wait for a person: the environment `npm` has required reviewers. That gate
-# is a setting on GitHub, so no commit here can remove it. Without it, a commit that edits this
-# file could publish, and mirror.yml brings every commit of the source's main.
+# WHO PUBLISHES: whoever can put a commit on main of the source, because mirror.yml brings every
+# such commit here and this file is part of it. Misha chose that on 27 Nov 2026 for builds of main;
+# a real release gets a person's approval when there is one.
 on:
   push:
     branches:
@@ -32,10 +33,11 @@
           - main
           - check
         default: dry-run
-# One run at a time for an action, in order, and no run is cancelled: a publish that was cut off
-# could leave `latest` behind `main`.
+# One run at a time for a dist-tag, in order, and no run is cancelled: a publish that was cut off
+# could leave `latest` behind `main`. A run that waits is replaced by a newer one, which publishes
+# what both changed.
 concurrency:
-  group: npm-${{ inputs.action || 'push' }}
+  group: npm-${{ inputs.action || 'main' }}
   cancel-in-progress: false
 permissions: {}
 jobs:
@@ -89,11 +91,11 @@
           path: ${{ runner.temp }}/tarball
       - run: node .github/npm-publish.mjs install --tarball "$(ls "$RUNNER_TEMP"/tarball/*.tgz)"
   # npm gets the tarball that both installs passed, as it is: no script of the package runs here.
-  # Only a dispatch on main that names a dist-tag gets here. The environment `npm` takes main
-  # alone, and a reviewer of it approves the job.
+  # Only main gets here: a push, or a dispatch that names a dist-tag. The environment `npm` takes
+  # main alone.
   publish:
     needs: [pack, install]
-    if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && (inputs.action == 'canary' || inputs.action == 'main')
+    if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || inputs.action == 'canary' || inputs.action == 'main')
     runs-on: ubuntu-latest
     environment: npm
     permissions:
@@ -116,7 +118,7 @@
           path: ${{ runner.temp }}/tarball
       - run: node .github/npm-publish.mjs publish --tarball "$(ls "$RUNNER_TEMP"/tarball/*.tgz)" --dist-tag "$DIST_TAG"
         env:
-          DIST_TAG: ${{ inputs.action }}
+          DIST_TAG: ${{ inputs.action || 'main' }}
   check:
     if: github.repository == 'iterate/kernel' && github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.action == 'check'
     runs-on: ubuntu-latest