Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>`, 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

Expand Down
Loading