name: Windows build

on: [push,workflow_dispatch]

jobs:
  build:
    runs-on: windows-latest

    strategy:
      fail-fast: false
      matrix:
        include:
          - { sys: xtensa }
          - { sys: mingw64, env: x86_64 }
          - { sys: mingw32, env: i686 }
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cache/pip
            ~/.platformio/.cache
          key: ${{ runner.os }}-pio
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install MSYS2 MINGW64/32 and SDL2
        if: ${{matrix.sys != 'xtensa'}}
        uses: msys2/setup-msys2@v2
        with:
          update: true
          msystem: ${{matrix.sys}}
          install: >-
            mingw-w64-${{matrix.env}}-gcc
            mingw-w64-${{matrix.env}}-SDL2
      - name: Add paths mingw64
        if: ${{matrix.sys == 'mingw64'}}
        run: |
          echo "${{runner.temp}}\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
          echo "${{runner.temp}}\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
      - name: Add paths mingw32
        if: ${{matrix.sys == 'mingw32'}}
        run: |
          echo "${{runner.temp}}\msys64\mingw32\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
          echo "${{runner.temp}}\msys64\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

      - name: Install PlatformIO Core
        run: pip install --upgrade platformio

      - name: Build PlatformIO env:ESP32
        working-directory: ./Platformio
        run: pio run -e esp32

      - name: Build PlatformIO env:windows_linux_64bit
        if: ${{matrix.sys == 'mingw64'}}
        working-directory: ./Platformio
        run: pio run -e windows_linux_64bit

      - name: Build PlatformIO env:windows_linux_32bit
        if: ${{matrix.sys == 'mingw32'}}
        working-directory: ./Platformio
        run: pio run -e windows_linux_32bit
