name: Windows x86-64

on: [ push, pull_request ]

jobs:
  build:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install zip
        run: |
          $system32 = [System.Environment]::GetEnvironmentVariable("WINDIR") + "\System32"
          Invoke-WebRequest -Uri "http://stahlworks.com/dev/zip.exe" -OutFile "$system32\zip.exe"
          Invoke-WebRequest -Uri "http://stahlworks.com/dev/unzip.exe" -OutFile "$system32\unzip.exe"

      - name: Install 7z
        uses: milliewalky/setup-7-zip@v2

      - name: Installing Java
        run: |
          curl -s --output ${{ runner.temp }}\java_package.zip -L https://cache-redirector.jetbrains.com/intellij-jbr/jbrsdk-21.0.7-windows-x64-b1034.51.zip
          unzip -q ${{ runner.temp }}\java_package.zip -d ${{ runner.temp }}\jbr
          echo "JAVA_HOME=${{ runner.temp }}\jbr\jbrsdk-21.0.7-windows-x64-b1034.51" >> $env:GITHUB_ENV

      - uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: ${{ runner.os }}-${{ runner.arch }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
          restore-keys: |
            ${{ runner.os }}-${{ runner.arch }}-gradle-

      # test build
      - run: |
          .\gradlew classes -x test --no-daemon
          .\gradlew clean --no-daemon

      # dist
      - run: |
          .\gradlew.bat dist --no-daemon
          .\gradlew.bat --stop

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: termora-windows-x86-64
          path: |
            build/distributions/*.zip
            build/distributions/*.exe
