name: Rust
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
paths-ignore:
- "README.md"
- "CONTRIBUTING.md"
merge_group:
types: [checks_requested]
env:
CARGO_TERM_COLOR: always
TARPAULIN_VERSION: 0.35.1
UDEPS_VERSION: 0.1.60
AUDIT_VERSION: 0.22.1
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
tests:
name: Cargo fmt,clippy,build,test,tarpaulin
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Cargo fmt
run: cargo fmt --all -- --check
- name: Cargo clippy
run: cargo clippy --all-targets -- -D warnings
- name: Cargo build
run: cargo build --verbose
- name: Cargo test
run: cargo test --verbose
- name: Install cargo-tarpaulin@${{ env.TARPAULIN_VERSION }}
uses: taiki-e/install-action@f8d25fb8a2df08dcd3cead89780d572767b8655f if: matrix.os == 'ubuntu-latest'
with:
tool: cargo-tarpaulin@${{ env.TARPAULIN_VERSION }}
- name: Cargo tarpaulin
if: matrix.os == 'ubuntu-latest'
run: cargo tarpaulin --verbose
audit:
runs-on: ubuntu-latest
name: Cargo udeps and audit
needs: tests
steps:
- uses: actions/checkout@v4
- name: Install cargo-udeps@${{ env.UDEPS_VERSION }}
uses: taiki-e/install-action@f8d25fb8a2df08dcd3cead89780d572767b8655f with:
tool: cargo-udeps@${{ env.UDEPS_VERSION }}
- name: Install cargo-audit@${{ env.AUDIT_VERSION }}
uses: taiki-e/install-action@f8d25fb8a2df08dcd3cead89780d572767b8655f with:
tool: cargo-audit@${{ env.AUDIT_VERSION }}
- name: Run cargo udeps
run: cargo +nightly udeps --verbose
- name: Run cargo audit
run: cargo audit
check-workflow-status:
name: Check Workflow Status
runs-on: ubuntu-latest
if: always()
needs:
- tests
- audit
steps:
- name: Check Workflow Status
run: |
exit_on_result() {
if [[ "$2" == "failure" || "$2" == "cancelled" ]]; then
echo "Job '$1' failed or was cancelled."
exit 1
fi
}
exit_on_result "linter" "${{ needs.linter.result }}"
exit_on_result "tests" "${{ needs.tests.result }}"
exit_on_result "audit" "${{ needs.audit.result }}"