name: check

on:
  pull_request:
    branches: [master]

jobs:
  format:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: check format
        uses: jidicula/clang-format-action@v4.11.0
        with:
          check-path: 'src'
          exclude-regex: 'argparse.h'

  linux:
    runs-on: ubuntu-latest
    steps:
    - name: checkout
      uses: actions/checkout@v4
    - name: build
      run: docker build .

  macos:
    runs-on: macos-latest
    steps:
    - name: depends
      run: brew update && brew install fmt poco spdlog
    - name: checkout
      uses: actions/checkout@v4
    - name: build
      run: |
        if [ "$RUNNER_ARCH" == "ARM64" ]; then
          export CPATH=/opt/homebrew/include
          export LIBRARY_PATH=/opt/homebrew/lib
        else
          export CPATH=/usr/local/include
          export LIBRARY_PATH=/usr/local/lib
        fi
        cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
        cmake --build build

  windows:
    runs-on: windows-latest
    steps:
    - name: depends
      uses: msys2/setup-msys2@v2
      with:
        msystem: MINGW64
        update: true
        install: >-
          mingw-w64-x86_64-cmake
          mingw-w64-x86_64-ninja
          mingw-w64-x86_64-gcc
          mingw-w64-x86_64-spdlog
          mingw-w64-x86_64-poco
    - name: checkout
      uses: actions/checkout@v4
    - name: cache
      uses: actions/cache@v4
      with:
        path: build
        key: ${{ hashFiles('CMakeLists.txt') }}
    - name: build
      shell: msys2 {0}
      run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo && cmake --build build
