name: CI

on:
  push:
    branches: [ "main" ]

env:
  # Bump when cache strategy changes to force refresh
  CACHE_VERSION: v4
  RUST_TOOLCHAIN: nightly-2026-02-26

jobs:
  test:
    name: Test Suite
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Cache
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-test-${{ env.CACHE_VERSION }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-test-${{ env.CACHE_VERSION }}-

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}
          components: rustfmt, clippy

      - name: Print useful env versions
        run: |
          rustup --version
          cargo --version
          rustc --version
          rustfmt --version
          cargo clippy --version

      - name: Setup justfile
        uses: extractions/setup-just@v4

      - name: Check all
        run: just check-all

  build:
    name: Build Check
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Cache
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-build-${{ env.CACHE_VERSION }}-${{ hashFiles('**/Cargo.lock', 'rust-toolchain.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-build-${{ env.CACHE_VERSION }}-

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}
          components: rustfmt, clippy

      - name: Print useful env versions
        run: |
          rustup --version
          cargo --version
          rustc --version
          rustfmt --version
          cargo clippy --version

      - name: Setup justfile
        uses: extractions/setup-just@v4

      - name: Build checks
        run: just build-release
