#!/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 # 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"