Files
yuez 8fb535f7f3 feat(cli): add pi2 update with a versioned install layout
The standalone (curl installer) channel had no upgrade path of its own: the
documented one was 're-run the installer', which the Neovim plugin cannot do
safely and which re-downloads 35 MB without version arithmetic, provenance or
rollback. ADR 0003 records the design; this is the implementation.

- install.sh now installs one immutable tree per version
  (`<prefix>/versions/<v>/{bin,share,LICENSE}`) behind a single atomically
  swapped `current` symlink, writes `<prefix>/install.json` as the install
  receipt, and migrates a pre-0.1.7 flat layout in place. Keeping `current` plus
  one previous tree gives a one-step rollback for free.
- `pi2 update` (native TypeScript, no `curl | sh` subprocess) resolves the
  release with an ETag-cached GitHub lookup, picks the asset from the
  build-time `PI2_BUILD_TARGET` define instead of re-probing libc, verifies
  SHA256SUMS, verifies SLSA provenance with `gh attestation verify`, runs the
  new binary once, then swaps `current` and rewrites the receipt. Flags:
  --check/--dry-run/--version/--force/--json/--require-attestation/
  --skip-attestation. Downgrades need --force; restarts stay manual.
- the receipt is the only channel detection: npm, Homebrew and the AUR are
  refused with the command that owns their tree, and a flat install is told to
  re-run the installer once. No heuristics on `process.execPath`.
- `pi2 install-service` renders `<prefix>/current/bin/pi2`, so an update no
  longer invalidates the unit.
- `scripts/build-binary.sh` injects `PI2_BUILD_TARGET`; `tarball.ts` is a
  dependency-free ustar/PAX reader with traversal and symlink rejection.

Verified against the real release: install.sh into a scratch prefix, update
--check/--dry-run, a local 0.1.7 mirror upgrade (attestation warn path), then
`pi2 update --version 0.1.6 --force` (real download, real attestation
verified), plus boot-check and the refusal paths. typecheck + 567 daemon tests
+ web typecheck + 537 web tests + smoke are green.
2026-10-29 16:42:57 +08:00

6.7 KiB

name, description
name description
release Cut and verify a pi2d release — pick the version, tag it, let GitHub Actions publish to npm through Trusted Publishing (OIDC), then verify the registry artifact, provenance, a clean install and a booting daemon. Use when asked to "release", "publish", "cut a version", "bump the version", or to diagnose a failed release run.

Release pi2d

Runbook. Architecture and house rules live in AGENTS.md; the npmjs.com checklist, provenance rationale and the long troubleshooting table live in ../../../docs/releasing.md. This file is the procedure to execute.

Non-negotiables

  • Publish only from CI. Tag → .github/workflows/release.yml → OIDC. A local npm publish is the one-time bootstrap only (see below), never the steady state.
  • No tokens. The publish step holds no credentials; the workflow's first guard step fails the job when NPM_TOKEN / NODE_AUTH_TOKEN is still present in the repo.
  • Tag == package.json version. The workflow verifies the pair and refuses to publish a mismatch.
  • Push the tag explicitly. git push --follow-tags only pushes annotated tags; a lightweight tag is skipped silently and release.yml never runs.

Steady-state release

  1. Preconditions — clean tree on main, in sync with origin/main, and CI green on the commit you are about to tag: gh run list --repo zgs225/pi2d --workflow ci.yml --limit 3.
  2. Pick the version with the user (do not assume). Semver: breaking → major, feature → minor, fix → patch. There is no CHANGELOG.md; build the notes from git log --oneline "$(git describe --tags --abbrev=0)"..HEAD, grouped by conventional type.
  3. Bump and commit:
    npm version <x.y.z> --no-git-tag-version
    git commit -am "chore: release <x.y.z>"
    
  4. Tag and push (annotated tag, pushed explicitly):
    git tag -a "v<x.y.z>" -m "v<x.y.z>"
    git push origin main
    git push origin "v<x.y.z>"
    
  5. Watch the publish:
    gh run watch "$(gh run list --repo zgs225/pi2d --workflow release.yml --limit 1 \
        --json databaseId --jq '.[0].databaseId')" --repo zgs225/pi2d --exit-status
    
    The interesting steps are Upgrade npm, Preflight — npm/node support trusted publishing, Publish to npm (trusted publishing, no token) and Create GitHub release.
  6. Verify the artifact — do not trust a green job, check the registry:
    bash .agents/skills/release/scripts/verify-release.sh <x.y.z>
    
    It asserts the exact version is on the registry, the SLSA provenance attestation exists, a clean install from the public registry reports pi2 <x.y.z>, the tarball ships web/dist, dist/cli/pi2.js and LICENSE, the daemon boots and serves / + a healthy /api/v1/health, and the GitHub release exists. Every line is PASS/FAIL; exit non-zero on any failure.
  7. Report the version, the run URL, the verification output and the release URL. Mention whether the new version is latest (a backport is not).

Bootstrap (once per package name, already done for @yuez/pi2d)

Only relevant if the package has left the registry. npmjs.com offers the Trusted Publisher page only for a package that already exists, so the first publish is manual:

  1. From the repo root: npm login (account yuez, 2FA) → npm whoami → npm publish --access public. That artifact has no provenance; every later release does.
  2. Then add the trusted publisher on npmjs.com: owner zgs225 (GitHub), repo pi2d, workflow filename release.yml, environment empty, and tick npm publish (post-2026-09-03 configs allow only npm stage publish by default). The first CI publish must happen within 2 days or the configuration expires.
  3. Bump to a higher version for the first CI release — npm rejects republishing a version.

Release assets (the curl channel)

release.yml also publishes six pi2d-<version>-<target>.tar.gz assets plus SHA256SUMS and SLSA provenance (actions/attest-build-provenance), which pi2 update consumes. Two things to know before debugging a missing asset:

  • Backfill an existing tag without re-publishing npm: gh workflow run release.yml -f tag=v0.1.6 — publish and packaging are gated on github.event_name == 'push', so a dispatch run only rebuilds and re-attaches assets. This is the repair path for "the release has no tarballs" (it happened to v0.1.6: the darwin-x64 leg sat queued on the retired macos-13 image for 21 h and checksums never ran).
  • Runner labels matter more than the build. darwin-x64 needs macos-15-intel and darwin-arm64 needs macos-15; a retired or deprecated label leaves the leg queued forever and the whole asset job blocked. Verify with gh api repos/zgs225/pi2d/actions/runs/<id>/jobs --jq '.jobs[] | "\(.name) \(.status)"'.

Verify what actually landed, not that the run was green:

gh release view "v<x.y.z>" --repo zgs225/pi2d --json assets --jq '.assets[].name'
gh attestation verify pi2d-<x.y.z>-linux-x64.tar.gz --repo zgs225/pi2d
PI2_VERSION=<x.y.z> PI2_INSTALL_DIR=/tmp/pi2-check/lib PI2_BIN_DIR=/tmp/pi2-check/bin \
  sh scripts/install.sh && sh scripts/boot-check.sh /tmp/pi2-check/bin/pi2 <x.y.z>

Failure playbook

Symptom Cause / action
No release.yml run after pushing The tag never reached the remote. Check gh api repos/zgs225/pi2d/tags --jq '.[].name'; a lightweight tag plus --follow-tags is silent. Push the tag explicitly.
ENEEDAUTH / "Unable to authenticate" OIDC or policy mismatch: workflow filename must be exactly release.yml, npm publish must be ticked under allowed actions, id-token: write must be present, and the trusted publisher must be attached to this package.
Preflight fails on npm version setup-node's node 22 ships npm 10; the Upgrade npm step must run before the preflight.
Refuse token-based publishing fails A NPM_TOKEN/NODE_AUTH_TOKEN repo secret still exists. Delete it — OIDC is the intended path.
E403 Package name too similar Unscoped names hit the registry's similarity filter; this package is scoped as @yuez/pi2d and must stay scoped.
E403 You cannot publish over the previously published versions The version was already published (often the bootstrap). Bump and re-tag.
Create GitHub release 403 Workflow permissions lost contents: write.
EOTP on a local publish Only the bootstrap needs 2FA; pass --otp=<code>. Steady state never publishes locally.

Definition of done

Registry shows the version with a slsa.dev/provenance attestation, verify-release.sh prints OK, the GitHub release exists, the working tree is clean, and the report tells the user what to install (npm i -g @yuez/pi2d@<x.y.z>).