name: Continuous Integration
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"
RUSTDOCFLAGS: "-Dwarnings"
AUTO_FORMAT: ${{ vars.AUTO_FORMAT }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo
~/.rustup
target
key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Add Rust to PATH
run: |
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
echo "$HOME/.rustup/bin" >> $GITHUB_PATH
- name: Install Rust nightly
run: |
if [ -d "$HOME/.cargo/" ] && [ -d "$HOME/.rustup/" ] && [ -f "$HOME/.cargo/bin/cargo-llvm-cov" ]; then
echo "Rust is already installed. Skipping installation."
rustup component add --toolchain nightly-x86_64-unknown-linux-gnu clippy rustfmt llvm-tools-preview
else
echo "Rust is not installed. Installing via rustup..."
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly
cargo install cargo-llvm-cov
fi
- name: Show rust version
run: rustc --version
- name: Format code
if: env.AUTO_FORMAT == 'true'
run: cargo +nightly fmt --all
- name: Check formatting
if: env.AUTO_FORMAT != 'true'
run: |
cargo +nightly fmt --all --check || {
echo "Formatting failed — please run 'cargo +nightly fmt --all' locally before pushing.";
exit 1;
}
- name: Clippy apply suggestions
if: env.AUTO_FORMAT == 'true'
run: RUSTFLAGS="-Dclippy::all" cargo +nightly clippy --all-targets --all-features --fix --allow-dirty -- -W clippy::pedantic -W clippy::nursery -W clippy::cargo -A clippy::cast-precision-loss
- name: Clippy
run: RUSTFLAGS="-Dclippy::all" cargo +nightly clippy --all-targets --all-features -- -W clippy::pedantic -W clippy::nursery -W clippy::cargo -A clippy::cast-precision-loss
- name: Test coverage
run: |
cargo +nightly llvm-cov clean --workspace;
cargo +nightly llvm-cov --no-report --workspace --all-features --all-targets;
cargo +nightly llvm-cov --no-report --workspace --all-features --doctests;
cargo +nightly llvm-cov report --fail-under-regions 40;
- name: Build documentation
run: cargo +nightly doc --no-deps;