Files
kits/scripts/trust-gitlab.sh
CatoandClaude Opus 5.5 a0197d1974 release: 14 packages through GitLab, so every package keeps its npm trust
accountkit 0.33.0, ai-kit 1.32.0 and design-tokens 1.8.0 carry the changes
that waited in their changelogs since publishing stopped on 2026-11-15; the
other 11 are patch releases with no code change. Publishing each once from
GitLab validates its new trust (npm drops one unused for 2 days).

scripts/trust-gitlab.sh replaces an older (GitHub) trust instead of failing:
npm keeps one per package, and bip-kit and chartkit failed with ENEEDAUTH.
README: releasing never needs npm; only a brand-new package needs one trust.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
2026-11-21 18:04:17 +01:00

63 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Once per package, ever: tell npm that .gitlab-ci.yml in gitlab.com/bitbaum/kits
# may publish it. One npm sign-in with the security key covers the whole run
# (tick "do not challenge for 5 minutes" when npm asks). Run it right before
# the package's first release this way: npm drops a trust that has not
# published within 2 days.
#
# scripts/trust-gitlab.sh <folder> [folder ...]
#
# `--all` does every package in packages/. npm keeps ONE trust per package:
# a package that already trusts this GitLab job is left alone, and one that
# trusts anything else (its old GitHub workflow) has that entry revoked first,
# because adding a second fails and the GitLab publish then ends in ENEEDAUTH
# (what happened to bip-kit and chartkit on 2026-11-21).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
PROJECT="${GITLAB_PROJECT:-bitbaum/kits}"
# `npm trust` needs npm >= 11.15, and returned 400 on 11.x for us (2026-10): use 12.
NPM=(npx -y npm@12)
folders=("$@")
[ ${#folders[@]} -gt 0 ] || { echo "name the package folder(s), or --all" >&2; exit 2; }
[ "${folders[0]}" = --all ] && folders=($(ls packages))
ok=0; failed=()
for f in "${folders[@]}"; do
name=$(node -p "require('./packages/$f/package.json').name")
# A failed `--json` call still prints JSON ({"error": ...}) and exits 1, so
# never append a fallback to it: `|| echo '[]'` made two documents and the
# parse below crashed instead of saying npm wanted a sign-in (EOTP).
entries=$("${NPM[@]}" trust list "$name" --json || true)
plan=$(printf '%s' "$entries" | PROJECT="$PROJECT" node -e '
let d = JSON.parse(require("fs").readFileSync(0, "utf8").trim() || "[]");
if (d && d.error) {
if (d.error.code !== "E404") { console.log("ERROR", d.error.code, d.error.authUrl || d.error.summary || ""); process.exit(); }
d = [];
}
if (!Array.isArray(d)) d = Object.values(d).find(Array.isArray) || [d];
for (const e of d) {
const s = JSON.stringify(e).toLowerCase();
if (s.includes("gitlab") && s.includes(process.env.PROJECT.toLowerCase())) console.log("KEEP", e.id ?? "?");
else if (e.id) console.log("REVOKE", e.id);
}')
if grep -q '^ERROR' <<<"$plan"; then
echo "FAILED $name: npm trust list said $(sed -n 's/^ERROR //p' <<<"$plan")"; failed+=("$name"); continue
fi
if grep -q '^KEEP' <<<"$plan"; then echo "already $name"; ok=$((ok + 1)); continue; fi
while read -r action id; do
[ "$action" = REVOKE ] || continue
"${NPM[@]}" trust revoke --id "$id" "$name" && echo "revoked $name (old trust $id)"
sleep 2
done <<<"$plan"
if "${NPM[@]}" trust gitlab "$name" --file .gitlab-ci.yml --project "$PROJECT" --allow-publish --yes; then
echo "trusted $name"; ok=$((ok + 1))
else
echo "FAILED $name"; failed+=("$name")
fi
sleep 2
done
echo "trusted $ok, failed ${#failed[@]}${failed:+: ${failed[*]}}"
[ ${#failed[@]} -eq 0 ]