name: 'Setup Gradle'
description: 'Checks out the repository and sets up Java and Gradle'
inputs:
  token:
    description: 'token input for actions/checkout'
    required: false
    default: ${{ github.token }}
  fetch-depth:
    description: 'fetch-depth input for actions/checkout'
    required: false
    default: 1
  cache-read-only:
    description: 'cache-read-only input for gradle/actions/setup-gradle'
    required: false
    default: ${{ github.event.repository != null && github.ref_name != github.event.repository.default_branch }}
  dependency-graph:
    description: 'dependency-graph input for gradle/actions/setup-gradle'
    required: false
    default: 'disabled'
  persist-credentials:
    description: 'Control the actions/checkout persist-credentials setting'
    required: false
    default: false
runs:
  using: "composite"
  steps:
    - name: Checkout repository
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      with:
        fetch-depth: ${{ inputs.fetch-depth }}
        token: ${{ inputs.token }}
        lfs: true
        persist-credentials: ${{ inputs.persist-credentials }}

    - name: Validate Gradle wrapper
      uses: gradle/actions/wrapper-validation@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6

    - name: Set up JDK
      uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
      with:
        distribution: temurin
        java-version: 25

    - name: Accept Android SDK licenses
      shell: bash
      run: |
        yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses || true

    - name: Set global Gradle properties
      shell: bash
      run: |
        mkdir -p ~/.gradle/
        echo "android.testoptions.manageddevices.emulator.gpu=swiftshader_indirect" >> ~/.gradle/gradle.properties

    - name: Setup Gradle
      uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6
      with:
        add-job-summary: always
        cache-read-only: ${{ inputs.cache-read-only }}
        dependency-graph: ${{ inputs.dependency-graph }}
        validate-wrappers: true
