name: Test & Lint
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
RUST_VERSION: "1.96.1"
on:
pull_request:
push:
paths:
- "src/**"
- "tests/**"
- "Cargo.toml"
- "Cargo.lock"
- "deny.toml"
- ".github/workflows/test.yml"
branches:
- "**"
tags:
- "*.*.*"
schedule:
- cron: "0 7 * * 1"
jobs:
security:
name: Security audit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Rustup
run: |
rustup default ${{ env.RUST_VERSION }}
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
shared-key: security
- name: cargo-audit (RustSec advisories)
uses: rustsec/audit-check@v2.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: cargo-deny (advisories + licenses + sources + bans)
uses: EmbarkStudios/cargo-deny-action@v2
with:
command: check
arguments: --all-features
linting:
name: Linting
runs-on: ubuntu-latest
needs: security
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Rustup
run: |
rustup default ${{ env.RUST_VERSION }}
rustup component add clippy rustfmt
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
shared-key: linting
- name: Rustfmt
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
test:
name: Test (${{ matrix.target }})
needs: linting
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Rustup
run: |
rustup update
rustup default ${{ env.RUST_VERSION }}
rustup target add ${{ matrix.target }}
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
shared-key: test-${{ matrix.target }}
key: ${{ matrix.target }}
- name: cargo test
run: cargo test --locked
publish-crate:
name: Publish crate to crates.io
if: startsWith(github.ref, 'refs/tags/')
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Rustup
run: |
rustup update
rustup default ${{ env.RUST_VERSION }}
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
shared-key: publish
- name: Publish to crates.io
run: |
cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }}
cargo publish --locked