name: 'Cross-compile protoc'
description: 'Produces a cross-compiled protoc binary for a target architecture'
inputs:
  credentials:
    required: true
    description: The GCP credentials to use for reading the docker image
    type: string
  architecture:
    required: true
    description: The target architecture to build for
    type: string
outputs:
  protoc:
    description: "Cross-compiled protoc location.  Also output to $PROTOC"
    value: ${{ steps.output.outputs.protoc }}

runs:
  using: 'composite'
  steps:
    - name: Cross compile protoc for ${{ inputs.architecture }}
      uses: ./.github/actions/bazel-docker
      with:
        credentials: ${{ inputs.credentials }}
        bazel-cache: xcompile-protoc/${{ inputs.architecture }}
        bash: |
          bazel build //:protoc --config=${{ inputs.architecture }} $BAZEL_FLAGS
          cp bazel-bin/protoc .

    - name: Set protoc environment variable
      shell: bash
      run: echo "PROTOC=protoc-${{ inputs.architecture }}" >> $GITHUB_ENV

    - name: Extract binary
      id: output
      shell: bash
      run: |
        mv protoc $PROTOC
        echo "protoc=$PROTOC" >> $GITHUB_OUTPUT
