name: ci-windows

on:
  push:
    paths:
      - "**"
      - "!android/**"
      - "!docs/**"
      - "docs/Makefile.am"
      - "!ios/**"
      - "!macosx/**"
      - "!msvcstuff/**"
      - "!AUTHORS"
      - "!ChangeLog"
      - "!COPYING"
      - "!FAQ"
      - "!INSTALL"
      - "!NEWS"
      - "!**README**"
      - "!**.ico"
      - "!**.md"
      - "!**.png"
      - "!**.txt"
      - "!.clang*"
      - "!.gitignore"
      - "!.gitattributes"
      - "!.github/workflows/*"
      - ".github/workflows/ci-windows.yml"
  pull_request:
    paths:
      - "**"
      - "!android/**"
      - "!docs/**"
      - "docs/Makefile.am"
      - "!ios/**"
      - "!macosx/**"
      - "!msvcstuff/**"
      - "!AUTHORS"
      - "!ChangeLog"
      - "!COPYING"
      - "!FAQ"
      - "!INSTALL"
      - "!NEWS"
      - "!**README**"
      - "!**.ico"
      - "!**.md"
      - "!**.png"
      - "!**.txt"
      - "!.clang*"
      - "!.gitignore"
      - "!.gitattributes"
      - "!.github/workflows/*"
      - ".github/workflows/ci-windows.yml"

jobs:
  notify:
    name: Exult-CI (IRC & Discord notification)
    runs-on: ubuntu-latest
    continue-on-error: true
    needs:
      - ci-windows
    if: ${{ always() && (github.repository_owner == 'exult' && github.event_name != 'pull_request') }}
    steps:
      - name: IRC success notification (ircs://irc.libera.chat:6697/#exult)
        uses: Gottox/irc-message-action@v2
        continue-on-error: true
        if: needs.ci-windows.result == 'success'
        with:
          server: irc.libera.chat
          port: 6697
          channel: "#exult"
          nickname: github-actions
          tls: true
          message: "\x0313exult\x03/\x0306${{ github.ref }}\x03 \x0314${{ github.sha }}\x03 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} The Windows build \x033succeeded\x03."
      - name: IRC failure notification (ircs://irc.libera.chat:6697/#exult)
        uses: Gottox/irc-message-action@v2
        continue-on-error: true
        if: needs.ci-windows.result != 'success'
        with:
          server: irc.libera.chat
          port: 6697
          channel: "#exult"
          nickname: github-actions
          tls: true
          message: "\x0313exult\x03/\x0306${{ github.ref }}\x03 \x0314${{ github.sha }}\x03 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} The Windows build \x034failed\x03."
      - name: Discord success notification
        uses: rjstone/discord-webhook-notify@v1
        continue-on-error: true
        if: needs.ci-windows.result == 'success'
        with:
          severity: info
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          username: Exult github-actions
          avatarUrl: https://avatars.githubusercontent.com/u/15114538?s=200&v=4
          text: '**[The Windows build succeeded:](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**'
      - name: Discord failure notification
        uses: rjstone/discord-webhook-notify@v1
        continue-on-error: true
        if: needs.ci-windows.result != 'success'
        with:
          severity: error
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          username: Exult github-actions
          avatarUrl: https://avatars.githubusercontent.com/u/15114538?s=200&v=4
          text: '**[The Windows build failed:](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**'
  ci-windows:
    runs-on: windows-2022
    strategy:
      fail-fast: false
      matrix:
        sys: [UCRT64, clang64]
        include:
          #- { sys: mingw64, env: mingw-w64-x86_64 }
          - { sys: UCRT64, env: mingw-w64-ucrt-x86_64 }
          - { sys: clang64, env: mingw-w64-clang-x86_64 }
    defaults:
      run:
        shell: msys2 {0}
    steps:
      - name: Install dependencies
        uses: msys2/setup-msys2@v2
        with:
          msystem: ${{ matrix.sys }}
          update: true
          install: |
            base-devel git zip
            ${{ matrix.env }}-toolchain ${{ matrix.env }}-binutils ${{ matrix.env }}-ntldd ${{ matrix.env }}-SDL2
            ${{ matrix.env }}-fluidsynth ${{ matrix.env }}-libtimidity ${{ matrix.env }}-libogg ${{ matrix.env }}-libvorbis
            ${{ matrix.env }}-munt-mt32emu ${{ matrix.env }}-libpng ${{ matrix.env }}-zlib ${{ matrix.env }}-SDL2_image
            ${{ matrix.env }}-gtk3 ${{ matrix.env }}-adwaita-icon-theme ${{ matrix.env }}-libxml2 ${{ matrix.env }}-freetype
            ${{ matrix.env }}-gimp ${{ matrix.env }}-icu
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Build
        run: |
          make -j 2 -f Makefile.mingw DEBUG=1 USECODE_DEBUGGER=1 DISTPATH=disttest Exult.exe exult_studio.exe tools u7shp.exe exult_shp.exe exconfig.dll dist studiodist toolsdist plugindist aseprite-plugindist
          for ff in $(find content -name 'Makefile.mingw' -exec dirname {} \;); do
            pushd "${ff}"
            make -j 2 -f Makefile.mingw
            popd
          done
          cd disttest
          mv exconfig-x86_64.dll exconfig-i686.dll
          mkdir Exult-i686
          cp -r Exult-x86_64/* Exult-i686
          mkdir studio-i686
          cp -r studio-x86_64/* studio-i686
          mkdir tools-i686
          cp -r tools-x86_64/* tools-i686
          mkdir GimpPlugin-i686
          cp -r GimpPlugin-x86_64/* GimpPlugin-i686
          "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" exult_installer.iss
          "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" exult_studio_installer.iss
          "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" exult_tools_installer.iss
          "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" exult_shpplugin_installer.iss
