name: 'Docker Non-Bazel Run'
description: 'Run a docker image for Protobuf CI testing with a non-Bazel build system'
inputs:
  credentials:
    required: true
    description: "The GCP credentials to use for reading the docker image"
    type: string
  command:
    required: true
    description: A command to run in the docker image
  image:
    required: false
    default: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-aec4d74f2eb6938fc53ef7d9a79a4bf2da24abc1
    description: "The docker image to use"
    type: string
  platform:
    required: false
    description: "The platform to use for the image"
    type: string
  skip-staleness-check:
    required: false
    description: "Skip staleness checks"
    type: boolean

runs:
  using: 'composite'
  steps:
    - name: Setup Runner
      uses: ./.github/actions/internal/setup-runner

    - name: Update stale files using Bazel
      if: ${{ !inputs.skip-staleness-check }}
      uses: ./.github/actions/bazel-docker
      with:
        image: us-docker.pkg.dev/protobuf-build/containers/common/linux/bazel:5.1.1-aec4d74f2eb6938fc53ef7d9a79a4bf2da24abc1
        credentials: ${{ inputs.credentials }}
        bazel-cache: regenerate-stale-files
        bash: ./regenerate_stale_files.sh $BAZEL_FLAGS

    - name: Generate docker flags
      if: inputs.platform
      shell: bash
      run: echo "DOCKER_RUN_FLAGS=--platform ${{inputs.platform}}" >> $GITHUB_ENV

    - name: Run Docker
      uses: ./.github/actions/internal/docker-run
      with:
        image: ${{ inputs.image }}
        command: ${{ inputs.command }}
        run-flags: ${{ env.DOCKER_RUN_FLAGS }}
