#!/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 # A release needs at least one entry under Unreleased. awk '/^## \[Unreleased\]$/ { section = 1; next } /^## / { section = 0 } section && NF { entry = 1 } END { exit entry ? 0 : 1 }' CHANGELOG.md \ || { echo "CHANGELOG.md needs an entry under '## [Unreleased]'" >&2; exit 1; } if [ -n "$bump" ]; then npm version "$bump" --no-git-tag-version fi version=$(node -p "require('./package.json').version") name=$(node -p "require('./package.json').name") npm run check npm pack --dry-run # The Unreleased section becomes the entry for this version, and a fresh # Unreleased section opens above it. perl -0pi -e "s/^## \[Unreleased\]\$/## [Unreleased]\n\n## [$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 # npm answers with a placeholder for a few minutes before the version resolves. tries=0 until [ "$(npm view "$name@$version" version 2>/dev/null | tr -d "[:space:]'")" = "$version" ]; do tries=$((tries + 1)) if [ "$tries" -ge 40 ]; then echo "npm still has not served $name@$version after 10 minutes. Check https://www.npmjs.com/package/$name" >&2 break fi sleep 15 done