name: Test MinGW

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

permissions:
  contents: read

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

env:
  FORCE_COLOR: 1

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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        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-libavif \
              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@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
        with:
          files: ./coverage.xml
          flags: GHA_Windows
          name: "MSYS2 MinGW"
