name: Fmt, Clippy, Test

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

jobs:
  test:
    name: test
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        node_index: [clippy, fmt, test]

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

      - uses: dtolnay/rust-toolchain@1.89.0
        with:
          components: "rustfmt, clippy"

      - name: Run cargo fmt
        if: ${{ matrix.node_index == 'fmt' }}
        run: cargo fmt --all -- --check

      - name: Run cargo clippy
        if: ${{ matrix.node_index == 'clippy' }}
        run: cargo clippy -- -D warnings

      - name: Run cargo test
        if: ${{ matrix.node_index == 'test' }}
        run: cargo test