shared-workflows/.github/workflows/test-rust-project.yml

162 lines
4.6 KiB
YAML

name: Test Rust project
on:
workflow_call:
inputs:
apt_packages:
required: false
type: string
msrv:
required: false
type: string
default: "1.57.0"
secrets:
github-token:
required: false
env:
RUSTFLAGS: '-Dwarnings'
# disable incremental compilation.
#
# incremental compilation is useful as part of an edit-build-test-edit cycle,
# as it lets the compiler avoid recompiling code that hasn't changed. however,
# on CI, we're not making small edits; we're almost always building the entire
# project from scratch. thus, incremental compilation on CI actually
# introduces *additional* overhead to support making future builds
# faster...but no future builds will ever occur in any given CI environment.
#
# see https://matklad.github.io/2021/09/04/fast-rust-builds.html#ci-workflow
# for details.
CARGO_INCREMENTAL: 0
# allow more retries for network requests in cargo (downloading crates) and
# rustup (installing toolchains). this should help to reduce flaky CI failures
# from transient network timeouts or other issues.
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
# don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
jobs:
check-msrv:
name: Check MSRV
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os:
- macos-11
- ubuntu-20.04
- windows-2022
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- name: Install Rust
uses: dtolnay/rust-toolchain@1482605bfc5719782e1267fd0c0cc350fe7646b8 # v1
with:
toolchain: ${{ inputs.msrv }}
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
key: cargo-cache-${{ hashFiles('Cargo.lock', 'Cargo.toml') }}-${{ matrix.os }}
- name: Install cargo-hack
uses: baptiste0928/cargo-install@9f6037ed331dcf7da101461a20656273fa72abf0 # v3
with:
crate: cargo-hack
- name: Test compilation
run: cargo hack check --each-feature
cargo-deny:
name: Run cargo-deny
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- bans licenses sources
# Prevent sudden announcement of a new advisory from failing ci:
continue-on-error: ${{ matrix.checks == 'advisories' }}
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: EmbarkStudios/cargo-deny-action@3f4a782664881cf5725d0ffd23969fcce89fd868 # v1
with:
command: check ${{ matrix.checks }}
test:
name: Run checks
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- macos-11
- ubuntu-20.04
- windows-2022
rust:
- beta
- nightly
- stable
steps:
- name: Checkout repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
- uses: rui314/setup-mold@6bebc01caac32fb5251ee64f60cea0322d0e6574 # v1
if: runner.os == 'Linux'
with:
make-default: true
- name: Install Rust
uses: dtolnay/rust-toolchain@1482605bfc5719782e1267fd0c0cc350fe7646b8 # v1
with:
toolchain: ${{ matrix.rust }}
components: clippy, rustfmt
- name: Install cargo-nextest
uses: baptiste0928/cargo-install@9f6037ed331dcf7da101461a20656273fa72abf0 # v3
with:
crate: cargo-nextest
- name: Install cargo-hack
uses: baptiste0928/cargo-install@9f6037ed331dcf7da101461a20656273fa72abf0 # v3
with:
crate: cargo-hack
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
key: cargo-cache-${{ hashFiles('Cargo.lock', 'Cargo.toml') }}-${{ matrix.os }}-${{ matrix.rust }}
- name: Install required packages (Linux)
if: ${{ inputs.apt_packages != '' && runner.os == 'Linux' }}
shell: bash
env:
PACKAGES: ${{ inputs.apt_packages }}
run: |
sudo apt-get update
sudo apt-get install -y ${PACKAGES}
- name: Check formatting
shell: bash
run: cargo fmt -- --check
- name: Setup Embark Studios lint rules
shell: bash
run: |
mkdir .cargo
curl -sL https://raw.githubusercontent.com/EmbarkStudios/rust-ecosystem/main/lints.toml > .cargo/config.toml
- name: Clippy
shell: bash
run: cargo clippy
- name: Test compilation
run: cargo hack check --each-feature
- name: Run tests
shell: bash
run: cargo nextest run --all-features