From 7f8e1e454158d73073b24749e32bb45a64f09eb1 Mon Sep 17 00:00:00 2001 From: Dennis Paler Date: Mon, 30 Nov 2026 22:22:03 +0800 Subject: [PATCH] release: preflight checks each package's collaborators instead of the user's package list 'npm access list packages' without a scope lists the logged-in user's own packages (GET /-/org//package), which a granular token may not read: the preflight failed with E403 on its first run although the token is valid (npm whoami succeeded). It now reads each @checkgate package's collaborators and requires read-write for the token's identity, for all nine packages (all exist since 0.2.0). --- .github/workflows/release.yml | 40 +++++++++++++++-------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 574dc79..80209a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -479,30 +479,24 @@ jobs: [ -n "$NODE_AUTH_TOKEN" ] || { echo "Error: NPM_TOKEN is not set."; exit 1; } WHO="$(npm whoami)" echo "npm identity: $WHO" - npm access list packages --json > access.json - node -e ' - const a = require("./access.json"); - const need = ["node","web","cli","edge","ssr","react-native"].map((p) => "@checkgate/" + p); - const bad = need.filter((p) => a[p] !== "read-write"); - for (const p of need) console.log(` ${p}: ${a[p] ?? "no access"}`); - if (bad.length) { console.error("Error: no read-write access to " + bad.join(", ")); process.exit(1); } - ' - # The new packages (openfeature-provider, node-integrations, - # mcp-server) are created by their first publish. Org members of - # any role may create packages in the org scope; a granular token - # must also cover the @checkgate scope, not only listed packages. - if npm org ls checkgate "$WHO" --json > role.json 2>/dev/null; then - echo "role in the checkgate org: $(node -p 'Object.values(require("./role.json"))[0] ?? "none"')" - else - echo "::warning::Could not read the checkgate org role (the token may lack organization read permission). Confirm on npmjs.com that this token's package scope includes @checkgate." - fi - for p in openfeature-provider node-integrations mcp-server; do - if npm view "@checkgate/$p" version >/dev/null 2>&1; then - echo " @checkgate/$p already exists: $(npm view @checkgate/$p versions --json | tr -d '\n ')" - else - echo " @checkgate/$p does not exist yet (its first publish creates it)" - fi + # Per-package collaborators: whether THIS identity may publish each + # package. (`npm access list packages` without a scope lists the + # user's own packages, which a granular token may not read: 403.) + # Every package exists since 0.2.0, so all nine are checked. + BAD="" + for p in node web cli edge ssr react-native openfeature-provider node-integrations mcp-server; do + ACCESS="$(npm access list collaborators "@checkgate/$p" --json | WHO="$WHO" node -e ' + let b = ""; process.stdin.on("data", (d) => b += d).on("end", () => { + console.log(JSON.parse(b)[process.env.WHO] ?? "no access"); + });')" + echo " @checkgate/$p: $ACCESS" + [ "$ACCESS" = read-write ] || BAD="$BAD @checkgate/$p" done + if [ -n "$BAD" ]; then echo "Error: $WHO has no read-write access to:$BAD"; exit 1; fi + # A granular token can be limited to some packages or to read-only; + # that cannot be checked without publishing. Confirm on npmjs.com + # that the token has read and write on the @checkgate scope. + echo "::notice::Token scope cannot be verified without publishing: confirm on npmjs.com that NPM_TOKEN has read-write on @checkgate." - name: pub.dev — credentials present and well-formed env: