From 9ea8f022a8cd643841065ec194134c4ef2b32bbb Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Thu, 19 Nov 2026 13:08:59 +0200 Subject: [PATCH 1/2] ci: publish the npm packages from CI by trusted publishing, with provenance (#246) publish.yml, run by hand from main in the npm environment, publishes every package whose version npm lacks with pnpm -r publish: in dependency order, one at a time, each after its prepublishOnly. npm takes the run's ID token in place of an access token and records each package's provenance. Node 24, since pnpm publishes through npm and npm takes a trusted publisher's token from 11.5.1. --- .github/workflows/publish.yml | 67 +++++++++++++++++++++++++++++++++++ design/build.md | 11 +++++- design/commands.md | 5 +-- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..49e11767 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,67 @@ +name: Publish to npm + +# Publishes every package whose version npm does not have yet, by trusted publishing. npm trusts +# this file in this repository, run in the `npm` environment, and takes the ID token GitHub gives +# the run in place of an access token, so none is stored anywhere. It then records each package's +# provenance: the run and the commit its tarball was built from. Each package's registration on +# npmjs.com names the file and the environment: renamed, they have to be registered again. +# +# Run it by hand, from main, once the bump is committed and pushed; before a player release, run +# ci.yml by hand first and wait for green (design/build.md). `pnpm -r publish` publishes in +# dependency order and passes over a version npm has, and each package's prepublishOnly runs +# first, as on a publish by hand. A dry run packs and checks each package and publishes none; a +# package's check that its pinned dependency is on npm then stops at one this release would +# publish. + +on: + workflow_dispatch: + inputs: + dry-run: + description: Pack and check every package that would be published, and publish none + type: boolean + default: false + +permissions: + contents: read + +jobs: + npm: + name: npm + runs-on: ubuntu-latest + # The environment deploys from main alone, and each registration names it, so a run from any + # other branch is not trusted. + environment: npm + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v5 + - uses: pnpm/action-setup@v6 + # No cache, as in vscode-publish.yml: a job that publishes installs from the registry against + # the lockfile's hashes, not from a store another run wrote. Node 24: pnpm publishes through + # npm, and npm takes a trusted publisher's token from 11.5.1, which Node 22's npm is not. + - uses: actions/setup-node@v5 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + package-manager-cache: false + - name: Check that npm can publish by trusted publishing + run: | + node -e ' + const [major, minor, patch] = process.argv[1].split(".").map(Number) + if (major < 11 || (major === 11 && (minor < 5 || (minor === 5 && patch < 1)))) { + console.error(`npm ${process.argv[1]} cannot publish by trusted publishing: it needs 11.5.1 or later`) + process.exit(1) + } + ' "$(npm --version)" + - run: pnpm install --frozen-lockfile + # The author, verify, mcp and embed packages' prepublishOnly run browser tests, as ci.yml's + # test jobs do, and install Chromium the same way. + - run: pnpm --filter @missing-elements/h5p-offline-player exec playwright install chromium + # One package at a time, as ci.yml's test jobs run them. Without git checks: prepack writes + # files into the tree (types/, the licence, the skill), and the environment already holds + # the run to main. + - run: pnpm -r --workspace-concurrency=1 publish --access public --no-git-checks $DRY_RUN + env: + NPM_CONFIG_PROVENANCE: true + DRY_RUN: ${{ inputs.dry-run && '--dry-run' || '' }} diff --git a/design/build.md b/design/build.md index a3e08008..27457e60 100644 --- a/design/build.md +++ b/design/build.md @@ -138,7 +138,16 @@ went; `typecheck` and `prepack` both run it. Three rules, with TypeScript 7: ## Publishing and Node versions -`pnpm publish` in `packages/player` runs `prepublishOnly` (typecheck, the unit suite and the +**The packages are published from CI, by trusted publishing** (#246). `publish.yml` is run by hand +from main, in the `npm` environment, once the bump is pushed (`gh workflow run publish.yml`). It +publishes every package whose version npm lacks, as `pnpm -r publish` finds them: in dependency +order, one at a time, passing over a version npm has. npm takes the ID token GitHub gives the run +in place of an access token, so none is stored, and records each package's provenance, the run and +the commit its tarball came from. Each package's trusted publisher on npmjs.com names the file and +the environment. pnpm publishes through npm, which takes that token from 11.5.1, so the job runs +Node 24. A publish by hand, with a one-time password, still works and records no provenance. + +A publish of the player runs its `prepublishOnly` (typecheck, the unit suite and the build) so a broken tree cannot ship; the browser suite is left out because it needs an installed Chromium. Firefox, WebKit and the slow browser files run only in CI's weekly run and a run by hand, so before publishing the player, run CI by hand on main (`gh workflow run ci.yml`) and wait for diff --git a/design/commands.md b/design/commands.md index f3aabd34..cf60f799 100644 --- a/design/commands.md +++ b/design/commands.md @@ -71,5 +71,6 @@ the installable app; the demo's pages are checked by hand, and the skills are te the content-type sweep. Node 22 LTS or 24 LTS: the commands the packages ship need 22, and the browser packages keep -`>=20`. Packages are published with pnpm, which rewrites the `workspace:` ranges, and each one's -`prepublishOnly` is its guard: [`design/build.md`](build.md). +`>=20`. Packages are published with pnpm, which rewrites the `workspace:` ranges, from CI +(`gh workflow run publish.yml` on main), and each one's `prepublishOnly` is its guard: +[`design/build.md`](build.md). From 0655856d8d13df352c0f871337ce8eb471947b03 Mon Sep 17 00:00:00 2001 From: Aleksandr Shevchuk Date: Thu, 19 Nov 2026 13:23:55 +0200 Subject: [PATCH 2/2] ci: no registry-url in publish.yml; the player's pack check in the design (#246) npm's default registry is npm's, and setup-node would write a placeholder token for it that nothing here needs. design/build.md lists the player's prepublishOnly with its first step, the check that the pack it names is on npm. --- .github/workflows/publish.yml | 5 +++-- design/build.md | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 49e11767..c676e85a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,11 +39,12 @@ jobs: - uses: pnpm/action-setup@v6 # No cache, as in vscode-publish.yml: a job that publishes installs from the registry against # the lockfile's hashes, not from a store another run wrote. Node 24: pnpm publishes through - # npm, and npm takes a trusted publisher's token from 11.5.1, which Node 22's npm is not. + # npm, and npm takes a trusted publisher's token from 11.5.1, which Node 22's npm is not. No + # registry-url: npm's default is npm's registry, and setup-node would write a placeholder token + # for it, which nothing here needs. - uses: actions/setup-node@v5 with: node-version: 24 - registry-url: https://registry.npmjs.org package-manager-cache: false - name: Check that npm can publish by trusted publishing run: | diff --git a/design/build.md b/design/build.md index 27457e60..5877137f 100644 --- a/design/build.md +++ b/design/build.md @@ -147,8 +147,8 @@ the commit its tarball came from. Each package's trusted publisher on npmjs.com the environment. pnpm publishes through npm, which takes that token from 11.5.1, so the job runs Node 24. A publish by hand, with a one-time password, still works and records no provenance. -A publish of the player runs its `prepublishOnly` (typecheck, the unit suite and the -build) so a broken tree cannot ship; the browser suite is left out because it needs an installed +A publish of the player runs its `prepublishOnly` (a check that the pack it names is on npm, +typecheck, the unit suite and the build) so a broken tree cannot ship; the browser suite is left out because it needs an installed Chromium. Firefox, WebKit and the slow browser files run only in CI's weekly run and a run by hand, so before publishing the player, run CI by hand on main (`gh workflow run ci.yml`) and wait for green. Then `prepack` copies the root LICENSE into the package, which is where npm takes it