From cc8483ec11b7ba725ad3dac50535f0812408b358 Mon Sep 17 00:00:00 2001 From: Mike Zupan Date: Sun, 8 Nov 2026 09:41:15 -0800 Subject: [PATCH] Release the CLI when a version bump merges to main Like query-api, merging a Cargo.toml version bump now tags and publishes that version; tags are no longer pushed by hand. A Cargo.toml change that keeps a released version (dependabot) publishes nothing. The security workflow no longer runs on pushes to main. --- .github/workflows/release.yml | 63 ++++++++++++++++++++++++---------- .github/workflows/security.yml | 2 -- README.md | 21 +++++------- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0604f9..4233ea2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,55 +1,78 @@ name: Release CLI +# Like query-api: merging a version bump in Cargo.toml to main tags and publishes +# that version. Run it by hand on main to retry a release that failed. on: push: - tags: - - "v*" + branches: [main] + paths: [Cargo.toml] workflow_dispatch: - inputs: - tag: - description: Existing version tag to build and publish - required: true - type: string permissions: contents: read -env: - TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }} - concurrency: - group: release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }} + group: release-cli cancel-in-progress: false jobs: validate: - name: Validate tag and test + name: Read version, test, and tag runs-on: ubuntu-latest + permissions: + contents: write + outputs: + tag: ${{ steps.version.outputs.tag }} + release: ${{ steps.version.outputs.release }} steps: - name: Check out source uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ env.TAG }} + fetch-depth: 0 - name: Install Rust run: | rustup toolchain install stable --profile minimal rustup default stable - - name: Require the tag to match Cargo.toml + - name: Read the package version + id: version + shell: bash run: | - version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')" - if [[ "$TAG" != "v$version" ]]; then - echo "Release tag $TAG does not match package version $version. Expected v$version." >&2 - exit 1 + set -euo pipefail + version="$(cargo metadata --locked --no-deps --format-version 1 | jq -r '.packages[0].version')" + tag="v${version}" + echo "tag=${tag}" >> "$GITHUB_OUTPUT" + if git rev-parse --verify --quiet "refs/tags/${tag}" >/dev/null \ + && [[ "$(git rev-parse "refs/tags/${tag}^{commit}")" != "$GITHUB_SHA" ]]; then + # Cargo.toml changed without a version bump (dependabot does this). + echo "release=false" >> "$GITHUB_OUTPUT" + echo "${tag} is already released from another commit; bump the version in Cargo.toml to release." >> "$GITHUB_STEP_SUMMARY" + exit 0 fi + # A tag on this commit means a re-run of a failed release, which continues. + echo "release=true" >> "$GITHUB_OUTPUT" + echo "Releasing ${tag}" >> "$GITHUB_STEP_SUMMARY" - name: Run tests + if: steps.version.outputs.release == 'true' run: cargo test --locked + # Pushed seconds after the merge, while main still matches this commit. + - name: Push the release tag + if: steps.version.outputs.release == 'true' + env: + TAG: ${{ steps.version.outputs.tag }} + run: | + if ! git rev-parse --verify --quiet "refs/tags/${TAG}" >/dev/null; then + git tag "$TAG" "$GITHUB_SHA" + git push origin "refs/tags/${TAG}" + fi + build: name: Build ${{ matrix.target }} needs: validate + if: needs.validate.outputs.release == 'true' strategy: fail-fast: false matrix: @@ -65,6 +88,7 @@ jobs: runs-on: ${{ matrix.runner }} env: TARGET: ${{ matrix.target }} + TAG: ${{ needs.validate.outputs.tag }} steps: - name: Check out source uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -113,11 +137,12 @@ jobs: release: name: Publish GitHub Release - needs: build + needs: [validate, build] runs-on: ubuntu-latest permissions: contents: write env: + TAG: ${{ needs.validate.outputs.tag }} GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} steps: diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index a1dbd97..be20e81 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -2,8 +2,6 @@ name: Security and quality on: pull_request: - push: - branches: [main] schedule: # Weekly, so advisories published after a merge still surface. - cron: "31 9 * * 1" diff --git a/README.md b/README.md index 05c2dfb..33a1d15 100644 --- a/README.md +++ b/README.md @@ -35,19 +35,14 @@ For local development from a checkout, use `cargo install --path .`. ### Releases -Pushing a version tag builds release archives for Linux x86_64, macOS Intel, -macOS Apple Silicon, and Windows x86_64, then publishes them with SHA-256 -checksums to a GitHub Release. The tag must match the package version in -`Cargo.toml`. - -```bash -# Cargo.toml version = "0.1.0" -git tag -a v0.1.0 -m "rush v0.1.0" -git push origin v0.1.0 -``` - -To retry an existing tag without moving it, run -`gh workflow run release.yml --ref main -f tag=v0.1.0`. +To release, bump `version` in `Cargo.toml` (and `Cargo.lock`, with +`cargo update -p rush-cli --offline`) in a pull request. Merging it to `main` +tags `v`, builds archives for Linux x86_64, macOS Intel, macOS Apple +Silicon, and Windows x86_64, and publishes them with SHA-256 checksums to a +GitHub Release. A `Cargo.toml` change that keeps a released version publishes +nothing. + +To retry a release that failed, run `gh workflow run release.yml --ref main`. ## Authentication