Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 18 additions & 49 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,48 @@
# SPDX-License-Identifier: PMPL-1.0-or-later
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
#
# rust-ci.yml — Cargo build, test, clippy, and fmt for Rust projects.
# Only runs if Cargo.toml exists in the repo root.
# Rust CI - cargo check + clippy + fmt + test on stable and MSRV
name: Rust CI

on:
pull_request:
branches: ['**']
push:
branches: [main, master]
branches:
- main

permissions:
contents: read

jobs:
check:
name: Cargo check + clippy + fmt
name: cargo check (stable)
runs-on: ubuntu-latest
if: hashFiles('Cargo.toml') != ''

steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # stable
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt

- name: Cache cargo registry and build
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2

- name: Cargo check
run: cargo check --all-targets 2>&1

- name: Cargo fmt
- uses: Swatinem/rust-cache@v2
- name: cargo fmt
run: cargo fmt --all -- --check

- name: Cargo clippy
- name: cargo clippy
run: cargo clippy --all-targets -- -D warnings

test:
name: Cargo test (${{ matrix.rust }})
name: cargo test (${{ matrix.rust }})
runs-on: ubuntu-latest
needs: check
if: hashFiles('Cargo.toml') != ''
strategy:
fail-fast: false
matrix:
# `1.85` matches Cargo.toml `rust-version` — the MSRV gate.
# `stable` keeps the lane honest against the latest stable.
rust: ['1.85', 'stable']

rust:
- "1.85"
- "stable"
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7 # pinned
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}

- name: Cache cargo registry and build
uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.rust }}

- name: Run tests
run: cargo test --all-targets

- name: Write summary
if: always()
run: |
echo "## Rust CI Results (${{ matrix.rust }})" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- **cargo check**: passed" >> "$GITHUB_STEP_SUMMARY"
echo "- **cargo test**: completed" >> "$GITHUB_STEP_SUMMARY"
- name: cargo test
run: cargo test --all-targets --no-fail-fast
Loading