name: NetBSD CMake

on:
  workflow_dispatch:
  push:
    branches: main
    tags-ignore: '*.*'
    paths:
      - '.github/workflows/cmake-netbsd.yml'
      - 'CMakeLists.txt'
      - 'cmake/**'
      - 'include/**'
      - 'src/*pp'
      - 'src/netbsd/*pp'
  pull_request:
    branches: main
    paths:
      - '.github/workflows/cmake-netbsd.yml'
      - 'CMakeLists.txt'
      - 'cmake/**'
      - 'include/**'
      - 'src/*pp'
      - 'src/netbsd/*pp'

jobs:
  build:
    name: netbsd-${{ matrix.version }}-${{ matrix.arch }}
    runs-on: ubuntu-24.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ matrix.arch }}-${{ matrix.version }}
      cancel-in-progress: true
    strategy:
      matrix:
        arch: ['aarch64', 'amd64']
        version: ['10.1']
    steps:
      - uses: actions/checkout@v6

      - name: Compile
        uses: vmactions/netbsd-vm@v1
        with:
          arch: ${{ matrix.arch }}
          release: ${{ matrix.version }}
          usesh: true
          prepare: |
            export PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH"
            export PKG_PATH="https://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/${{ matrix.arch }}/${{ matrix.version }}/All/"
            /usr/sbin/pkg_add pkgin
            pkgin -y install cmake gcc14 git ninja-build
          run: |
            export CXX="/usr/pkg/gcc14/bin/g++"
            cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
            cmake --build build --verbose
            ctest --test-dir build
