name: build

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  linux:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: release
            build_type: Release
            enable_asan: OFF
          - name: asan
            build_type: RelWithDebInfo
            enable_asan: ON
    name: Linux ${{ matrix.name }}
    steps:
    - uses: actions/checkout@v4
    - name: Install dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y cmake ninja-build pkg-config libsodium-dev libmariadb-dev
    - name: Configure
      run: |
        cmake -S . -B build-${{ matrix.name }} -G Ninja \
          -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
          -DENABLE_ASAN=${{ matrix.enable_asan }}
    - name: Build
      run: cmake --build build-${{ matrix.name }} --parallel
    - name: Smoke tests
      run: ctest --test-dir build-${{ matrix.name }} --output-on-failure

  freebsd:
    runs-on: ubuntu-latest
    name: FreeBSD build
    steps:
    - uses: actions/checkout@v4
    - name: FreeBSD job
      id: test
      uses: vmactions/freebsd-vm@v1
      with:
        usesh: true
        sync: sshfs
        prepare: |
          pkg install -y git cmake gmake
        run: |
          mkdir build
          cd build
          cmake ..
          gmake all -j6
          ctest --output-on-failure
    - name: Collect outputs
      run: |
        mkdir _output
        cp build/bin/* _output
    - name: Upload
      uses: actions/upload-artifact@v4
      with:
        name: output_bsd
        path: _output
