name: CI

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0
  CARGO_NET_RETRY: 10
  RUST_BACKTRACE: 1
  RUSTUP_MAX_RETRIES: 10
  RUSTFLAGS: "-D warnings"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
  tests:
    name: Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - uses: taiki-e/install-action@v2
        with:
          tool: just@1.40.0
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: 1.90.0
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2
        with:
          prefix-key: "v1"
          cache-workspace-crates: true
          cache-on-failure: true
          workspaces: |
            .
      - name: Compile
        run: just cargo-compile
      - name: Clippy
        run: just cargo-clippy-check
      - name: Rustfmt
        run: just cargo-fmt-check
      - name: Run tests
        run: just test
