name: CI

on:
  push:
  pull_request:

jobs:
  build-openbsd:
    runs-on: ubuntu-latest
    name: build • openbsd
    defaults:
      run:
        shell: openbsd {0}
    steps:
      - uses: actions/checkout@v5

      - name: Start OpenBSD VM
        uses: vmactions/openbsd-vm@v1
        with:
          prepare: |
            pkg_add -v cmake ninja git bash
          run: |
            git clone --depth=1 https://codeberg.org/OpenBSD/ports.git /usr/ports
          sync: 'rsync'
          copyback: false

      - name: Install capnproto
        run: |
          cd /usr/ports/devel/capnproto/
          make install

      - name: Run CI script
        run: |
          cd ${{ github.workspace }}
          CI_CONFIG="ci/configs/openbsd.bash" bash ci/scripts/ci.sh

  build-freebsd:
    runs-on: ubuntu-latest
    name: build • freebsd
    defaults:
      run:
        shell: freebsd {0}
    steps:
      - uses: actions/checkout@v5

      - name: Start FreeBSD VM
        uses: vmactions/freebsd-vm@v1
        with:
          prepare: |
            pkg install -y cmake ninja bash capnproto
          sync: 'rsync'
          copyback: false

      - name: Run CI script
        run: |
          cd ${{ github.workspace }}
          CI_CONFIG="ci/configs/freebsd.bash" bash ci/scripts/ci.sh

  build-macos:
    runs-on: macos-latest
    name: build • macos

    steps:
      - uses: actions/checkout@v5

      - name: Install dependencies
        env:
          HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
        run: |
          brew install --quiet ninja capnp

      - name: Run CI script
        run: |
          CI_CONFIG="ci/configs/macos.bash" bash ci/scripts/ci.sh

  build:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        config: [default, llvm, gnu32, sanitize, olddeps]

    name: build • ${{ matrix.config }}

    steps:
      - uses: actions/checkout@v5

      - name: Install Nix
        uses: cachix/install-nix-action@v31       # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
        with:
          nix_path: nixpkgs=channel:nixos-25.05   # latest release

      - name: Run CI script
        env:
          CI_CONFIG: ci/configs/${{ matrix.config }}.bash
        run: ci/scripts/run.sh
