build: move release scripts and harden publish

publish.sh and test_npm_package.sh now live in scripts/ and cd to the
repo root, so they run from any directory. publish.sh polls npm until
the released version resolves: the first release ended inside the
registry's processing window, when a fresh install still gets the
0.0.0-stage placeholder. It also reopens an empty Unreleased section
after the rename and refuses an empty one before the version bump, so
a refused release leaves the tree clean.

test_npm_package.sh switches pi between the symlink checkout and
npm:pi-nous-portal. Only one may be installed: pi identifies npm
packages by name and local ones by path, so both register the provider
twice.
This commit is contained in:
AlexKucera committed 2026-11-25 16:51:36 +01:00
1 parent 21ec8029c5
commit b71363efb9
8 files changed
+146 -8

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
#!/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
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Switch pi between this checkout (a symlink) and the published npm package.
#
# ./test_npm_package.sh toggle to whichever is not active
# ./test_npm_package.sh dev load this checkout
# ./test_npm_package.sh npm load the published package
#
# Only one of the two may be installed. pi identifies an npm package by name
# and a local one by path, so both at once register the provider twice.
# Takes effect on the next pi start or /reload.
set -euo pipefail
cd "$(dirname "$0")/.."
name=$(node -p "require('./package.json').name")
provider=nous-portal
agent_dir="${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}"
repo="$PWD"
link="$agent_dir/extensions/$provider"
npm_installed() {
node -e "
const packages = require('$agent_dir/settings.json').packages || [];
const source = 'npm:$name';
process.exit(packages.some(p => (typeof p === 'string' ? p : p.source) === source) ? 0 : 1);
" 2>/dev/null
}
if [ -n "${1:-}" ]; then
target="$1"
elif [ -e "$link" ] || [ -L "$link" ]; then
target=npm
elif npm_installed; then
target=dev
else
target=npm
fi
case "$target" in
dev)
if npm_installed; then pi remove "npm:$name"; fi
mkdir -p "$(dirname "$link")"
if [ ! -e "$link" ] && [ ! -L "$link" ]; then ln -s "$repo" "$link"; fi
echo "dev: $link -> $repo"
;;
npm)
# Plain rm on the symlink. A trailing slash or -r would delete the checkout.
if [ -e "$link" ] || [ -L "$link" ]; then rm "$link"; fi
if ! npm_installed; then pi install "npm:$name"; fi
echo "npm: npm:$name in $agent_dir/settings.json"
;;
*)
echo "usage: $0 [dev|npm]" >&2
exit 1
;;
esac
echo "$provider models on the next start: $(pi --list-models 2>/dev/null | grep -c -w "$provider")"