CI #237
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # yaml-language-server: $schema=https://www.schemastore.org/github-workflow.json | |
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| schedule: | |
| # Nightly at midnight UTC (for coverage) | |
| - cron: "0 0 * * *" | |
| # Cancel in-progress runs when new commits are pushed | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| # Default to read-only permissions | |
| permissions: | |
| contents: read | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| # Check code formatting | |
| fmt: | |
| name: Formatting | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Install Rust nightly toolchain | |
| uses: dtolnay/rust-toolchain@881ba7bf39a41cda34ac9e123fb41b44ed08232f # nightly | |
| with: | |
| components: rustfmt | |
| - name: Check formatting | |
| run: cargo +nightly fmt --all -- --check | |
| # Run Clippy for linting | |
| clippy: | |
| name: Clippy | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@881ba7bf39a41cda34ac9e123fb41b44ed08232f # stable | |
| with: | |
| components: clippy | |
| - name: Cache Rust dependencies | |
| uses: step-security/rust-cache@f8fba7098297c8c53a7c9a30575ec2ad4ad85056 # v2.8.2 | |
| with: | |
| shared-key: clippy | |
| - name: Run clippy (default features) | |
| run: cargo clippy --all-targets -- -D warnings | |
| - name: Run clippy (all features) | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Run clippy (no default features) | |
| run: cargo clippy --all-targets --no-default-features -- -D warnings | |
| # Check MSRV (Minimum Supported Rust Version) | |
| msrv: | |
| name: MSRV (${{ matrix.msrv }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| msrv: ["1.92"] | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Install Rust ${{ matrix.msrv }} | |
| uses: dtolnay/rust-toolchain@881ba7bf39a41cda34ac9e123fb41b44ed08232f # master | |
| with: | |
| toolchain: ${{ matrix.msrv }} | |
| - name: Cache Rust dependencies | |
| uses: step-security/rust-cache@f8fba7098297c8c53a7c9a30575ec2ad4ad85056 # v2.8.2 | |
| with: | |
| shared-key: msrv-${{ matrix.msrv }} | |
| - name: Check compilation | |
| run: cargo check --all-features | |
| # Run tests on multiple platforms | |
| test: | |
| name: Test (${{ matrix.os }}) | |
| needs: [fmt, clippy] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, macos-latest, windows-latest] | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@881ba7bf39a41cda34ac9e123fb41b44ed08232f # stable | |
| - name: Cache Rust dependencies | |
| uses: step-security/rust-cache@f8fba7098297c8c53a7c9a30575ec2ad4ad85056 # v2.8.2 | |
| with: | |
| shared-key: test-${{ matrix.os }} | |
| - name: Run unit tests (default features) | |
| run: cargo test --lib | |
| - name: Run unit tests (all features) | |
| run: cargo test --lib --all-features | |
| - name: Run doc tests | |
| run: cargo test --doc --all-features | |
| # Code coverage (nightly only to reduce CI costs) | |
| coverage: | |
| name: Code Coverage | |
| needs: test | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' | |
| continue-on-error: true | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@881ba7bf39a41cda34ac9e123fb41b44ed08232f # stable | |
| with: | |
| components: llvm-tools-preview | |
| - name: Install cargo-llvm-cov | |
| uses: taiki-e/install-action@3522286d40783523f9c7880e33f785905b4c20d0 # v2.66.1 | |
| with: | |
| tool: cargo-llvm-cov | |
| - name: Cache Rust dependencies | |
| uses: step-security/rust-cache@f8fba7098297c8c53a7c9a30575ec2ad4ad85056 # v2.8.2 | |
| with: | |
| shared-key: coverage | |
| - name: Generate coverage | |
| run: | | |
| cargo llvm-cov --lib \ | |
| --codecov \ | |
| --output-path codecov.json | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 | |
| with: | |
| files: ./codecov.json | |
| fail_ci_if_error: false | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| # Build documentation | |
| docs: | |
| name: Documentation | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout code | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Install Rust nightly toolchain | |
| uses: dtolnay/rust-toolchain@881ba7bf39a41cda34ac9e123fb41b44ed08232f # nightly | |
| - name: Cache Rust dependencies | |
| uses: step-security/rust-cache@f8fba7098297c8c53a7c9a30575ec2ad4ad85056 # v2.8.2 | |
| with: | |
| shared-key: docs | |
| - name: Build documentation | |
| env: | |
| RUSTDOCFLAGS: -D warnings --cfg docsrs | |
| run: cargo +nightly doc --no-deps --all-features | |
| # Overall status check | |
| ci-success: | |
| name: CI Success | |
| needs: [fmt, clippy, msrv, test, coverage, docs] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Harden the runner (Audit all outbound calls) | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Check all jobs | |
| env: | |
| FMT_RESULT: ${{ needs.fmt.result }} | |
| CLIPPY_RESULT: ${{ needs.clippy.result }} | |
| MSRV_RESULT: ${{ needs.msrv.result }} | |
| TEST_RESULT: ${{ needs.test.result }} | |
| DOCS_RESULT: ${{ needs.docs.result }} | |
| COVERAGE_RESULT: ${{ needs.coverage.result }} | |
| run: | | |
| results="$FMT_RESULT $CLIPPY_RESULT $MSRV_RESULT $TEST_RESULT $DOCS_RESULT" | |
| for result in $results; do | |
| if [[ "$result" != "success" && "$result" != "skipped" ]]; then | |
| echo "One or more jobs failed" | |
| exit 1 | |
| fi | |
| done | |
| # Coverage is optional | |
| if [[ "$COVERAGE_RESULT" == "failure" ]]; then | |
| echo "Coverage failed (non-blocking)" | |
| fi | |
| echo "All required checks passed!" |