name: Android (Windows)

on:
  pull_request:
    branches:
      - dev

jobs:
  build:
    runs-on: windows-latest
    strategy:
      fail-fast: false
      matrix:
        arch: [armeabi-v7a, arm64-v8a]
        ndk: ["r22", "r27"]
        ndk_sdkver: ["30"]

    concurrency:
      group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Android-Windows-${{ matrix.arch }}-${{ matrix.ndk }}-${{ matrix.ndk_sdkver }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v1
      - uses: xmake-io/github-action-setup-xmake@v1
        with:
          xmake-version: branch@master

      - name: Configure Pagefile
        uses: al-cheb/configure-pagefile-action@v1.2
        with:
          minimum-size: 8GB
          maximum-size: 32GB
          disk-root: "D:"

      - name: Prepare
        run: |
          if ("${{ matrix.ndk }}" -eq "r27") {
            curl -fsSL "https://dl.google.com/android/repository/android-ndk-r27-windows.zip" -o android-ndk-r27-windows.zip
            Expand-Archive ./android-ndk-r27-windows.zip -DestinationPath ./ndk
          } else {
            curl -fsSL "https://dl.google.com/android/repository/android-ndk-r22-windows-x86_64.zip" -o android-ndk-r22-windows-x86_64.zip
            Expand-Archive ./android-ndk-r22-windows-x86_64.zip -DestinationPath ./ndk
          }

      - name: Tests
        run: |
          git clone https://github.com/xmake-io/xmake.git --recurse-submodules -b master xmakesrc
          cd xmakesrc/core
          xmake
          cd ../..
          Copy-Item ./xmakesrc/core/build/xmake.exe ./xmakesrc/xmake
          Copy-Item ./xmakesrc/scripts/xrepo.bat ./xmakesrc/xmake
          Copy-Item ./xmakesrc/scripts/xrepo.ps1 ./xmakesrc/xmake
          $Env:XMAKE_MAIN_REPO = "https://github.com/xmake-io/xmake-repo.git"
          $Env:XMAKE_PROGRAM_DIR = $(Resolve-Path ./xmakesrc/xmake)
          Set-Item -Path Env:Path -Value ($Env:XMAKE_PROGRAM_DIR + ";" + $Env:Path)
          xmake --version
          xmake l ./scripts/test.lua -D -p android --ndk=D:/a/xmake-repo/xmake-repo/ndk/android-ndk-${{ matrix.ndk }} --ndk_sdkver=${{ matrix.ndk_sdkver }} -a ${{ matrix.arch }}
