name: Windows build

on:
  push:
    paths-ignore:
      - '.clang-format'
      - '.drone.star'
      - '.gitattributes'
      - '.gitignore'
      - '.gdbinit'
      - '.github/*'
      - '.github/workflows/Linux_build.yml'
      - '.github/*_TEMPLATE/**'
      - '*.md'
      - '*.yml'
      - '*.txt'
      - 'docs/**'
      - 'src/**/*_posix.*'
      - 'src/**/*_linux.*'
      - 'src/**/*_gnulinux.*'
      - 'src/**/*_x11.*'
      - 'src/**/*_gtk.*'
      - 'src/**/*_android.*'
      - 'src/**/*_mac.*'
      - 'LICENSE'
  pull_request:
    paths-ignore:
      - '.clang-format'
      - '.drone.star'
      - '.gitattributes'
      - '.gitignore'
      - '.gdbinit'
      - '.github/*'
      - '.github/workflows/Linux_build.yml'
      - '.github/*_TEMPLATE/**'
      - '*.md'
      - '*.yml'
      - '*.txt'
      - 'docs/**'
      - 'src/**/*_posix.*'
      - 'src/**/*_linux.*'
      - 'src/**/*_gnulinux.*'
      - 'src/**/*_x11.*'
      - 'src/**/*_gtk.*'
      - 'src/**/*_android.*'
      - 'src/**/*_mac.*'
      - 'LICENSE'
  workflow_dispatch:

jobs:
  lint:
    name: Lint
    runs-on: windows-latest
    env:
      POWERSHELL_TELEMETRY_OPTOUT: 1
    steps:
      - uses: actions/checkout@main
      # TODO: Remove this once the default Python is upgraded from 3.9: https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md#language-and-runtime
      - uses: actions/setup-python@main
        with:
          python-version: '3.x'
      - name: Lint
        run: python xenia-build.py lint --all

  build:
    name: Build
    needs: lint
    runs-on: windows-2025
    env:
      POWERSHELL_TELEMETRY_OPTOUT: 1
    steps:
      - uses: actions/checkout@main
        with:
          fetch-depth: 0
      - name: Setup
        run: git submodule update --init --depth=1 -j $env:NUMBER_OF_PROCESSORS (Select-String -CaseSensitive '(?<=path = )(?!third_party\/(FidelityFX-(CAS|FSR)|premake-(androidndk|cmake|export-compile-commands))).+' .gitmodules).Matches.Value
      # TODO: Remove this once the default Python is upgraded from 3.9: https://github.com/actions/runner-images/blob/main/images/windows/Windows2025-Readme.md#language-and-runtime
      - uses: actions/setup-python@main
        with:
          python-version: '3.x'
      - name: Build
        run: python xenia-build.py build --config=Release --target=src\xenia-app
      - name: Prepare artifacts
        id: prepare_artifacts
        run: |
          foreach ($file in 'build\bin\Windows\Release\xenia_canary.exe','build\bin\Windows\Release\xenia_canary.pdb') {
            if ((get-item $file).Length -le 100000) {
              echo "::error::$file is too small."
            }
          }
          robocopy . build\bin\Windows\Release                                                                LICENSE /r:0 /w:0
          robocopy   build\bin\Windows\Release artifacts\xenia_canary   xenia_canary.exe   xenia_canary.pdb   LICENSE /r:0 /w:0
          If ($LastExitCode -le 7) { echo "LastExitCode = $LastExitCode";$LastExitCode = 0 }
      - name: Upload xenia canary artifacts
        if: steps.prepare_artifacts.outcome == 'success'
        uses: actions/upload-artifact@main
        with:
          name: xenia_canary_windows
          path: artifacts\xenia_canary
          if-no-files-found: error

  create-release:
    name: Create release
    needs: [lint, build]
    if: |
      github.repository == 'xenia-canary/xenia-canary' &&
      github.event.action != 'pull_request' &&
      github.ref == 'refs/heads/canary_experimental'
    uses: ./.github/workflows/Create_release.yml
    with:
      os: windows
    secrets:
      RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
