name: msys2 auto

on:
  workflow_dispatch:

permissions:
  contents: read

# Using concurrency to cancel any in-progress job or run
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
  cancel-in-progress: true

jobs:
  msys2_build_and_test:
    runs-on: windows-latest
    strategy:
      matrix:
        include:
          - { icon: '⬛', sys: mingw32 }
          - { icon: '🟦', sys: mingw64 }
          - { icon: '🟨', sys: ucrt64  }
          - { icon: '🟧', sys: clang64 }
    name: ${{ matrix.icon }} msys2-${{ matrix.sys }}-${{ inputs.build_mode }}
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - name: Get Sources
        uses: actions/checkout@v4.1.7

      - name: '${{ matrix.icon }} Setup MSYS2'
        uses: msys2/setup-msys2@v2
        with:
          msystem: ${{matrix.sys}}
          update: true
          install: >-
            git
            autotools
          pacboy: >-
            toolchain:p
            libjpeg-turbo:p

      - name: Autotools Configure
        shell: msys2 {0}
        run: |
          sh ./autogen.sh
          mkdir "$GITHUB_WORKSPACE/build"
          cd "$GITHUB_WORKSPACE/build"
          LDFLAGS="-lws2_32" $GITHUB_WORKSPACE/configure \
            --disable-netcdf --disable-netcdf-tools --enable-static-exec

      - name: Autotools Build
        shell: msys2 {0}
        run: |
          make -j3
        working-directory: $GITHUB_WORKSPACE/build

      - name: Autotools Run Tests
        shell: msys2 {0}
        run: |
          make check -j
        working-directory: $GITHUB_WORKSPACE/build
