name: Rust CI
on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
build-test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v5
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install Protocol Buffers compiler
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --locked --tests --all-targets --all-features -- -D warnings
- name: Install cargo-audit
uses: baptiste0928/cargo-install@v3
with:
crate: cargo-audit
- name: Run security audit
run: cargo audit
- name: Build
run: cargo build --verbose --all-features --locked
- name: Run tests
run: cargo test --verbose --all-features --locked
- name: Check documentation
run: cargo doc --no-deps --document-private-items --all-features --locked
release:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [build-test]
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout sources
uses: actions/checkout@v5
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install Protocol Buffers compiler
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --locked