name: Windows

on: [ push, pull_request ]

jobs:
  build:
    env:
      android-version: 26
    runs-on: windows-latest
    strategy:
      fail-fast: true
      matrix:
        java_version: [ 11, 14 ]

    steps:
      - uses: actions/checkout@v2
      - name: "Set up JDK ${{ matrix.java_version }}"
        uses: actions/setup-java@v1
        with:
          java-version: ${{ matrix.java_version }}

      - name: build
        run: ./gradlew build

      - name: Cache android jar
        id: android-cache
        uses: actions/cache@v1
        with:
          path: android-jar-cache
          key: ${{ runner.os }}-android-version-${{ env.android-version }}

      - name: download Android SDK's android.jar (or use cached file)
        if: steps.android-cache.outputs.cache-hit != 'true'
        run: |
          md android-jar-cache
          cd android-jar-cache
          curl -o android.jar -L "https://github.com/Sable/android-platforms/blob/master/android-${{ env.android-version }}/android.jar?raw=true"
          $file_sha256 = $(certutil -hashfile android.jar sha256)[1] -replace " ",""
          $expected_sha256 = "cdc1846376a14b0370cc63454a129606b4a52cc50ada75ef0d4cf956b1ad2daa"
          if ($file_sha256 -Ne $expected_sha256) {
              echo "wrong sha256 for android.jar: $file_sha256";
              echo "                    expected: $expected_sha256";
              exit -1
          }

      - name: check Atrium's -android.jar can be dexed
        run: ATRIUM_ANDROID_JAR="$PWD/android-jar-cache/android.jar" ./gradlew checkDexer
        shell: bash

      # TODO 0.18.0 re-activate scala API
      #            -   name: composite build atrium-scala2
      #                run: ./gradlew build
      #                working-directory: misc\tools\atrium-scala2-test

      - name: Upload windows build code coverage
        uses: codecov/codecov-action@v1
        if: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/master') }}
        env:
          JAVA_VERSION: ${{ matrix.java_version }}
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          flags: current_windows
          env_vars: JAVA_VERSION
          # too many timeout errors, let's not fail at the moment
          #fail_ci_if_error: true

      - name: composite build atrium-samples-test
        run: ./gradlew build
        working-directory: misc\tools\atrium-samples-test

      - name: composite build atrium-js-sample-test
        run: ./gradlew build
        working-directory: misc\tools\atrium-js-sample-test
