name: Test and clippy common crates

on:
  push:
    branches:
      - master
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs: 
  test:
    name: Test and clippy crate ${{ matrix.crate }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - crate: build-utils
            run_test: true
          - crate: test-utils
            run_test: true
          - crate: zkvm-interface
            run_test: true
          - crate: ere-dockerized
            run_test: false # They are run in per-zkVM workflows
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2

      - name: Run cargo clippy
        run: cargo clippy --all-targets --package ${{ matrix.crate }} -- -D warnings

      - name: Run cargo test on documentation
        run: cargo test --doc --package ${{ matrix.crate }}

      - name: Run cargo test
        if: ${{ matrix.run_test }} 
        run: cargo test --release --package ${{ matrix.crate }}
