name: Reusable - Test latest deps

on:
  workflow_call:
    inputs:
      skip:
        type: boolean
        required: false
      cache-read-only:
        type: boolean
        required: false
      no-build-cache:
        type: boolean
        required: false
    secrets:
      GRADLE_ENTERPRISE_ACCESS_KEY:
        required: false
      GE_CACHE_USERNAME:
        required: false
      GE_CACHE_PASSWORD:
        required: false

jobs:
  test-latest-deps:
    # the condition is on the steps below instead of here on the job, because skipping the job
    # causes the job to show up as canceled in the GitHub UI which prevents the build section from
    # collapsing when everything (else) is green
    #
    # and the name is updated when the steps below are skipped which makes what's happening clearer
    # in the GitHub UI
    name: testLatestDeps${{ inputs.skip && ' (skipped)' || '' }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up JDK for running Gradle
        if: ${{ !inputs.skip }}
        uses: actions/setup-java@v2
        with:
          distribution: temurin
          java-version: 17

      # vaadin tests use pnpm
      - name: Cache pnpm modules
        uses: actions/cache@v2
        with:
          path: ~/.pnpm-store
          key: ${{ runner.os }}-test-latest-cache-pnpm-modules

      - name: Test
        if: ${{ !inputs.skip }}
        uses: gradle/gradle-build-action@v2
        env:
          GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
          GE_CACHE_USERNAME: ${{ secrets.GE_CACHE_USERNAME }}
          GE_CACHE_PASSWORD: ${{ secrets.GE_CACHE_PASSWORD }}
        with:
          arguments: test -PtestLatestDeps=true ${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
          # testLatestDeps dependencies bundle is over 2gb, which causes restoring it to fail with:
          #     RangeError [ERR_OUT_OF_RANGE]: The value of "length" is out of range.
          #     It must be >= 0 && <= 2147483647. Received 2299528741
          cache-read-only: true
