ci: a pull request runs the tests and fails while a package in it isn't on npm yet (#52)

Trusted publishing can't create a package, so #39's block-patterns,
merged before its first version was on npm, left every publish run on
main red after it (8 runs, the last 37781353941), and a real refused
publish would have hidden behind it. pr.yml runs bun test and check.mjs
on each pull request, and scripts/new-to-npm.sh names any package npm
doesn't know, so its first version is published by hand and its Trusted
Publisher set before the merge. The README's market section says so.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yetone
2026-10-08 21:59:38 +08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent f4c0d96c9c
commit 2b0b2d9401
3 changed files with 64 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# Checks a pull request before it is merged: the tests publish.yml runs, and
# that every package is on npm already (scripts/new-to-npm.sh). A new
# package merged first turned every publish run red (#39's block-patterns).
name: pr
on:
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: 24
- name: test
# the tests refuse a real home: no real sign-in is ever read
run: HOME=$(mktemp -d) bun test
- name: check
run: bun scripts/check.mjs
on-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- name: every package is on npm
run: scripts/new-to-npm.sh
+7
View File
@@ -156,3 +156,10 @@ it can't. To list a plugin, add an entry with its npm `package`, a
`name`, `providers` (the provider ids it signs in to), an `icon` and a
`summary` in English and Chinese (`{"en": …, "zh": …}`), and open a pull
request.
A new package's first version is published by hand before its pull request
is merged: npm's trusted publishing, which publishes every later version
from `main`, can't create a package. A magpie-community npm owner runs
`scripts/publish.sh <otp>` on the pull request's branch and sets
`.github/workflows/publish.yml` as the package's Trusted Publisher on
npmjs.com. The pull request's `on-npm` check fails until then.
+22
View File
@@ -0,0 +1,22 @@
#!/bin/sh
# Fails, naming them, when a package here has never been published to npm.
# Trusted publishing can't create a package, so one merged before its first
# version is on npm leaves every publish run on main red until someone
# publishes it by hand (scripts/publish.sh <otp>) and sets publish.yml as
# its Trusted Publisher on npmjs.com. A pull request runs this, so that is
# done before the merge, not found after.
set -e
cd "$(dirname "$0")/.."
export npm_config_registry=https://registry.npmjs.org
for dir in packages/*/; do
name=$(node -p "require('./${dir}package.json').name")
if [ "$(npm view "$name" name 2>/dev/null)" != "$name" ]; then
echo "::error file=${dir}package.json::$name is not on npm yet, and trusted publishing can't create it. Before this is merged, a magpie-community npm owner publishes its first version by hand (scripts/publish.sh <otp>) and sets .github/workflows/publish.yml as its Trusted Publisher on npmjs.com; then re-run this check."
new="$new $name"
fi
done
if [ -n "$new" ]; then
echo "new to npm:$new"
exit 1
fi
echo "every package is on npm"