name: CI

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

env:
  CARGO_TERM_COLOR: always

jobs:
  actionlint:
    name: actionlint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false

      - uses: docker://rhysd/actionlint:latest
        with:
          args: -color

  build:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        # Run on latest and minimal supported rust versions.
        rust-version: ["stable", "1.92.0"]

    steps:
      - uses: actions/checkout@v7

      - name: Install Rust
        run: |
          echo "Installing Rust ${{ matrix.rust-version }}"
          rustup update --no-self-update ${{ matrix.rust-version  }}
          rustup default ${{ matrix.rust-version  }}

      - name: Rust Cache
        uses: Swatinem/rust-cache@v2.9.1

      - name: Check General
        run: cargo check --verbose

      - name: Check sqlite
        run: cargo check --no-default-features -F sqlite --verbose

      - name: Clippy
        if: ${{ matrix.rust-version == 'stable' }}
        run: cargo clippy --all-targets --all-features --verbose -- -D warnings

      - name: Format
        if: ${{ matrix.rust-version == 'stable' }}
        run: cargo fmt --all -- --check

      - name: Build
        if: ${{ matrix.rust-version == 'stable' }}
        run: cargo build --verbose

      - name: Run tests
        if: ${{ matrix.rust-version == 'stable' }}
        run: cargo test --verbose

  cffconvert:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false

      - uses: docker://citationcff/cffconvert:latest
        with:
          args: --validate
