forestui icon indicating copy to clipboard operation
forestui copied to clipboard

Distribution: adopt the house release matrix and bring back auto self-update

Open flipbit03 opened this issue 3 months ago • 6 comments

Blocked on #26 merging. The Rust port replaces the PyPI/uv tool distribution, and the release path needs to land before the first tag or a release will simply fail. Tracking it here rather than in the PR, since it is follow-on work on this repo.

Two of my other Rust CLIs already solve this — lineark and terminal-use — and forestui should match them so one install script and one updater shape cover all three.

1. Release matrix

Replace the matrix #26 lands with (gnu Linux x86_64, both macOS arches) with the house layout:

runner target asset
ubuntu-latest x86_64-unknown-linux-musl forestui_linux_x86_64
ubuntu-24.04-arm aarch64-unknown-linux-musl forestui_linux_aarch64
macos-latest aarch64-apple-darwin forestui_macos_aarch64

Differences from what #26 ships, and why:

  • [x] musl, not gnu — static Linux binaries with no glibc floor.
  • [x] ARM Linux included. Currently absent, so an ARM Linux box falls through to cargo install and needs a full Rust toolchain. Needs musl-tools installed, guarded by if: contains(matrix.target, 'musl').
  • [x] macOS x86_64 dropped — the other installers point Intel Macs at cargo install.
  • [x] Bare binaries, not tarballs. This is what lets the updater be a single download with no unpacking step.
  • [x] permissions: contents: write at workflow level. Without it gh release upload fails at the last step on a repo whose default token is read-only.
  • [x] Build with --features binary-release (see below).
  • [x] Version patched from the tag; source stays 0.0.0.
  • [x] Reconsider cargo publish --allow-dirty — lineark needs it because it patches Cargo.toml in place, so it probably stays, but it should be a deliberate choice.

2. install.sh

  • [x] Rewrite to lineark's shape: detect linux|macos × x86_64|aarch64, refuse macOS x86_64 with a cargo install hint, resolve releases/latest, drop the bare asset into $HOME/.local/bin, warn if that is not on PATH.
  • [x] Decide on checksums. #26 adds .sha256 verification to install.sh; keep it and have the new workflow publish the checksums, or drop the check rather than leave it warning on every install. Publishing them is the better end state.
  • [x] Keep the existing uv tool uninstall forestui hint for people coming from the Python build. Note ~/.local/bin typically precedes ~/.cargo/bin on PATH, so a leftover Python install silently keeps winning.

3. Auto self-update — the part that differs

lineark and terminal-use update manually via <tool> self update. The Python forestui updated automatically on every launch (uv tool upgrade forestui), and that behaviour should survive the port. #26 drops it, correctly noting there is no sane Cargo equivalent — but the answer is the binary path, not removal.

Port from crates/lineark/src/version_check.rs and commands/self_cmd.rs:

  • [x] binary-release cargo feature, off by default, enabled only by the release build.
  • [x] is_dev_build() — version 0.0.0 never self-updates. This is what protects cargo run and a checked-out source build.
  • [x] Latest version from the GitHub releases API, cached at ~/.config/forestui/latest_version_check.json.
  • [x] Update path branches on cfg!(feature = "binary-release"): download the asset and atomically rename over current_exe() when it came from a release; shell out to cargo install forestui when it came from cargo.

Adaptations specific to forestui:

  • [x] Automatic, not a subcommand — but forestui is a TUI and CLAUDE.md requires instant start, so the check must not block. Run it as a background task once the UI is up and surface a notification ("forestui vX.Y.Z installed — restart to use it"). Replacing the file under a running process is safe on Unix; the running image is already mapped.
  • [x] Make --no-self-update real again. #26 reduces it to an accepted no-op. Wire it to skip the check, and keep it forwarded through the tmux re-exec argv (cli.rs::self_command already does).
  • [x] Use the same HTTP spec as the other two — reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] } plus semver = "1". rustls-tls is not cosmetic: it drops the native-tls/OpenSSL system dependency, which is what makes the musl static builds link.

4. Prerequisites before the first tag

  • [x] Create the CARGO_REGISTRY_TOKEN repo secret.
  • [x] Confirm the crates.io name forestui is available.
  • [x] Confirm the repo's default Actions token permissions, or rely on the explicit permissions: block.

flipbit03 avatar Aug 15 '26 02:08 flipbit03

Pre-flight done against the merged tree. cargo publish --dry-run passes — packages 115 files, 1.1 MiB (309.6 KiB compressed) — and the crate name forestui is free on crates.io. Cargo.toml already carries everything the registry requires (description, license, repository, readme, keywords, categories).

Two things to fix before the first publish, both found by the dry run:

  • [ ] There is no LICENSE file. Cargo.toml declares license = "MIT" and the registry accepts the SPDX identifier on its own, so the publish will succeed — but shipping a crate that claims MIT with no licence text anywhere in the repo is a gap worth closing rather than inheriting.
  • [ ] 79 of the 115 packaged files are doc/ — the rust-rewrite spec and the committed sweep baselines. Nobody installing from crates.io needs them, and they are the bulk of the tarball. Add an exclude to [package] for doc/, scripts/, .github/ and install.sh.

Also worth noting for the token step: crates.io API tokens can be scoped to specific crates, but a crate that does not exist yet cannot be scoped to. The first publish needs a token with the publish-new scope; once forestui exists it can be rotated to a crate-scoped publish-update token, which is what lineark and terminal-use effectively run on. Both of those repos already carry a CARGO_REGISTRY_TOKEN secret; forestui currently has none.

flipbit03 avatar Aug 15 '26 03:08 flipbit03

Correcting my previous comment on the token: forestui should use Trusted Publishing and never hold a CARGO_REGISTRY_TOKEN secret at all.

crates.io supports OIDC trusted publishing now, via the official rust-lang/crates-io-auth-action (v1.0.5). The workflow asks GitHub for a JWT, exchanges it with crates.io for a 30-minute token, and the action's post step revokes it when the job ends — same model as the PyPI trusted publishing the old publish.yml used before the rewrite deleted it.

  publish:
    permissions:
      id-token: write        # required to mint the OIDC JWT
      contents: read
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - uses: rust-lang/crates-io-auth-action@v1
        id: auth
      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

Note permissions: has to be set on the job here, not only at workflow level, because the binary-upload job needs contents: write and this one needs id-token: write.

One ordering constraint: crates.io cannot configure a trusted publisher for a crate that does not exist yet, so the first version has to be published by hand. That is cargo publish from a local checkout against an ordinary cargo login session — it does not need a repo secret, and nothing long-lived ends up in GitHub. Sequence:

  1. Land the LICENSE and the exclude (above), so v0.1.0 ships the right files.
  2. cargo publish locally to claim forestui and create the crate.
  3. Configure the trusted publisher on crates.io: crate settings → Trusted Publishing → owner flipbit03, repo forestui, workflow release.yml.
  4. Every release after that runs tokenless from CI.

lineark and terminal-use both still use a stored CARGO_REGISTRY_TOKEN; worth migrating them the same way once this one is proven.

flipbit03 avatar Aug 15 '26 03:08 flipbit03

Status after the #26 merge: 12 of 21 boxes ticked, and the half this issue is named for is untouched.

Done — §1 release matrix (musl x86_64 + aarch64, ARM Linux included, macOS x86_64 dropped, bare binaries with a .sha256 beside each, permissions: contents: write, version from the tag), all of §2 install.sh (rewritten to the house shape, checksum verified both ways against a stub release server, uv tool uninstall hint kept), and all of §4 plus the LICENSE and the crate exclude from the comment above — the crate now packages 28 files / 418 KiB instead of 115 / 1.1 MiB.

Not done:

  • All of §3, the auto self-update. No binary-release feature, no version_check, no reqwest/semver, and --no-self-update is still a no-op — cli.rs forwards it through the tmux argv and nothing ever reads it. This is the behaviour the Python build had on every launch and the reason the issue exists.
  • --features binary-release in the release workflow, which has nothing to gate until §3 lands.
  • cargo publish --allow-dirty was carried over from lineark rather than deliberately decided.

One live bug blocks the first release. Both version-patch steps rewrite Cargo.toml only, but Cargo.lock records the package's own version too, and the binary job builds with --locked:

error: cannot update the lock file ... because --locked was passed to prevent this

The publish job runs first and would succeed, so a tag today puts 2.0.0 on crates.io and then fails all three binary builds — a release with no binaries attached, and a version number that cannot be reused. Fix is to patch both files, verified locally (cargo build --release --locked then forestui 2.0.0). Not yet pushed.

flipbit03 avatar Aug 15 '26 03:08 flipbit03

PR #32 covers the rest of this: all of §3, and the --features binary-release build flag from §1. 20 of 21 boxes.

The one left is cargo publish --allow-dirty, carried over from lineark rather than deliberately decided — deliberately not touched in #32, since changing the publish invocation right after a successful release is not something to do incidentally.

flipbit03 avatar Aug 15 '26 03:08 flipbit03

Groomed the last checkbox (slot 6 of the ship-a-thon train): --allow-dirty stays, now deliberate — the workflow seds the tag version into Cargo.toml/Cargo.lock without committing, so the tree is dirty by design at publish time. A why-comment lands next to the publish line and this epic closes.

flipbit03 avatar Aug 15 '26 22:08 flipbit03

Final checkbox ticked and the epic is complete: --allow-dirty was confirmed load-bearing (the workflow stamps the tag version into Cargo.toml/Cargo.lock uncommitted, so the tree is dirty by design at publish time) and is now documented in release.yml (#44). 21 of 21.

flipbit03 avatar Aug 16 '26 16:08 flipbit03