name: Rhino CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      # Some tests require more CPU, and all can use multiple CPUs
      max-parallel: 1
      matrix:
        java: [ '8', '11', '17' ]
    name: Rhino Java ${{ matrix.java }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        # Need all history or spotless check will fail
        fetch-depth: 0
    - name: Check out test262
      # We don't actually want all the history for this part
      run: git submodule update --init --single-branch
    - name: Set up Java
      uses: actions/setup-java@v2
      with:
        java-version: ${{ matrix.java }}
        distribution: 'adopt'
    - if: matrix.java == '8'
      name: Check everything with Gradle on Java 8
      run: ./gradlew check jacocoTestReport
    - if: matrix.java != '8'
      name: Check everything with Gradle, modular Java
      run: >-
        ./gradlew check jacocoTestReport
        -Dorg.gradle.jvmargs="--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
        --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
        --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
        --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
        --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
    - name: Upload results
      uses: actions/upload-artifact@v2
      with:
        name: reports
        path: buildGradle/reports

