name: Test develocity injection

on:
  workflow_call:
    inputs:
      cache-key-prefix:
        type: string
        default: '0'
      runner-os:
        type: string
        default: '["ubuntu-latest"]'
      skip-dist:
        type: boolean
        default: false

env:
  SKIP_DIST: ${{ inputs.skip-dist }}
  GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: build-scan-publish-${{ inputs.cache-key-prefix }}

permissions:
  contents: read

jobs:
  build-scan-publish:
    strategy:
      fail-fast: false
      matrix:
        gradle: [current, 7.6.2, 6.9.4, 5.6.4]
        os: ${{fromJSON(inputs.runner-os)}}
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
      uses: actions/checkout@v4
    - name: Initialize integ-test
      uses: ./.github/actions/init-integ-test

    - name: Setup Java
      uses: actions/setup-java@v4
      with:
        distribution: temurin
        java-version: 11
    - name: Setup Gradle
      id: setup-gradle
      uses: ./setup-gradle
      with:
        cache-read-only: false # For testing, allow writing cache entries on non-default branches
        gradle-version: ${{ matrix.gradle }}
        build-scan-publish: true
        build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
        build-scan-terms-of-use-agree: "yes"
    - name: Run Gradle build
      id: gradle
      working-directory: .github/workflow-samples/no-ge
      run: gradle help
    - name: Check Build Scan url
      if: ${{ !steps.gradle.outputs.build-scan-url }}
      uses: actions/github-script@v7
      with:
        script: |
          core.setFailed('No Build Scan detected')   

