diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..46ff374 --- /dev/null +++ b/.github/workflows/pr.yml @@ -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 diff --git a/README.md b/README.md index a33d524..131d6b7 100644 --- a/README.md +++ b/README.md @@ -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 ` 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. diff --git a/scripts/new-to-npm.sh b/scripts/new-to-npm.sh new file mode 100755 index 0000000..a9fb06f --- /dev/null +++ b/scripts/new-to-npm.sh @@ -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 ) 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 ) 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"