name: CI

on:
  push:
    branches: [ "main" ]

env:
  # Use nightly to support edition 2024 features
  RUST_VERSION: nightly

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

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

      - name: Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}

      - name: Install Rust nightly
        uses: dtolnay/rust-toolchain@nightly
        with:
          components: rustfmt, clippy

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

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

      - name: Run tests
        run: just test

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

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

      - name: Cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}

      - name: Install Rust nightly
        uses: dtolnay/rust-toolchain@nightly

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

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

      - name: Build checks
        run: just build-release

