|
| 1 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +# |
| 4 | +# rust-ci.yml — Cargo build, test, clippy, and fmt for Rust projects. |
| 5 | +# Only runs if Cargo.toml exists in the repo root. |
| 6 | +name: Rust CI |
| 7 | + |
| 8 | +on: |
| 9 | + pull_request: |
| 10 | + branches: ['**'] |
| 11 | + push: |
| 12 | + branches: [main, master] |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + check: |
| 19 | + name: Cargo check + clippy + fmt |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: hashFiles('Cargo.toml') != '' |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 26 | + |
| 27 | + - name: Install Rust toolchain |
| 28 | + uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable |
| 29 | + with: |
| 30 | + components: clippy, rustfmt |
| 31 | + |
| 32 | + - name: Cache cargo registry and build |
| 33 | + uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2 |
| 34 | + |
| 35 | + - name: Cargo check |
| 36 | + run: cargo check --all-targets 2>&1 |
| 37 | + |
| 38 | + - name: Cargo fmt |
| 39 | + run: cargo fmt --all -- --check |
| 40 | + |
| 41 | + - name: Cargo clippy |
| 42 | + run: cargo clippy --all-targets -- -D warnings |
| 43 | + |
| 44 | + test: |
| 45 | + name: Cargo test |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: check |
| 48 | + if: hashFiles('Cargo.toml') != '' |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Checkout repository |
| 52 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 53 | + |
| 54 | + - name: Install Rust toolchain |
| 55 | + uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable |
| 56 | + |
| 57 | + - name: Cache cargo registry and build |
| 58 | + uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2 |
| 59 | + |
| 60 | + - name: Run tests |
| 61 | + run: cargo test --all-targets |
| 62 | + |
| 63 | + - name: Write summary |
| 64 | + if: always() |
| 65 | + run: | |
| 66 | + echo "## Rust CI Results" >> "$GITHUB_STEP_SUMMARY" |
| 67 | + echo "" >> "$GITHUB_STEP_SUMMARY" |
| 68 | + echo "- **cargo check**: passed" >> "$GITHUB_STEP_SUMMARY" |
| 69 | + echo "- **cargo test**: completed" >> "$GITHUB_STEP_SUMMARY" |
0 commit comments