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@master
        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@master
        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-latest
    strategy:
      fail-fast: false
      matrix:
        sys: [mingw64, clang64]
        include:
          - { sys: mingw64, env: mingw-w64-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 }}
          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 }}-gtk2 ${{ 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_CONTAINER=1 USECODE_DEBUGGER=1 SHOW_NONREADIED_OBJECTS=1 Exult.exe exult_studio.exe tools u7shp.exe exconfig.dll
          for ff in $(find content -name 'Makefile.mingw' -exec dirname {} \;); do
            pushd "${ff}"
            make -j 2 -f Makefile.mingw
            popd
          done
