name: Test
on:
  push:
    branches: ["main"]
    paths-ignore:
      - "**.md"
  pull_request:
    branches: ["main"]
    types: [opened, synchronize]
    paths-ignore:
      - "**.md"

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          # without this it will override our rust flags
          rustflags: ""
          components: rustfmt, clippy

      - name: Install Solc
        uses: ./.github/actions/get-solc

      - name: Download LLVM
        uses: ./.github/actions/get-llvm
        with:
          target: x86_64-unknown-linux-gnu

      - name: Set LLVM Environment Variables
        run: |
          echo "LLVM_SYS_181_PREFIX=$(pwd)/llvm-x86_64-unknown-linux-gnu" >> $GITHUB_ENV

      - name: Install Geth
        run: |
          sudo add-apt-repository -y ppa:ethereum/ethereum
          sudo apt update
          sudo apt install -y ethereum

      - name: Machete
        uses: bnjbvr/cargo-machete@v0.7.1

      - name: Format
        run: make format

      - name: Clippy
        run: make clippy

      - name: Test cargo workspace
        run: make test-workspace

      - name: Test docs
        run: make doc
