name: Test MinGW

on:
  push:
    branches:
      - "**"
    paths-ignore:
      - ".github/workflows/docs.yml"
      - ".github/workflows/wheels*"
      - ".gitmodules"
      - "docs/**"
      - "wheels/**"
  pull_request:
    paths-ignore:
      - ".github/workflows/docs.yml"
      - ".github/workflows/wheels*"
      - ".gitmodules"
      - "docs/**"
      - "wheels/**"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  COVERAGE_CORE: sysmon

jobs:
  build:
    runs-on: windows-latest

    defaults:
      run:
        shell: bash.exe --login -eo pipefail "{0}"
    env:
      MSYSTEM: MINGW64
      CHERE_INVOKING: 1

    timeout-minutes: 30
    name: "MinGW"

    steps:
      - name: Checkout Pillow
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Set up shell
        run: echo "C:\msys64\usr\bin\" >> $env:GITHUB_PATH
        shell: pwsh

      - name: Install dependencies
        run: |
          pacman -S --noconfirm \
              mingw-w64-x86_64-freetype \
              mingw-w64-x86_64-gcc \
              mingw-w64-x86_64-ghostscript \
              mingw-w64-x86_64-lcms2 \
              mingw-w64-x86_64-libimagequant \
              mingw-w64-x86_64-libjpeg-turbo \
              mingw-w64-x86_64-libraqm \
              mingw-w64-x86_64-libtiff \
              mingw-w64-x86_64-libwebp \
              mingw-w64-x86_64-openjpeg2 \
              mingw-w64-x86_64-python-numpy \
              mingw-w64-x86_64-python-olefile \
              mingw-w64-x86_64-python-pip \
              mingw-w64-x86_64-python-pytest \
              mingw-w64-x86_64-python-pytest-cov \
              mingw-w64-x86_64-python-pytest-timeout \
              mingw-w64-x86_64-python-pyqt6

          pushd depends && ./install_extra_test_images.sh && popd

      - name: Build Pillow
        run: CFLAGS="-coverage" python3 -m pip install .

      - name: Test Pillow
        run: |
          python3 selftest.py --installed
          .ci/test.sh

      - name: Upload coverage
        uses: codecov/codecov-action@v5
        with:
          files: ./coverage.xml
          flags: GHA_Windows
          name: "MSYS2 MinGW"
          token: ${{ secrets.CODECOV_ORG_TOKEN }}