diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..93130aa --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,85 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + +jobs: + quality: + name: Format, lint, document, and package + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v7 + + - name: Install stable Rust with quality components + run: rustup toolchain install stable --profile minimal --component rustfmt,clippy --no-self-update + + - name: Check formatting + run: cargo +stable fmt --all -- --check + + - name: Lint every target and feature + run: cargo +stable clippy --workspace --all-targets --all-features --locked -- -D warnings + + - name: Build API documentation with warnings denied + env: + RUSTDOCFLAGS: -D warnings + run: cargo +stable doc --workspace --all-features --no-deps --locked + + - name: Verify the publishable crate archive + run: cargo +stable package --locked + + test: + name: Test on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + steps: + - uses: actions/checkout@v7 + + - name: Install stable Rust + run: rustup toolchain install stable --profile minimal --no-self-update + + - name: Run the complete test suite + run: cargo +stable test --workspace --all-features --locked + + architecture: + name: Dogfood the public architecture API + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v7 + + - name: Install stable Rust + run: rustup toolchain install stable --profile minimal --no-self-update + + - name: Check ArchUnitRust with ArchUnitRust + run: cargo +stable test --test architecture --all-features --locked + + msrv: + name: Build on Rust 1.85.0 + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v7 + + - name: Install the minimum supported Rust toolchain + run: rustup toolchain install 1.85.0 --profile minimal --no-self-update + + - name: Check every target and feature on the MSRV + run: cargo +1.85.0 check --workspace --all-targets --all-features --locked diff --git a/README.md b/README.md index ded515f..35ef175 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # ArchUnitRust +[![CI](https://github.com/LukasNiessen/ArchUnitRust/actions/workflows/ci.yml/badge.svg)](https://github.com/LukasNiessen/ArchUnitRust/actions/workflows/ci.yml) +[![Documentation](https://github.com/LukasNiessen/ArchUnitRust/actions/workflows/pages.yml/badge.svg)](https://github.com/LukasNiessen/ArchUnitRust/actions/workflows/pages.yml) + Architecture tests for Cargo projects, expressed as ordinary Rust tests. ArchUnitRust is part of **ArchUnitEverything** — one architecture-testing library per language. @@ -141,7 +144,6 @@ The sections after this guide are the detailed reference for the implemented sur - crates.io publication is tracked by [#44](https://github.com/LukasNiessen/ArchUnitRust/issues/44), so installation currently uses the Git repository; -- repository CI is tracked by [#43](https://github.com/LukasNiessen/ArchUnitRust/issues/43); - extraction is syntax-based: it does not expand macros or inspect build-script-generated source, evaluates `cfg` branches as a conservative union, and exposes files rather than Rust items as dependency nodes. diff --git a/docs/PORTING_PLAN.md b/docs/PORTING_PLAN.md index 161da16..f012e42 100644 --- a/docs/PORTING_PLAN.md +++ b/docs/PORTING_PLAN.md @@ -288,7 +288,7 @@ preserve the small conventional commits made on the branch. | Metrics | #32-#37 | Rust-defined counts, cohesion, coupling, custom metrics, and HTML export work | | Cross-cutting | #39 | Opt-in deterministic logging is covered | | Self-hosting | #40 | ArchUnitRust enforces its own module rules | -| Adoption | #41-#43 | README and the source-checked rustdoc/GitHub Pages site are live; the full CI matrix remains | +| Adoption | #41-#43 | README, source-checked rustdoc/GitHub Pages, and the full CI matrix are live | | Release | #44 | A verified package is published and install instructions are tested | Issue #38 stays open until every selector family has exclusion coverage, even though the matching diff --git a/docs/adr/0024-split-ci-by-evidence-and-supported-host.md b/docs/adr/0024-split-ci-by-evidence-and-supported-host.md new file mode 100644 index 0000000..1374aae --- /dev/null +++ b/docs/adr/0024-split-ci-by-evidence-and-supported-host.md @@ -0,0 +1,63 @@ +# ADR 0024: Split CI by evidence and supported host + +**Status:** accepted + +## Context + +ArchUnitRust needs continuous evidence for more than whether the library compiles on one machine. +Its public contract includes ordinary Rust tests, cross-platform path handling, a declared minimum +Rust version, warning-free documentation, a publishable crate archive, and architecture rules that +exercise the library against its own production sources. + +One opaque job would make failures harder to classify. Running only the complete suite would also +leave the self-hosting promise hidden among hundreds of tests. The Go, .NET, and Ruby ports provide +direction for always-on repository checks, but Rust's toolchains, Clippy, rustdoc, Cargo packaging, +and host-specific behavior require Rust-native gates. + +## Decision + +Run `.github/workflows/ci.yml` for every push, every pull request, and manual dispatch with read-only +repository contents permission. Cancel an older run for the same workflow and ref when a newer +commit supersedes it. + +Expose four independent jobs: + +1. On stable Linux, check formatting, deny every Clippy warning across all targets and features, + deny rustdoc warnings, and build the crate package. +2. On stable Linux, Windows, and macOS, run the complete workspace test suite with all features. +3. On stable Linux, run `tests/architecture.rs` separately as the visible dogfooding gate, even + though the complete suite also includes it. +4. On Linux with Rust 1.85.0, check all workspace targets and features to enforce the declared MSRV. + +Every Cargo command uses `Cargo.lock`. Toolchains are installed with rustup's minimal profile, and +the quality components are requested only by the job that needs them. The first workflow uses no +dependency cache or third-party Rust setup action; the official runner tool cache and Cargo's own +incremental behavior are sufficient until run data justifies more moving parts. + +## Consequences + +- A PR presents formatting, lint, documentation, packaging, host portability, self-architecture, + and MSRV failures as distinct review signals. +- Path and process assumptions are exercised on all three primary GitHub-hosted operating systems. +- The architecture test intentionally runs twice on Linux. The small cost buys a named required + signal that cannot disappear silently inside a general test command. +- Stable verifies current compiler behavior while Rust 1.85.0 protects the compatibility promise. +- Adding a cache later requires an explicit decision about action trust, cache keys, and observed + workflow cost rather than becoming an unexamined default. + +## Alternatives considered + +### Use one Linux job + +Rejected. It is quick but cannot validate Windows and macOS path semantics, and it mixes unrelated +failure modes into a long serial log. + +### Run only the stable toolchain + +Rejected. A stable build can start accepting syntax or dependency versions newer than the declared +MSRV without warning. + +### Rely on the complete test suite for dogfooding + +Rejected. The tests would execute, but the repository's defining self-architecture guarantee would +not be independently discoverable or enforceable in branch protection. diff --git a/docs/adr/README.md b/docs/adr/README.md index 2d3e0a6..db2e335 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -27,3 +27,4 @@ rewriting history after released behavior depends on it. - [0021: Keep logging explicit and scoped to a check](0021-keep-logging-explicit-and-scoped-to-a-check.md) - [0022: Enforce a Rust-aware self-architecture](0022-enforce-rust-aware-self-architecture.md) - [0023: Publish a source-checked guide beside rustdoc](0023-publish-a-source-checked-guide-beside-rustdoc.md) +- [0024: Split CI by evidence and supported host](0024-split-ci-by-evidence-and-supported-host.md) diff --git a/tests/ci_workflow.rs b/tests/ci_workflow.rs new file mode 100644 index 0000000..80ea6b8 --- /dev/null +++ b/tests/ci_workflow.rs @@ -0,0 +1,78 @@ +use std::fs; + +const WORKFLOW_PATH: &str = ".github/workflows/ci.yml"; + +#[test] +fn workflow_runs_for_every_push_pull_request_and_manual_dispatch() { + let workflow = workflow(); + + assert!(workflow.starts_with("name: CI\n\non:\n")); + assert!(workflow.contains(" push:\n pull_request:\n workflow_dispatch:\n")); + assert!(workflow.contains("permissions:\n contents: read\n")); + assert!(workflow.contains("concurrency:\n")); + assert!(workflow.contains(" cancel-in-progress: true\n")); +} + +#[test] +fn stable_quality_job_enforces_every_static_gate() { + let workflow = workflow(); + let quality = job(&workflow, "quality", "test"); + + assert!(quality.contains("rustup toolchain install stable")); + assert!(quality.contains("--component rustfmt,clippy")); + assert!(quality.contains("cargo +stable fmt --all -- --check")); + assert!(quality.contains( + "cargo +stable clippy --workspace --all-targets --all-features --locked -- -D warnings" + )); + assert!(quality.contains("RUSTDOCFLAGS: -D warnings")); + assert!(quality.contains("cargo +stable doc --workspace --all-features --no-deps --locked")); + assert!(quality.contains("cargo +stable package --locked")); +} + +#[test] +fn complete_suite_runs_on_all_three_supported_host_platforms() { + let workflow = workflow(); + let tests = job(&workflow, "test", "architecture"); + + for host in ["ubuntu-latest", "windows-latest", "macos-latest"] { + assert!(tests.contains(host), "test matrix is missing {host}"); + } + assert!(tests.contains("cargo +stable test --workspace --all-features --locked")); +} + +#[test] +fn dogfooding_and_msrv_are_independent_visible_gates() { + let workflow = workflow(); + let architecture = job(&workflow, "architecture", "msrv"); + let msrv = job(&workflow, "msrv", ""); + + assert!(architecture.contains("Dogfood the public architecture API")); + assert!( + architecture.contains("cargo +stable test --test architecture --all-features --locked") + ); + assert!(msrv.contains("rustup toolchain install 1.85.0 --profile minimal --no-self-update")); + assert!(msrv.contains("cargo +1.85.0 check --workspace --all-targets --all-features --locked")); +} + +fn workflow() -> String { + fs::read_to_string(WORKFLOW_PATH) + .expect("CI workflow should be readable") + .replace("\r\n", "\n") +} + +fn job<'a>(workflow: &'a str, name: &str, next: &str) -> &'a str { + let start_marker = format!(" {name}:\n"); + let start = workflow + .find(&start_marker) + .unwrap_or_else(|| panic!("missing {name} job")); + let rest = &workflow[start..]; + if next.is_empty() { + return rest; + } + + let end_marker = format!("\n {next}:\n"); + let end = rest + .find(&end_marker) + .unwrap_or_else(|| panic!("missing {next} job after {name}")); + &rest[..end] +}