name: CI

on:
  push:
    paths:
      - ".github/workflows/ci.yaml"
      - ".config/nextest.toml"
      - "src/**"
      - "tests/**"
      - "Cargo.toml"
      - "Cargo.lock"
  pull_request: {}

env:
  RUSTFLAGS: -D warnings
  CARGO_TERM_COLOR: always
  TEST_STATS_DELAY: 5000

jobs:
  lint:
    name: Lint
    strategy:
      matrix:
        runner:
          - "ubuntu-22.04"
          - "ubuntu-24.04"
    runs-on: ${{ matrix.runner }}

    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Lint (clippy)
        run: cargo clippy

      - name: Lint (rustfmt)
        run: cargo fmt --all --check

  build:
    strategy:
      matrix:
        rabbitmq-series:
          - "4.0"
          - "4.1"
        rust-version:
          - stable
          - beta
        runner:
          - "ubuntu-22.04"
          - "ubuntu-24.04"
          # - "ubuntu-24.04-arm"
    runs-on: ${{ matrix.runner }}

    services:
      rabbitmq:
        image: rabbitmq:${{ matrix.rabbitmq-series }}-management
        ports:
          - 15672:15672
          - 5672:5672

    steps:
      - uses: actions/checkout@v6
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust-version }}

      - uses: taiki-e/install-action@nextest

      - name: Wait for node to start booting
        run: sleep 15

      - name: Configure broker
        run: RUST_HTTP_API_CLIENT_RABBITMQCTL=DOCKER:${{job.services.rabbitmq.id}} bin/ci/before_build.sh

      - name: Run tests
        run: RUST_BACKTRACE=1 NEXTEST_RETRIES=2 cargo nextest run --workspace --no-fail-fast --all-features