Files
CatoandClaude Opus 5.5 9970922b74 ci(kits): publish to npm from GitLab.com on a release tag (#6)
* ci(kits): publish to npm from GitLab.com on a release tag

npm's trusted publishing (no stored npm token) accepts only GitHub Actions,
GitLab.com shared runners and CircleCI cloud. GitHub Actions has been off for
the bitbaum org since 2026-11-15 and Gitea's runners are self-hosted, so every
release needed an npm sign-in and a security key on the laptop.

- .gitlab-ci.yml: on `<folder>-v<version>`, check the version matches, pack
  with pnpm (workspace ranges written in), publish the tarball with npm.
- scripts/release.sh: bump, verify, commit, tag, push to origin and gitlab;
  no npm login.
- scripts/trust-gitlab.sh: once per package, trust the GitLab job.

Provenance stays off until package.json `repository` names the project that
builds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(kits): trust a package at its first GitLab release (npm drops unused trusts after 2 days)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 14:28:40 +01:00

54 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Release ONE package from this repo: raise its version, check it and every
# package that uses it, commit, tag, push. The tag reaching GitLab.com is what
# publishes it to npm (.gitlab-ci.yml) — no npm login on this machine.
#
# scripts/release.sh <package-folder> <patch|minor|major|x.y.z>
# scripts/release.sh --pending # list packages whose version is not on npm yet
#
# Replaces the 7 release workflows each old package repo carried. Run it from
# a clean main. Needs a `gitlab` remote (the GitLab.com project that
# publishes): `git remote add gitlab git@gitlab.com:bitbaum/kits.git`.
#
# pnpm publish turns `workspace:^` into the real version range, so apps get
# ordinary semver dependencies.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
published() { npm view "$1@$2" version 2>/dev/null || true; }
if [ "${1:-}" = "--pending" ]; then
for dir in packages/*/; do
name=$(node -p "require('./${dir}package.json').name")
ver=$(node -p "require('./${dir}package.json').version")
[ -n "$(published "$name" "$ver")" ] || echo "$name@$ver is not on npm"
done
exit 0
fi
PKG="${1:?package folder, e.g. listkit}"; BUMP="${2:?patch|minor|major|x.y.z}"
DIR="packages/$PKG"
[ -f "$DIR/package.json" ] || { echo "no package at $DIR" >&2; exit 1; }
[ "$(git rev-parse --abbrev-ref HEAD)" = main ] || { echo "release from main" >&2; exit 1; }
[ -z "$(git status --porcelain)" ] || { echo "working tree is not clean" >&2; exit 1; }
git remote get-url gitlab >/dev/null 2>&1 || { echo "no 'gitlab' remote — see the top of this file" >&2; exit 1; }
NAME=$(node -p "require('./$DIR/package.json').name")
( cd "$DIR" && npm version "$BUMP" --no-git-tag-version >/dev/null )
VER=$(node -p "require('./$DIR/package.json').version")
[ -z "$(published "$NAME" "$VER")" ] || { echo "$NAME@$VER is already on npm" >&2; git checkout -- "$DIR/package.json"; exit 1; }
echo "releasing $NAME@$VER"
# The package and everything in this repo that depends on it.
pnpm install --frozen-lockfile=false >/dev/null
pnpm -r --workspace-concurrency=1 --filter "...$NAME" run verify
git add "$DIR/package.json" pnpm-lock.yaml
git commit --quiet -m "release($PKG): $VER"
git tag "$PKG-v$VER"
git push --quiet origin main "$PKG-v$VER"
git push --quiet gitlab main "$PKG-v$VER"
echo "tagged $NAME@$VER — GitLab publishes it to npm in about a minute"