name: Rust Next

on:
  schedule:
    - cron: "3 3 3 * *"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  test:
    name: Test (${{ matrix.name }} - ${{ matrix.rust }})
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: stable
            os: ubuntu-latest
            rust: stable
          - name: linux-beta
            os: ubuntu-latest
            rust: beta
          - name: windows-beta
            os: windows-latest
            rust: beta
          - name: mac-beta
            os: macos-latest
            rust: beta
          - name: nightly
            os: ubuntu-latest
            rust: nightly
    continue-on-error: ${{ matrix.rust != 'stable' }}
    runs-on: ${{ matrix.os }}
    timeout-minutes: 30
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: next-${{ matrix.name }}

      - name: Strip path dependencies
        uses: ./.github/actions/strip-path-deps

      - name: Build
        run: cargo build --workspace --all-targets

      - name: Test
        run: cargo test --workspace

  rustfmt:
    name: Format (${{ matrix.rust }})
    strategy:
      fail-fast: false
      matrix:
        rust: [stable, beta]
    continue-on-error: ${{ matrix.rust != 'stable' }}
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          components: rustfmt

      - name: Check formatting
        run: cargo fmt --all -- --check

  clippy:
    name: Clippy (${{ matrix.rust }})
    strategy:
      fail-fast: false
      matrix:
        rust: [stable, beta]
    continue-on-error: ${{ matrix.rust != 'stable' }}
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          components: clippy

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: clippy-${{ matrix.rust }}

      - name: Strip path dependencies
        uses: ./.github/actions/strip-path-deps

      - name: Lint
        run: cargo clippy --workspace --all-targets -- -D warnings -A deprecated
