name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
validate:
name: Validate release
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Checkout release tag
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Verify release tag
shell: bash
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
package_version="$(
python3 - <<'PY'
import tomllib
with open("Cargo.toml", "rb") as manifest:
package = tomllib.load(manifest)["package"]
if package.get("publish") is False:
raise SystemExit("Cargo.toml has publish = false")
print(package["version"])
PY
)"
expected_tag="v${package_version}"
if [[ "${RELEASE_TAG}" != "${expected_tag}" ]]; then
echo "Release tag ${RELEASE_TAG} does not match Cargo.toml version ${package_version}."
exit 1
fi
build:
name: Build ${{ matrix.target }}
needs: validate
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
- os: windows-2025
target: x86_64-pc-windows-msvc
- os: macos-15-intel
target: x86_64-apple-darwin
- os: macos-15
target: aarch64-apple-darwin
steps:
- name: Checkout release tag
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Show Rust toolchain
run: rustup show
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: Test
run: cargo test --workspace --all-targets --all-features --locked
- name: Build binaries
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package Unix binaries
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
rm -rf dist package
mkdir -p dist package
cp "target/${{ matrix.target }}/release/rustuse" package/
cp "target/${{ matrix.target }}/release/cargo-rustuse" package/
cp README.md package/
cp LICENSE-MIT package/
cp LICENSE-APACHE package/
tar -C package -czf \
"dist/rustuse-${{ github.ref_name }}-${{ matrix.target }}.tar.gz" \
.
- name: Package Windows binaries
if: runner.os == 'Windows'
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
Remove-Item -Recurse -Force dist, package -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Force dist | Out-Null
New-Item -ItemType Directory -Force package | Out-Null
Copy-Item "target/${{ matrix.target }}/release/rustuse.exe" package/
Copy-Item "target/${{ matrix.target }}/release/cargo-rustuse.exe" package/
Copy-Item README.md package/
Copy-Item LICENSE-MIT package/
Copy-Item LICENSE-APACHE package/
Compress-Archive `
-Path package/* `
-DestinationPath "dist/rustuse-${{ github.ref_name }}-${{ matrix.target }}.zip" `
-Force
- name: Upload packaged binary
uses: actions/upload-artifact@v6
with:
name: rustuse-${{ matrix.target }}
path: dist/*
if-no-files-found: error
release:
name: Publish GitHub Release
needs: build
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: write
steps:
- name: Checkout release tag
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Download packaged binaries
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Publish GitHub Release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
release_flags=(
--verify-tag
--generate-notes
--title "rustuse-cli ${GITHUB_REF_NAME}"
)
if [[ "${GITHUB_REF_NAME}" == *-* ]]; then
release_flags+=(--prerelease)
else
release_flags+=(--latest)
fi
gh release create \
"${GITHUB_REF_NAME}" \
dist/* \
"${release_flags[@]}"
publish-crate:
name: Publish to crates.io
needs: release
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: read
id-token: write
steps:
- name: Checkout release tag
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
persist-credentials: false
- name: Show Rust toolchain
run: rustup show
- name: Verify package
run: cargo publish --dry-run --locked
- name: Authenticate with crates.io
id: crates_io
uses: rust-lang/crates-io-auth-action@v1
- name: Publish to crates.io
run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ steps.crates_io.outputs.token }}