name: Push and PR

on:
  push:
    paths-ignore:
      - '**.md'
      - 'docs/**'
      - 'LICENSE*'
      - '.*'
      - '!.github/**'
    branches:
      - master
  pull_request:
    paths-ignore:
      - '**.md'
      - 'docs/**'
      - 'LICENSE*'
      - '.*'
      - '!.github/**'

jobs:
  check:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-24.04
            shell: bash
          - os: macos-13
            shell: bash
          - os: windows-2022
            msystem: 'MINGW32'
            shell: msys2
          - os: windows-2022
            msystem: 'UCRT64'
            shell: msys2
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: ${{ matrix.shell }} {0}
    steps:
    - uses: actions/checkout@v4

    # cmake pulls ninja by default
    - name: Install dependencies (MSYS)
      if: matrix.os == 'windows-2022'
      uses: msys2/setup-msys2@v2
      with:
        msystem: ${{ matrix.msystem }}
        update: true
        install: >-
          git
        pacboy: >-
          toolchain:p
          glib2:p
          cmake:p
          libxml2:p

    - name: Install dependencies (Ubuntu)
      if: matrix.os == 'ubuntu-24.04'
      run: >
        sudo apt-get install -y
        build-essential
        cmake
        ninja-build
        libglib2.0-dev
        libxml2-utils

    - name: Install dependencies (MacOS)
      if: matrix.os == 'macos-13'
      run: |
        brew install cmake ninja

    - name: Pre-build
      run: |
        cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo

    - name: Build
      run: |
        cmake --build build -v

    - name: Test prefixed install
      run: |
        cmake --install build --prefix inst --strip -v

    - name: Basic CTest
      continue-on-error: true
      id: basic_ctest
      env:
        MSYS2_PATH_TYPE: inherit
      run: |
        cd build && ctest

    - name: Rerun failed tests
      if: steps.basic_ctest.outcome == 'failure'
      env:
        MSYS2_PATH_TYPE: inherit
      run: |
        cd build && ctest --rerun-failed --output-on-failure -V

