name: CI

on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    container: gitea.tap-tap.win/taptap/fastsync-ci:v7
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: clang-format check
        run: find src/ tests/ -name '*.c' -o -name '*.h' | xargs clang-format --dry-run --Werror

      - name: cppcheck
        run: cppcheck --enable=warning,style,performance,portability --suppress=missingIncludeSystem --error-exitcode=1 --inline-suppr src/ tests/

  build-and-test:
    runs-on: ubuntu-latest
    container: gitea.tap-tap.win/taptap/fastsync-ci:v7
    needs: lint
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Configure
        run: cmake -B build -S . -DSTRICT_WARNINGS=ON

      - name: Build
        run: cmake --build build -j$(nproc)

      - name: Unit Tests
        run: ./build/tests

      - name: Integration Tests
        run: python3 -m pytest tests/ -v --tb=short

  sanitizers:
    runs-on: ubuntu-latest
    container: gitea.tap-tap.win/taptap/fastsync-ci:v7
    needs: lint
    strategy:
      matrix:
        sanitizer: [address]
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Configure
        run: cmake -B build-${{ matrix.sanitizer }} -S . -DSANITIZER=${{ matrix.sanitizer }}

      - name: Build
        run: cmake --build build-${{ matrix.sanitizer }} -j$(nproc)

      - name: Unit Tests
        run: ./build-${{ matrix.sanitizer }}/tests
