name: Release
on:
push:
tags:
- "v*"
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
jobs:
publish:
name: Publish crate and GitHub release
runs-on: ubuntu-latest
environment: crates-io
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Verify tag matches Cargo.toml
run: |
crate_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "ghr-cli") | .version')"
tag_version="${GITHUB_REF_NAME#v}"
if [ "$crate_version" != "$tag_version" ]; then
echo "tag $GITHUB_REF_NAME does not match crate version $crate_version" >&2
exit 1
fi
- name: Check formatting
run: cargo fmt --all -- --check
- name: Check all targets
run: cargo check --locked --all-targets
- name: Clippy
run: cargo clippy --locked --all-targets -- -D warnings
- name: Test
run: cargo test --locked
- name: Package
run: cargo package --locked
- name: Publish to crates.io
run: cargo publish --locked --token "$CARGO_REGISTRY_TOKEN"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub release
run: |
gh release create "$GITHUB_REF_NAME" \
--verify-tag \
--title "ghr $GITHUB_REF_NAME" \
--notes "Published to crates.io: https://crates.io/crates/ghr-cli/${GITHUB_REF_NAME#v}"
env:
GH_TOKEN: ${{ github.token }}