name: CI

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

env:
  CARGO_TERM_COLOR: always

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

      - name: Install cargo-llvm-cov
        run: cargo install cargo-llvm-cov --version 0.6.21
      - name: Install cargo-audit
        run: cargo install cargo-audit
      - name: Install rustfmt and clippy
        run: rustup component add --toolchain nightly-2025-10-12-x86_64-unknown-linux-gnu rustfmt clippy
      - name: pre-commit
        uses: j178/prek-action@v1
      - name: Install cargo-llvm-cov
        run: cargo install cargo-llvm-cov
      - name: Test Build
        env:
          RUSTFLAGS: "-C target-feature=+crt-static"
        run: cargo build
      - name: Run tests with coverage
        run: cargo llvm-cov --doctests --verbose --lcov --output-path lcov.info
      # TODO codecov
