name: VCPKG CI
on:
  pull_request_target:
  push:
    tags:
      - '*'
    branches:
      - 'master'
      - 'ci-tests/**'  # Branch namespace can be used to test changes to test before going to master
jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # This is the matrix. They form permutations.
        os: [ubuntu-24.04, macos-13, windows-latest]
        cc: [""]
        cxx: [""]
        # These are additional individual jobs. There are no permutations of these.
        include:
          - os: ubuntu-24.04
            cc: clang
            cxx: clang++
          # Broken for bgfx 1.127.8725-469, fixed in 1.128.8777-475
          # - os: windows-latest
          #   cc: clang
          #   cxx: clang++

    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.ref }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          submodules: recursive

      - name: Add base repo to git config
        run: git remote add upstream ${{ github.event.pull_request.base.repo.html_url }}
        if: startsWith(github.event_name, 'pull_request')

      - name: Install Linux dependencies
        run: |
          sudo apt update -y
          sudo apt install -y libgl1-mesa-dev libglu1-mesa-dev libltdl-dev libxext-dev
        if: startsWith(matrix.os, 'ubuntu')

      - name: Download ClangBuildAnalyzer
        uses: dsaltares/fetch-gh-release-asset@master
        if: matrix.cc == 'clang' || startsWith(matrix.os, 'macos')
        with:
          repo: 'aras-p/ClangBuildAnalyzer'
          file: ${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }}

      - name: Install MacOS dependencies
        run: |
          brew install llvm@18
          echo "$(brew --prefix llvm@18)/bin" >> $GITHUB_PATH
          echo "CC=$(brew --prefix llvm@18)/bin/clang" >> $GITHUB_ENV
          echo "CXX=$(brew --prefix llvm@18)/bin/clang++" >> $GITHUB_ENV
        if: startsWith(matrix.os, 'macos')

      # Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
      - uses: lukka/get-cmake@latest

      - name: Restore from cache and setup vcpkg executable and data files.
        uses: lukka/run-vcpkg@v11
        with:
          vcpkgJsonGlob: 'vcpkg.json'

      - name: Run CMake+vcpkg to build packages.
        id: build-packages
        uses: lukka/run-cmake@v10
        with:
          configurePreset: 'ninja-multi-vcpkg'
          configurePresetAdditionalArgs: "['-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DOPENBLACK_WARNINGS_AS_ERRORS=ON', '-DOPENBLACK_TRACE_TIME=ON']"

      - name: Upload logs if failed
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: vcpkg-build-logs-${{ matrix.os }}
          path: vcpkg/buildtrees/*/*.log

      - name: Clang Build Analysis (Debug).
        if: matrix.cc == 'clang' || startsWith(matrix.os, 'macos')
        run: |
          chmod +x ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }}
          ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }} --start cmake-build-presets/ninja-multi-vcpkg
        shell: bash

      - name: Run CMake+Ninja+CTest to build/test the code (Debug).
        uses: lukka/run-cmake@v10
        with:
          buildPreset: 'ninja-multi-vcpkg-debug'
          testPreset: 'ninja-multi-vcpkg-debug'

      - name: Clang Build Analysis (Release).
        if: matrix.cc == 'clang' || startsWith(matrix.os, 'macos')
        run: |
          ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }} --stop cmake-build-presets/ninja-multi-vcpkg clang-build-analysis-debug-${{ matrix.os }}.cap
          ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }} --start cmake-build-presets/ninja-multi-vcpkg
        shell: bash

      - name: Run CMake+Ninja+CTest to build/test the code (Release).
        uses: lukka/run-cmake@v10
        with:
          buildPreset: 'ninja-multi-vcpkg-release'
          testPreset: 'ninja-multi-vcpkg-release'

      - name: Display Clang Build Analysis.
        if: matrix.cc == 'clang' || startsWith(matrix.os, 'macos')
        run: |
          ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }} --stop cmake-build-presets/ninja-multi-vcpkg clang-build-analysis-release-${{ matrix.os }}.cap
          ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }} --analyze clang-build-analysis-debug-${{ matrix.os }}.cap
          ./${{ startsWith(matrix.os, 'ubuntu') && 'ClangBuildAnalyzer-linux' || startsWith(matrix.os, 'windows') && 'ClangBuildAnalyzer.exe' || startsWith(matrix.os, 'macos') && 'ClangBuildAnalyzer-mac' }} --analyze clang-build-analysis-release-${{ matrix.os }}.cap

      - name: Upload Clang Build Analysis
        uses: actions/upload-artifact@v4
        if: matrix.cc == 'clang' || startsWith(matrix.os, 'macos')
        with:
          name: openblack-clang-build-analysis-${{ github.sha }}
          path: |
            clang-build-analysis-debug-${{ matrix.os }}.cap
            clang-build-analysis-release-${{ matrix.os }}.cap
          if-no-files-found: error
          overwrite: true

      - name: Upload compile database and system includes
        uses: actions/upload-artifact@v4
        if: startsWith(matrix.os, 'ubuntu')
        with:
          name: openblack-compile-database-${{ github.sha }}
          path: |
            cmake-build-presets/ninja-multi-vcpkg/include
            cmake-build-presets/ninja-multi-vcpkg/vcpkg_installed/x64-linux/include
            cmake-build-presets/ninja-multi-vcpkg/compile_commands.json
          if-no-files-found: error
          overwrite: true

      - run: echo "GITHUB_REF_NAME_DASHES=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV
        shell: bash

      - name: Upload compiled openblack and tools
        uses: actions/upload-artifact@v4
        if: matrix.cc == ''
        with:
          name: openblack-${{ matrix.os }}-${{ env.GITHUB_REF_NAME_DASHES }}
          path: cmake-build-presets/ninja-multi-vcpkg/bin
          if-no-files-found: error

      - name: Upload generated test data
        uses: actions/upload-artifact@v4
        if: matrix.cc == ''
        with:
          name: openblack-test-data-${{ env.GITHUB_REF_NAME_DASHES }}
          path: |
            cmake-build-presets/ninja-multi-vcpkg/test/*/scenarios
            cmake-build-presets/ninja-multi-vcpkg/test/mock/Scripts
            cmake-build-presets/ninja-multi-vcpkg/test/mock/Data
            cmake-build-presets/ninja-multi-vcpkg/test/mock/Audio
          if-no-files-found: error
          overwrite: true

    env:
      CC: ${{ matrix.cc }}
      CXX: ${{ matrix.cxx }}

  clang-tidy:
    needs: build
    runs-on: ubuntu-latest
    if: startsWith(github.event_name, 'pull_request')
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.ref }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          submodules: recursive
      - name: Download generated compile database
        uses: actions/download-artifact@v4
        with:
          name: openblack-compile-database-${{ github.sha }}
          path: cmake-build-presets/ninja-multi-vcpkg
      - name: Add base repo to git config
        run: git remote add upstream ${{ github.event.pull_request.base.repo.html_url }}
        if: startsWith(github.event_name, 'pull_request')
      - uses: ZedThree/clang-tidy-review@v0.19.0
        id: review
        with:
          build_dir: cmake-build-presets/ninja-multi-vcpkg
          exclude: "*ShaderIncluder.h,*json.hpp,*imgui_impl_sdl*,*stb_image_write.h,*stb_rect_pack.h,*dr_*.h"
          config_file: ""       # Don't use a single config file
          clang_tidy_checks: "" # Use checks from .clang-tidy tree
          lgtm_comment_body: "" # Don't post a lgtm message
          annotations: false
      - name: If there are any comments, fail the check
        if: steps.review.outputs.total_comments > 0
        run: exit 1

  run:
    needs: build
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # This is the matrix. They form permutations.
        os: [ ubuntu-24.04, macos-13, windows-latest ]
    steps:
      - run: echo "GITHUB_REF_NAME_DASHES=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV
        shell: bash
      - name: Download compiled openblack and tools
        uses: actions/download-artifact@v4
        id: download-binary
        with:
          name: openblack-${{ matrix.os }}-${{ env.GITHUB_REF_NAME_DASHES }}
      - name: Download generated mock data
        uses: actions/download-artifact@v4
        id: download-test
        with:
          name: openblack-test-data-${{ env.GITHUB_REF_NAME_DASHES }}
          path: cmake-build-presets/ninja-multi-vcpkg/test
      - name: Download Pre-patched and installed Game Data
        uses: suisei-cn/actions-download-file@v1.6.0
        id: game-data
        with:
          url: ${{secrets.BW_DOWNLOAD_URL}}
          filename: bw.7z
          target: game-data
      - name: Extract Game Data
        run: 7z x -ogame-data/bw "$PWD/game-data/${{steps.game-data.outputs.filename}}"
      - name: Add empty Audio directory
        run: mkdir game-data/bw/Audio
      - name: Enable execute permissions on binary
        run: chmod +x ${{steps.download-binary.outputs.download-path}}/*/*
        if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   -g ${{steps.download-test.outputs.download-path}}/mock -b Noop --num-frames-to-simulate 10 --log-file stdout --log-level all=debug
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack -g ${{steps.download-test.outputs.download-path}}/mock -b Noop --num-frames-to-simulate 10 --log-file stdout --log-level all=debug
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   -g game-data/bw                                        -b Noop --num-frames-to-simulate 10 --log-file stdout --log-level all=debug
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack -g game-data/bw                                        -b Noop --num-frames-to-simulate 10 --log-file stdout --log-level all=debug
      - name: Install valgrind and libc6-dbg
        run: |
          sudo apt update -y
          sudo apt install -y valgrind
        if: startsWith(matrix.os, 'ubuntu')
      - name: Check unittests for memory leaks
        run:  |
          for test in ${{steps.download-binary.outputs.download-path}}/Debug/test* ; do
              echo Running valgrind on $test
              valgrind --tool=memcheck --track-origins=yes --leak-check=full -s --error-exitcode=1 "$test"
          done
        if: startsWith(matrix.os, 'ubuntu')
        env:
          ALSOFT_DRIVERS: "null" # avoid using also which fails, then leaks memory outside of project
      - name: Check openblack for memory leaks (Mock)
        run: valgrind --tool=memcheck --track-origins=yes --leak-check=full -s --error-exitcode=1 ${{steps.download-binary.outputs.download-path}}/Debug/openblack -g ${{steps.download-test.outputs.download-path}}/mock -b Noop --num-frames-to-simulate 10  --log-level all=error
        if: startsWith(matrix.os, 'ubuntu')
        env:
          ALSOFT_DRIVERS: "null" # avoid using also which fails, then leaks memory outside of project
      - name: Check openblack for memory leaks (Real)
        run: valgrind --tool=memcheck --track-origins=yes --leak-check=full -s --error-exitcode=1 ${{steps.download-binary.outputs.download-path}}/Debug/openblack -g game-data/bw -b Noop --num-frames-to-simulate 10  --log-level all=error
        if: startsWith(matrix.os, 'ubuntu')
        env:
          ALSOFT_DRIVERS: "null" # avoid using also which fails, then leaks memory outside of project

  screenshot:
    needs: run
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        # This is the matrix. They form permutations.
        os: [ windows-latest ] # ubuntu-latest, macos-latest
    env:
      ARGS: -g game-data\bw --num-frames-to-simulate 10 --screenshot-frame 5 --log-file stdout --log-level all=debug -W 800 -H 600
      BACKEND: Direct3D11
    steps:
      - run: echo "GITHUB_REF_NAME_DASHES=${GITHUB_REF_NAME/\//-}" >> $GITHUB_ENV
        shell: bash
      - name: Download compiled openblack and tools
        uses: actions/download-artifact@v4
        id: download-binary
        with:
          name: openblack-${{ matrix.os }}-${{ env.GITHUB_REF_NAME_DASHES }}
      - name: Download generated mock data
        uses: actions/download-artifact@v4
        id: download-test
        with:
          name: openblack-test-data-${{ env.GITHUB_REF_NAME_DASHES }}
      - name: Enable execute permissions on binary
        run: chmod +x ${{steps.download-binary.outputs.download-path}}/*/*
        if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
      - name: Download Pre-patched and installed Game Data
        uses: suisei-cn/actions-download-file@v1.6.0
        id: game-data
        with:
          url: ${{secrets.BW_DOWNLOAD_URL}}
          filename: bw.7z
          target: game-data
      - name: Extract Game Data
        run: 7z x -ogame-data/bw "$PWD/game-data/${{steps.game-data.outputs.filename}}"
      - name: Add empty Audio directory
        run: mkdir game-data/bw/Audio
      - name: Get openblack-assets
        uses: actions/checkout@v4
        with:
          repository: openblack/openblack-assets
          path: openblack-assets
      - name: Install openblack-assets
        run: cp -v -r openblack-assets/assets/* game-data/bw
        shell: bash
      - name: Set Screenshot Position For Maps
        run: |
          'START_CAMERA_POS("1788.40,2710.00")' | Add-Content -Path game-data\bw\Scripts\Land1.txt
          'START_CAMERA_POS("2847.10,3063.12")' | Add-Content -Path game-data\bw\Scripts\Land2.txt
          'START_CAMERA_POS("2002.57,2122.02")' | Add-Content -Path game-data\bw\Scripts\Land3.txt
          'START_CAMERA_POS("2689.87,2609.63")' | Add-Content -Path game-data\bw\Scripts\Land4.txt
          'START_CAMERA_POS("2654.25,3059.49")' | Add-Content -Path game-data\bw\Scripts\LandT.txt
          'START_CAMERA_POS("2802.60,2154.76")' | Add-Content -Path game-data\bw\Scripts\Playgrounds/ThreeGods.txt
          'START_CAMERA_POS("1801.69,2012.08")' | Add-Content -Path game-data\bw\Scripts\Playgrounds/FourGods.txt
          'START_CAMERA_POS("2550.00,2000.00")' | Add-Content -Path game-data\bw\Scripts\Playgrounds/construct.txt
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Land1.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-1.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Land1.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-1.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Land2.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-2.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Land2.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-2.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Land3.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-3.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Land3.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-3.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Land4.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-4.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Land4.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-4.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Land5.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-5.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Land5.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-5.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s LandT.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-T.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s LandT.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-T.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/TwoGods.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-two-gods.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/TwoGods.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-two-gods.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/ThreeGods.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-three-gods.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/ThreeGods.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-three-gods.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/FourGods.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-four-gods.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/FourGods.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-four-gods.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Debug/openblack   ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/construct.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-construct.png"
      - run: ${{steps.download-binary.outputs.download-path}}/Release/openblack ${{env.ARGS}} -b ${{env.BACKEND}} -s Playgrounds/construct.txt --screenshot-path "screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-construct.png"
      - name: Upload screenshots
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: openblack-screenshots
          path: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-*.png
          if-no-files-found: error
      - name: Upload Land 1 Debug screenshot for comments
        id: upload-screenshot-debug-land-1
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-1.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-1.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 1 Release screenshot for comments
        id: upload-screenshot-release-land-1
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-1.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-1.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 2 Debug screenshot for comments
        id: upload-screenshot-debug-land-2
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-2.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-2.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 2 Release screenshot for comments
        id: upload-screenshot-release-land-2
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-2.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-2.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 3 Debug screenshot for comments
        id: upload-screenshot-debug-land-3
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-3.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-3.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 3 Release screenshot for comments
        id: upload-screenshot-release-land-3
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-3.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-3.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 4 Debug screenshot for comments
        id: upload-screenshot-debug-land-4
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-4.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-4.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 4 Release screenshot for comments
        id: upload-screenshot-release-land-4
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-4.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-4.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 5 Debug screenshot for comments
        id: upload-screenshot-debug-land-5
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-5.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-5.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land 5 Release screenshot for comments
        id: upload-screenshot-release-land-5
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-5.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-5.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land T Debug screenshot for comments
        id: upload-screenshot-debug-land-T
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-T.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-T.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Land T Release screenshot for comments
        id: upload-screenshot-release-land-T
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-T.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-T.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Two Gods Debug screenshot for comments
        id: upload-screenshot-debug-two-gods
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-two-gods.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-two-gods.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Two Gods Release screenshot for comments
        id: upload-screenshot-release-two-gods
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-two-gods.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-two-gods.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Three Gods Debug screenshot for comments
        id: upload-screenshot-debug-three-gods
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-three-gods.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-three-gods.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Three Gods Release screenshot for comments
        id: upload-screenshot-release-three-gods
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-three-gods.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-three-gods.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Four Gods Debug screenshot for comments
        id: upload-screenshot-debug-four-gods
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-four-gods.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-four-gods.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Four Gods Release screenshot for comments
        id: upload-screenshot-release-four-gods
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-four-gods.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-four-gods.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Construct Debug screenshot for comments
        id: upload-screenshot-debug-construct
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-construct.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-construct.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Upload Construct Release screenshot for comments
        id: upload-screenshot-release-construct
        uses: fjogeleit/http-request-action@v1
        if: github.event_name == 'pull_request_target'
        with:
          file: screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-construct.png
          url: "https://screenshots.bwgame.net/screenshot-${{ matrix.os }}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-construct.png"
          method: 'PUT'
          customHeaders: '{"X-Openblack-Auth-Key": "${{ secrets.SCREENSHOTS_API_KEY }}"}'
      - name: Find Image Comment
        if: github.event_name == 'pull_request_target'
        uses: peter-evans/find-comment@v2
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          body-includes: Uploaded images
      - name: Create or update comment with images
        if: github.event_name == 'pull_request_target'
        uses: peter-evans/create-or-update-comment@v2
        with:
          comment-id: ${{ steps.fc.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            # Uploaded images
            | Map | Debug | Release | Vanilla |
            | --- | ----- | ------- | ------- |
            | Land1.txt | ![Land1 Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-1.png) | ![Land1 Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-1.png) | ![Land1 Vanilla](https://user-images.githubusercontent.com/1013356/188042342-a6e84dfd-840d-4b90-a1b8-84128e4aab5d.png) |
            | Land2.txt | ![Land2 Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-2.png) | ![Land2 Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-2.png) | ![Land2 Vanilla](https://github.com/openblack/openblack/assets/1013356/0910a1c9-23f2-4cb2-a617-8e5efff9d9ab) |
            | Land3.txt | ![Land3 Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-3.png) | ![Land3 Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-3.png) | ![Land3 Vanilla](https://user-images.githubusercontent.com/1013356/188042339-4a3941f3-1089-4838-a086-9836c6fe5113.png) |
            | Land4.txt | ![Land4 Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-4.png) | ![Land4 Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-4.png) | ![Land4 Vanilla](https://user-images.githubusercontent.com/1013356/188042337-6d139916-5988-4020-a738-1a1fe64a915d.png) |
            | Land5.txt | ![Land5 Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-5.png) | ![Land5 Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-5.png) | ![Land5 Vanilla](https://user-images.githubusercontent.com/1013356/188042333-5009397c-087f-48fd-a150-b811284f65ed.png) |
            | LandT.txt | ![LandT Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-land-T.png) | ![LandT Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-land-T.png) | ![LandT Vanilla](https://user-images.githubusercontent.com/1013356/188042332-f9fd0060-d0e0-478a-bb7f-c8eb0ae0690f.png) |
            | TwoGods.txt | ![TwoGods Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-two-gods.png) | ![TwoGods Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-two-gods.png) | ![TwoGods Vanilla](https://user-images.githubusercontent.com/1013356/188042326-6cbe726c-6753-4157-86fa-63016804f313.png) |
            | ThreeGods.txt | ![ThreeGods Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-three-gods.png) | ![ThreeGods Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-three-gods.png) | ![ThreeGods Vanilla](https://user-images.githubusercontent.com/1013356/188042329-51054173-dec5-47b2-8537-ac605ab2be4b.png) |
            | FourGods.txt | ![FourGods Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-four-gods.png) | ![FourGods Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-four-gods.png) | ![FourGods Vanilla](https://user-images.githubusercontent.com/1013356/188042323-7d428031-cf7e-4e46-b185-a12950bff76a.png) |
            | construct.txt | ![Construct Debug](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-debug-construct.png) | ![Construct Release](https://screenshots.bwgame.net/screenshot-${{matrix.os}}-${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}-release-construct.png) | ![construct Vanilla](https://github.com/openblack/openblack/assets/1013356/8e7480a9-5839-49d2-894f-b9821c3dd3e2) |
          edit-mode: replace
