#!/usr/bin/env bash # Release pi-nous-portal to npm and push the tag. # # ./publish.sh release the version in package.json # ./publish.sh patch bump first (minor, major, or an explicit version work too) # # npm asks for your 2FA code at the publish step. If the publish fails after # the tag exists, fix the cause and rerun: npm publish && git push origin main --follow-tags set -euo pipefail bump="${1:-}" cd "$(dirname "$0")" [ -z "$(git status --porcelain)" ] || { echo "working tree is not clean" >&2; exit 1; } [ "$(git branch --show-current)" = "main" ] || { echo "not on main" >&2; exit 1; } npm whoami >/dev/null if [ -n "$bump" ]; then npm version "$bump" --no-git-tag-version fi version=$(node -p "require('./package.json').version") grep -qx '## \[Unreleased\]' CHANGELOG.md || { echo "CHANGELOG.md has no '## [Unreleased]' heading" >&2; exit 1; } npm run check npm pack --dry-run # The Unreleased section becomes the entry for this version. perl -0pi -e "s/^## \[Unreleased\]\$/## [$version] - $(date +%F)/m" CHANGELOG.md git commit -am "release v$version" git tag -a "v$version" -m "v$version" npm publish git push origin main --follow-tags