drep-ai 3.1.5

A local commit gate: runs the linters your repo configures, and sends changed code to an LLM for review
Documentation
name: rust

on:
  push:
    branches: [main]
  pull_request:

env:
  CARGO_TERM_COLOR: always

permissions:
  contents: read

jobs:
  # homelab-1 has a dedicated repository-scoped validation runner, so separate Linux jobs would only
  # serialize while repeating checkout, cache and toolchain setup. Keep the
  # complete Linux gate in one allocation; macOS remains independent below.
  linux:
    # Preserve the required check name across the host move.
    name: validate (ai-1)
    if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
    runs-on: [self-hosted, linux, x64, homelab-1, drep-linux]
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

      - uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
        with:
          toolchain: stable
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
        with:
          # Its default save cleanup deletes every Cargo binary present when
          # the action starts. These runners own pinned publisher tools.
          cache-bin: false

      - name: Format
        run: cargo fmt --all --check

      # Lint levels come from [lints] in Cargo.toml, not from flags here.
      - name: Clippy
        run: cargo clippy --all-targets --all-features

      # Clippy does not run rustdoc's lints, and most modules are private, so only a private-items build sees a broken intra-doc link. [lints] denies its warnings too.
      - name: Rustdoc
        run: cargo doc --no-deps --all-features --document-private-items

      - name: Test
        run: cargo test --all-targets --all-features

      # If this breaks, the MSRV in Cargo.toml is wrong - do not paper over it
      # by bumping the toolchain here. It has moved once already: `ignore`
      # 0.4.30 raised the real floor to 1.88 while open-agent-sdk still asks
      # for 1.85, and declares no `rust-version`, so the first sign was a
      # compile error in a dependency.
      - uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
        with:
          toolchain: 1.88.0

      # No --all-targets: MSRV is a property of [dependencies]. Whether the dev
      # dependencies build on 1.88 has no consumer.
      - name: MSRV
        run: cargo +1.88.0 check

  test-macos:
    name: test (Mac mini)
    if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
    runs-on: [self-hosted, macos, arm64, drep-macos]
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

      - uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
        with:
          toolchain: stable
          components: clippy

      - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
        with:
          cache-bin: false

      - run: cargo test --all-targets --all-features

  # Exhaustive mutation is scheduled separately. A trusted main push or a pull request from this repository's own branches gets fast feedback on only the production code it changes, after both validation lanes pass. Forked pull requests never reach the self-hosted runner.
  mutants-diff:
    # Preserve the required check name across the host move.
    name: mutate diff (ai-1)
    needs: [linux, test-macos]
    if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
    runs-on: [self-hosted, linux, x64, homelab-1, drep-mutants]
    timeout-minutes: 120
    # Only a pull request's newest head matters, so a push to it cancels the run it supersedes. Every main push keeps its own run, since each mutates a different diff.
    concurrency:
      group: mutants-diff-${{ github.event.pull_request.number || github.sha }}
      cancel-in-progress: ${{ github.event_name == 'pull_request' }}
    # A pull request mutates its head commit, not GitHub's merge commit: cargo-mutants refuses a diff whose new side does not match the tree it mutates. A push has no pull_request object and falls back to its own before and after SHAs.
    env:
      DIFF_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
      DIFF_HEAD: ${{ github.event.pull_request.head.sha || github.sha }}
    steps:
      # cargo-mutants builds every mutant in its own scratch copy of the tree, which excludes target/, so an ordinary clean checkout loses nothing.
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ env.DIFF_HEAD }}
          fetch-depth: 0
          persist-credentials: false

      - uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
        with:
          toolchain: stable
          components: clippy

      - uses: taiki-e/install-action@f7e5d7c961414b23f5b25b2da9294395d08513ad # v2.87.26
        with:
          tool: cargo-mutants@27.1.0

      # Three dots diff from the merge base, so a pull request's diff holds only its own changes after its base branch moves on. An empty end would read as HEAD and yield an empty diff, which cargo-mutants passes.
      - name: Materialize diff
        shell: bash
        run: |
          set -euo pipefail
          : "${DIFF_BASE:?}" "${DIFF_HEAD:?}"
          git diff --no-ext-diff --unified=0 "$DIFF_BASE...$DIFF_HEAD" > "$RUNNER_TEMP/changes.diff"

      - run: ./scripts/mutants-run.sh --in-diff "$RUNNER_TEMP/changes.diff"