name: "Setup Bazel Caching"
description: "Sets up Bazel caching"
inputs:
  cache_url:
    description: "URL of the Bazel cache to read/write"
    required: false
    default: https://storage.googleapis.com/protobuf-bazel-cache/upb
  read_only:
    description: "If true, we can read from the cache but not write it."
    required: false
    default: ${{ github.event.pull_request.head.repo.full_name != 'protocolbuffers/upb' }}
outputs:
  cache_args:
    description: "Caching related arguments to pass to 'bazel build"
    value: --remote_cache=${{ inputs.cache_url }} ${{ steps.set_auth_arg.outputs.auth_arg }}
runs:
  using: "composite"
  steps:
    - id: set_auth_arg
      run: echo auth_arg=${{ inputs.read_only == 'true' && '--remote_upload_local_results=false' || '--google_default_credentials' }} >> $GITHUB_OUTPUT
      shell: bash
