diff --git a/.github/release-plz.toml b/.github/release-plz.toml index bb6419f..07fc2a7 100644 --- a/.github/release-plz.toml +++ b/.github/release-plz.toml @@ -1,7 +1,5 @@ [workspace] changelog_update = true -git_only = true -publish = false git_tag_enable = true git_release_enable = true git_release_type = "auto" diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index 190f65a..a9db54a 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -11,8 +11,12 @@ jobs: release: runs-on: ubuntu-latest timeout-minutes: 20 + # crates.io trusts this workflow and environment; release-plz exchanges + # the job's OIDC token for a short-lived publish token. + environment: crates-io permissions: contents: read + id-token: write steps: - name: harden runner uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffd96f9..e4d0bf2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,10 @@ # Release builds once release-plz has published a GitHub release: a wheel and -# a binary archive per platform, the archives attached to the release and the -# wheels sent to PyPI. release-plz owns the version, the tag and crates.io -# (docs/reference/release.md). One machine per platform, because these are the -# only jobs that must run on macOS and Windows (ADR 0017). A pull request that -# changes the release build runs the builds without publishing anything. +# a binary archive per platform, the archives attached to the release, the +# wheels sent to PyPI and the Homebrew formula rewritten. release-plz owns the +# version, the tag and crates.io (docs/reference/release.md). One machine per +# platform, because these are the only jobs that must run on macOS and Windows +# (ADR 0017). A pull request that changes the release build runs the builds +# without publishing anything. name: release on: @@ -184,3 +185,58 @@ jobs: enable-cache: false - name: publish run: uv publish --trusted-publishing always dist/* + + # Rewrites Formula/dataseek.rb in lmarkmann/homebrew-tap from the checksums + # just attached, with a release App token scoped to that one repository. + homebrew: + if: github.event_name == 'release' && !github.event.release.prerelease + needs: assets + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + steps: + - name: harden runner + uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1 + with: + egress-policy: audit + - name: token + id: app + uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 + with: + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + owner: lmarkmann + repositories: homebrew-tap + permission-contents: write + - name: checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: checkout tap + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: lmarkmann/homebrew-tap + token: ${{ steps.app.outputs.token }} + path: tap + persist-credentials: false + - name: formula + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + TAG: ${{ github.event.release.tag_name }} + run: | + gh release download "$TAG" --repo "$REPO" -p '*.tar.gz.sha256' -D sums + scripts/homebrew-formula.sh "$TAG" sums > tap/Formula/dataseek.rb + - name: push + working-directory: tap + env: + TOKEN: ${{ steps.app.outputs.token }} + TAG: ${{ github.event.release.tag_name }} + run: | + git config user.name "lmarkmann-release[bot]" + git config user.email "333785277+lmarkmann-release[bot]@users.noreply.github.com" + git add Formula/dataseek.rb + git diff --cached --quiet && exit 0 + git commit -m "dataseek $TAG" + git push "https://x-access-token:$TOKEN@github.com/lmarkmann/homebrew-tap.git" HEAD:main diff --git a/README.md b/README.md index 54d9947..547a986 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ Most sources need no key and nothing to set up. Results come back in the termina ## Install ```sh -cargo install --locked dataseek # builds dataseek and dsk from source -cargo binstall dataseek # a prebuilt binary when the release has one, else builds -uv tool install dataseek # installs dataseek and dsk with uv +brew install lmarkmann/tap/dataseek # dataseek and dsk, with completions and the man page +cargo binstall dataseek # the prebuilt binaries from the release +cargo install --locked dataseek # builds them from source +uv tool install dataseek # the binaries in a wheel ``` To run it once without installing: @@ -25,7 +26,7 @@ crgx --allow-build dataseek search sea surface temperature uvx dataseek search sea surface temperature ``` -To upgrade, run the install command again, or `uv tool upgrade dataseek` for uv. Building from source needs a recent stable Rust toolchain; from a clone, `cargo install --locked --path .` does the same. +To upgrade, run the install command again, or `brew upgrade dataseek` and `uv tool upgrade dataseek`. Building from source needs a recent stable Rust toolchain; from a clone, `cargo install --locked --path .` does the same. ## Usage diff --git a/docs/reference/release.md b/docs/reference/release.md index 3257288..3fdcaca 100644 --- a/docs/reference/release.md +++ b/docs/reference/release.md @@ -29,7 +29,6 @@ Nothing earlier than v0.3.0 exists: release-plz diffs against the newest `v*` ta `.github/release-plz.toml`, passed through the action's `config` input in both jobs and `--config` locally: -- `git_only = true`, `publish = false`: the previous version comes from git tags, not crates.io, and release-plz publishes nothing. Both go once the first crates.io release exists (below). - `git_release_enable = true`, `git_release_type = "auto"`, `git_release_body = "{{ changelog }}"`: every tag gets a GitHub release carrying that version's section. - `release_commits`: release-plz decides whether to release from changed files, not from changelog groups, so without it a `ci:` merge alone opens a release with an empty section. That is how v0.3.1 happened. - `features_always_increment_minor = true`: see ADR 0003. @@ -59,16 +58,11 @@ No release-plz subcommand has a dry-run flag, so the recipe runs the real `relea `cargo install dataseek` installs `dataseek` and `dsk`. The package holds only what building needs (`cargo package --list`); the `internals` feature is for the benches and unstable. -crates.io trusts a publisher only for a crate that exists, so the first release goes up by hand: - -1. Merge the release PR; release-plz tags `vX.Y.Z`. -2. `git switch --detach vX.Y.Z && cargo publish --locked`, with a new-crate token in `CARGO_REGISTRY_TOKEN`. -3. Add the trusted publisher on crates.io (`lmarkmann/dataseek`, workflow `release-plz.yml`, environment `crates-io`), then revoke the token. -4. Drop `git_only` and `publish = false` from `.github/release-plz.toml`, and give the `release` job `environment: crates-io` and `id-token: write`. +The `release` job publishes through crates.io trusted publishing (`lmarkmann/dataseek`, workflow `release-plz.yml`, environment `crates-io`); no registry token is stored. ## Publishing to PyPI -`uvx dataseek` runs a wheel holding both binaries, built by maturin with the version from `Cargo.toml`. `release.yml` builds the wheels on each GitHub release and uploads them with `uv publish` through trusted publishing ([ADR 0017](../adr/0017-release-builds-on-a-platform-matrix.md)). The same jobs attach `dataseek-.tar.gz` (`.zip` on Windows) with a `.sha256` to the release, which `cargo binstall dataseek` downloads. +`uvx dataseek` runs a wheel holding both binaries, built by maturin with the version from `Cargo.toml`. `release.yml` builds the wheels on each GitHub release and uploads them with `uv publish` through trusted publishing ([ADR 0017](../adr/0017-release-builds-on-a-platform-matrix.md)). The same jobs attach `dataseek-.tar.gz` (`.zip` on Windows) with a `.sha256` to the release, which `cargo binstall dataseek` downloads, and its `homebrew` job rewrites `Formula/dataseek.rb` in [lmarkmann/homebrew-tap](https://github.com/lmarkmann/homebrew-tap) from them with `scripts/homebrew-formula.sh`, through a release App token scoped to the tap. Before the first release, add a pending publisher at : project `dataseek`, `lmarkmann/dataseek`, workflow `release.yml`, environment `pypi`. diff --git a/scripts/homebrew-formula.sh b/scripts/homebrew-formula.sh new file mode 100755 index 0000000..6c7577c --- /dev/null +++ b/scripts/homebrew-formula.sh @@ -0,0 +1,60 @@ +#!/bin/sh +# Prints the Homebrew formula for one release, from the .sha256 files the +# release workflow attaches next to each archive: +# +# scripts/homebrew-formula.sh v0.8.0 +# +# The release workflow writes the output to Formula/dataseek.rb in +# lmarkmann/homebrew-tap (docs/reference/release.md). +set -eu + +tag=$1 +sums=$2 +releases="https://github.com/lmarkmann/dataseek/releases/download/$tag" + +sha() { + cut -d' ' -f1 "$sums/dataseek-$1.tar.gz.sha256" +} + +cat < "dsk.1" + end + + test do + assert_match version.to_s, shell_output("#{bin}/dsk --version") + end +end +EOF