name: GCP login
description: "Login to GCP & configure gcloud CLI."
inputs:
  service_account:
    description: "GCP service account name. Format: <account-name>@<project-name>.iam.gserviceaccount.com"
    required: true
runs:
  using: "composite"
  steps:
    - name: Clean env to prevent warnings
      shell: bash
      run: |
        echo "CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE=" >> "$GITHUB_ENV"
        echo "GOOGLE_APPLICATION_CREDENTIALS=" >> "$GITHUB_ENV"
        echo "GOOGLE_GHA_CREDS_PATH=" >> "$GITHUB_ENV"
        echo "CLOUDSDK_CORE_PROJECT=" >> "$GITHUB_ENV"
        echo "CLOUDSDK_PROJECT=" >> "$GITHUB_ENV"
        echo "GCLOUD_PROJECT=" >> "$GITHUB_ENV"
        echo "GCP_PROJECT=" >> "$GITHUB_ENV"
        echo "GOOGLE_CLOUD_PROJECT=" >> "$GITHUB_ENV"

    # As described at:
    # https://github.com/google-github-actions/setup-gcloud#service-account-key-json
    - name: Authorize GCP access
      uses: google-github-actions/auth@35b0e87d162680511bf346c299f71c9c5c379033 # v1.1.1
      with:
        workload_identity_provider: projects/796962942582/locations/global/workloadIdentityPools/constellation-ci-pool/providers/constellation-ci-provider
        service_account: ${{ inputs.service_account }}

    # Even if preinstalled in Github Actions runner image, this setup does some magic authentication required for gsutil.
    - name: Set up Cloud SDK
      uses: google-github-actions/setup-gcloud@e30db14379863a8c79331b04a9969f4c1e225e0b # v1.1.1
