name: Rust CI/Unit Tests
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
RUSTFLAGS: "-Dwarnings"
jobs:
pre_ci:
uses: dtolnay/.github/.github/workflows/pre_ci.yml@master
test:
name: ${{ matrix.os }}, Rust ${{matrix.rust}}
needs: pre_ci
if: needs.pre_ci.outputs.continue
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rust: [nightly, beta, stable, 1.85.0]
os: [ubuntu-latest, macos-latest, windows-latest]
timeout-minutes: 45
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt
- name: Enable type layout randomization
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
if: matrix.rust == 'nightly'
- name: Run tests (bless stderr on nightly)
shell: bash
run: |
if [ "${{ matrix.rust }}" = "nightly" ]; then
TRYBUILD=overwrite cargo test
else
cargo test
fi
- uses: actions/upload-artifact@v7
if: matrix.os == 'ubuntu-latest' && matrix.rust == 'nightly' && always()
with:
name: Cargo.lock
path: Cargo.lock
- name: Run cargo check with all features
run: cargo check --all-features
- name: Run cargo fmt
run: cargo fmt --all -- --check
coverage:
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-Cinstrument-coverage -Clink-dead-code -Coverflow-checks=off"
LLVM_PROFILE_FILE: "coverage/%p-%m.profraw"
steps:
- uses: actions/checkout@v6
- name: Set up Rust with coverage tools
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: llvm-tools-preview
- name: Install grcov
run: |
curl -LsSf https://github.com/mozilla/grcov/releases/download/v0.8.19/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar xj
sudo mv grcov /usr/local/bin/
- name: Run tests with coverage
run: |
cargo clean
cargo build --tests
cargo test
- name: Generate coverage report
run: |
mkdir -p coverage
grcov . \
--binary-path ./target/debug/ \
--source-dir . \
--output-type lcov \
--branch \
--ignore-not-existing \
--ignore "/*/.cargo/**" \
--ignore "target/**" \
--output-path coverage/lcov.info
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2.3.6
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
with:
path-to-lcov: coverage/lcov.info
doc:
name: Documentation
needs: pre_ci
if: needs.pre_ci.outputs.continue
runs-on: ubuntu-latest
timeout-minutes: 45
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
outdated:
name: Outdated
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
timeout-minutes: 45
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/install@cargo-outdated
- run: cargo outdated --workspace --exit-code 1