Convert Figma logo to code with AI

google-github-actions logosetup-gcloud

A GitHub Action for installing and configuring the gcloud CLI.

1,857
522
1,857
1

Top Related Projects

Configure AWS credential environment variables for use in other GitHub Actions.

Sets up Terraform CLI in your GitHub Actions workflow.

Quick Overview

The google-github-actions/setup-gcloud repository is a GitHub Action that sets up the Google Cloud SDK (gcloud CLI) in your GitHub Actions workflow. It allows you to authenticate with Google Cloud Platform (GCP) and use gcloud commands in your CI/CD pipelines, enabling seamless integration with GCP services.

Pros

  • Easy integration with GitHub Actions workflows
  • Simplifies authentication with Google Cloud Platform
  • Supports multiple authentication methods (service account key, workload identity federation)
  • Regularly updated to support the latest gcloud CLI features

Cons

  • Limited to GitHub Actions environment (not usable in other CI/CD platforms)
  • Requires careful handling of credentials to maintain security
  • May add some overhead to workflow execution time
  • Dependent on Google Cloud SDK updates and potential breaking changes

Getting Started

To use the google-github-actions/setup-gcloud action in your workflow, add the following step to your GitHub Actions workflow file:

- uses: google-github-actions/setup-gcloud@v1
  with:
    project_id: ${{ secrets.GCP_PROJECT_ID }}
    service_account_key: ${{ secrets.GCP_SA_KEY }}
    export_default_credentials: true

Replace ${{ secrets.GCP_PROJECT_ID }} with your Google Cloud project ID and ${{ secrets.GCP_SA_KEY }} with your service account key (stored as a GitHub secret). This setup authenticates the gcloud CLI and sets the default project for subsequent steps in your workflow.

For more advanced usage and configuration options, refer to the official documentation in the repository's README.

Competitor Comparisons

Configure AWS credential environment variables for use in other GitHub Actions.

Pros of configure-aws-credentials

  • Supports assuming IAM roles, allowing for more granular access control
  • Provides automatic credential rotation, enhancing security
  • Integrates seamlessly with other AWS-specific actions in GitHub workflows

Cons of configure-aws-credentials

  • Limited to AWS services, lacking cross-cloud flexibility
  • Requires more setup steps compared to setup-gcloud
  • May have a steeper learning curve for users new to AWS IAM concepts

Code Comparison

setup-gcloud:

- uses: google-github-actions/setup-gcloud@v0
  with:
    project_id: ${{ secrets.GCP_PROJECT_ID }}
    service_account_key: ${{ secrets.GCP_SA_KEY }}
    export_default_credentials: true

configure-aws-credentials:

- uses: aws-actions/configure-aws-credentials@v1
  with:
    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    aws-region: us-east-2

Both actions serve similar purposes for their respective cloud platforms, setting up authentication for CI/CD workflows. setup-gcloud focuses on Google Cloud Platform, while configure-aws-credentials is tailored for Amazon Web Services. The choice between them depends on the cloud provider being used and the specific requirements of the project.

Sets up Terraform CLI in your GitHub Actions workflow.

Pros of setup-terraform

  • Specifically designed for Terraform workflows, offering tailored features
  • Supports multiple Terraform versions and automatic version detection
  • Integrates seamlessly with other HashiCorp products

Cons of setup-terraform

  • Limited to Terraform-specific tasks, less versatile for general cloud operations
  • May require additional setup for non-HashiCorp cloud providers

Code Comparison

setup-gcloud:

- uses: google-github-actions/setup-gcloud@v0
  with:
    project_id: ${{ secrets.GCP_PROJECT_ID }}
    service_account_key: ${{ secrets.GCP_SA_KEY }}
    export_default_credentials: true

setup-terraform:

- uses: hashicorp/setup-terraform@v1
  with:
    terraform_version: 0.14.x
    cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}

Key Differences

  • setup-gcloud focuses on Google Cloud Platform setup and authentication
  • setup-terraform is tailored for Terraform workflows across various cloud providers
  • setup-gcloud offers more GCP-specific features, while setup-terraform provides Terraform-centric functionality

Use Cases

  • Choose setup-gcloud for GCP-specific projects and workflows
  • Opt for setup-terraform when working primarily with Terraform across multiple cloud providers

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

setup-gcloud GitHub Action

Configures the Google Cloud SDK in the GitHub Actions environment. The Google Cloud SDK includes both the gcloud and gsutil binaries.

Or integrate natively with other Google Cloud GitHub Actions:

This is not an officially supported Google product, and it is not covered by a Google Cloud support contract. To report bugs or request features in a Google Cloud product, please contact Google Cloud support.

Prerequisites

  • This action requires Google Cloud credentials to execute gcloud commands. See Authorization for more details.

  • This action runs using Node 24. If you are using self-hosted GitHub Actions runners, you must use a runner version that supports this version or newer.

Usage

jobs:
  job_id:
    # Add "id-token" with the intended permissions.
    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
    - id: 'auth'
      uses: 'google-github-actions/auth@v2'
      with:
        workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
        service_account: 'my-service-account@my-project.iam.gserviceaccount.com'

    - name: 'Set up Cloud SDK'
      uses: 'google-github-actions/setup-gcloud@v3'
      with:
        version: '>= 363.0.0'

    - name: 'Use gcloud CLI'
      run: 'gcloud info'

Inputs

  • version: (Optional, default: latest) A string representing the version or version constraint of the Cloud SDK (gcloud) to install (e.g. "290.0.1" or ">= 197.0.1"). The default value is "latest", which will always download and install the latest available Cloud SDK version.

    - uses: 'google-github-actions/setup-gcloud@v3'
      with:
        version: '>= 416.0.0'
    

    If there is no installed gcloud version that matches the given constraint, this GitHub Action will download and install the latest available version that still matches the constraint.

    Authenticating via Workload Identity Federation requires version 363.0.0 or newer. If you need support for Workload Identity Federation, specify your version constraint as such:

    - uses: 'google-github-actions/setup-gcloud@v3'
      with:
        version: '>= 363.0.0'
    

    You are responsible for ensuring the gcloud version matches the features and components required.

  • project_id: (Optional) ID of the Google Cloud project. If provided, this will configure gcloud to use this project ID by default for commands. Individual commands can still override the project using the --project flag which takes precedence. If unspecified, the action attempts to find the "best" project ID by looking at other inputs and environment variables.

  • install_components: (Optional) List of additional gcloud components to install, specified as a comma-separated list of strings:

    install_components: 'alpha,cloud-datastore-emulator'
    
  • skip_install: (Optional) Skip installation of gcloud and use the system-supplied version instead. If specified, the version input is ignored.

    ⚠️ You will not be able to install additional gcloud components, because the system installation is locked.

  • cache: (Optional) Transfer the downloaded artifacts into the runner's tool cache. On GitHub-managed runners, this have very little impact since runneres are ephemeral. On self-hosted runners, this could improve future runs by skipping future gcloud installations.

Outputs

  • version: Version of gcloud that was installed.

Authorization

The setup-gcloud action installs the Cloud SDK (gcloud). To configure its authentication to Google Cloud, you must first use the google-github-actions/auth action. The auth action sets Application Default Credentials, then the setup-gcloud action references these credentials to configure gcloud credentials . You can authenticate via the following options:

Workload Identity Federation (preferred)

⚠️ You must use the Cloud SDK version 390.0.0 or later to authenticate the bq and gsutil tools.

jobs:
  job_id:
    # Add "id-token" with the intended permissions.
    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
    - id: 'auth'
      uses: 'google-github-actions/auth@v2'
      with:
        workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
        service_account: 'my-service-account@my-project.iam.gserviceaccount.com'

    - name: 'Set up Cloud SDK'
      uses: 'google-github-actions/setup-gcloud@v3'

    - name: 'Use gcloud CLI'
      run: 'gcloud info'

Service Account Key JSON

jobs:
  job_id:
    steps:
    - id: 'auth'
      uses: 'google-github-actions/auth@v2'
      with:
        credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

    - name: 'Set up Cloud SDK'
      uses: 'google-github-actions/setup-gcloud@v3'

    - name: 'Use gcloud CLI'
      run: 'gcloud info'

Self-hosted runners on Google Cloud Platform

If you are using self-hosted runners that are hosted on Google Cloud Platform, credentials are automatically obtained from the service account attached to the runner. In this scenario, you do not need to run the google-github-actions/auth action.

jobs:
  job_id:
    steps:
    - name: 'Set up Cloud SDK'
      uses: 'google-github-actions/setup-gcloud@v3'

    - name: 'Use gcloud CLI'
      run: 'gcloud info'

Multiple Service Accounts

To use multiple service accounts, a second auth step is required to update the credentials before using setup-gcloud:

jobs:
  job_id:
    # Add "id-token" with the intended permissions.
    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
      - id: 'auth service account 1'
        uses: 'google-github-actions/auth@v2'
        with:
          workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider'
          service_account: 'service-account-1@my-project.iam.gserviceaccount.com'

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v3'

      - name: 'Use gcloud CLI'
        run: 'gcloud auth list --filter=status:ACTIVE --format="value(account)"'
        # service-account-1@my-project.iam.gserviceaccount.com

      - id: 'auth service account 2'
        uses: 'google-github-actions/auth@v2'
        with:
          credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

      - name: 'Set up Cloud SDK'
        uses: 'google-github-actions/setup-gcloud@v3'

      - name: 'Use gcloud CLI'
        run: 'gcloud auth list --filter=status:ACTIVE --format="value(account)"'
        # service-account-2@my-project.iam.gserviceaccount.com

Versioning

We recommend pinning to the latest available major version:

- uses: 'google-github-actions/setup-gcloud@v3'

While this action attempts to follow semantic versioning, but we're ultimately human and sometimes make mistakes. To prevent accidental breaking changes, you can also pin to a specific version:

- uses: 'google-github-actions/setup-gcloud@v3.0.0'

However, you will not get automatic security updates or new features without explicitly updating your version number. Note that we only publish MAJOR and MAJOR.MINOR.PATCH versions. There is not a floating alias for MAJOR.MINOR.