name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
verify:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6.0.2
- name: Cache cargo registry and target
uses: actions/cache@v5.0.4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install rustfmt and clippy
run: rustup component add rustfmt clippy
- name: Run tests
run: cargo test --verbose
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings
- name: Check formatting
run: cargo fmt --all --check
publish:
needs: verify
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
- name: Verify tag matches crate version
id: version
shell: bash
run: |
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
tag="${GITHUB_REF_NAME#v}"
test "$version" = "$tag"
echo "value=$version" >> "$GITHUB_OUTPUT"
- name: Package crate
run: cargo package
- name: Upload crate artifact
uses: actions/upload-artifact@v7.0.0
with:
name: is_sudo-${{ github.ref_name }}
path: target/package/is_sudo-${{ steps.version.outputs.value }}.crate
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked
- name: Create GitHub release
uses: softprops/action-gh-release@v2.6.1
with:
name: is_sudo ${{ github.ref_name }}
generate_release_notes: true
files: target/package/is_sudo-${{ steps.version.outputs.value }}.crate