### Start Cloud Datastore emulator Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Example of starting the Cloud Datastore emulator using an installed beta component. ```bash - name: 'Start Cloud Datastore emulator' run: 'gcloud beta emulators datastore start --host-port=localhost:8081 &' ``` -------------------------------- ### Run Main Action Entry Point (TypeScript) Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt The exported run() async function is the sole entry point of the action. It orchestrates all setup logic, including reading inputs, resolving/installing the SDK version, populating the tool cache path, installing components, wiring authentication, and setting the default project. Errors are caught and forwarded to core.setFailed. ```typescript import { run } from './src/main'; // Called automatically when the action executes (require.main === module). // Internally performs the following sequence: // 1. Export CLOUDSDK_METRICS_ENVIRONMENT env vars // 2. Parse inputs: version, install_components, project_id, skip_install, cache // 3. Resolve version (handles '', 'latest', semver constraint) // 4. Check tool cache; call installGcloudSDK(version, cache) on cache miss // 5. Install comma-separated components via installComponent([]) // 6. Authenticate via GOOGLE_GHA_CREDS_PATH → authenticateGcloudSDK(credFile) // OR emit a warning if gcloud is not authenticated // 7. Set default project via setProject(projectId) // 8. Output resolved version string await run(); // On success: sets output `version` to the installed version string // On failure: calls core.setFailed("google-github-actions/setup-gcloud failed with: ") ``` -------------------------------- ### Use installed alpha gcloud commands Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Example of using a gcloud command from an additionally installed component (e.g., 'alpha'). ```bash - name: 'Use alpha commands' run: 'gcloud alpha run services list' ``` -------------------------------- ### Set up Cloud SDK and echo version Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Installs the Cloud SDK and captures the exact version for use in subsequent steps. ```yaml - name: 'Set up Cloud SDK' id: 'setup-gcloud' uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 416.0.0' - name: 'Echo installed version' run: | echo "Installed version: ${{ steps.setup-gcloud.outputs.version }}" # Example output: Installed version: 503.0.0 ``` -------------------------------- ### List services in the default project Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Example of a gcloud command that targets the project configured by the `project_id` input. ```bash - name: 'List Cloud Run services in default project' run: 'gcloud run services list --region=us-central1' # Equivalent to: gcloud run services list --region=us-central1 --project=my-gcp-project-123 ``` -------------------------------- ### Install Additional gcloud Components Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Use the `install_components` input to specify a comma-separated list of additional gcloud components to install. ```yaml install_components: 'alpha,cloud-datastore-emulator' ``` -------------------------------- ### Use system-provided gcloud installation Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Skips SDK installation and uses the gcloud version pre-installed on the runner. The `version` input is ignored. ```yaml - name: 'Set up Cloud SDK (skip install)' uses: 'google-github-actions/setup-gcloud@v3' with: skip_install: true ``` -------------------------------- ### Install additional gcloud SDK components Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Installs specified gcloud components alongside the base SDK. This cannot be used with `skip_install: true`. ```yaml - name: 'Set up Cloud SDK with components' uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 363.0.0' install_components: 'alpha,beta,cloud-datastore-emulator,cloud-run-proxy' ``` -------------------------------- ### Install gcloud SDK with version constraint Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Install a gcloud SDK version that meets a minimum semver constraint. Recommended for WIF support. ```yaml - name: 'Set up Cloud SDK (constraint)' uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 363.0.0' ``` -------------------------------- ### Skip gcloud Installation Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Set `skip_install` to `true` to use the system-supplied gcloud version instead of installing a new one. The `version` input is ignored in this case, and additional components cannot be installed. ```yaml skip_install: 'true' ``` -------------------------------- ### Configure Google Cloud SDK in GitHub Actions Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md This example demonstrates how to set up the Google Cloud SDK using the setup-gcloud action. It includes authentication with Workload Identity Federation and a basic gcloud command execution. ```yaml 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' ``` -------------------------------- ### Install gcloud SDK with exact version Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Use this to pin to a specific gcloud SDK version. If the version is already cached, it will be reused. ```yaml - name: 'Set up Cloud SDK (exact)' uses: 'google-github-actions/setup-gcloud@v3' with: version: '374.0.0' ``` -------------------------------- ### Verify system gcloud installation Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Confirms that the system-provided gcloud binary is accessible after setting `skip_install: true`. ```bash - name: 'Use system gcloud' run: 'gcloud info' ``` -------------------------------- ### Install latest gcloud SDK version Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Always install the newest available gcloud SDK release. The action will automatically use cached versions if available. ```yaml - name: 'Set up Cloud SDK (latest)' uses: 'google-github-actions/setup-gcloud@v3' with: version: 'latest' ``` -------------------------------- ### Output installed gcloud SDK version Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt The action exports the resolved gcloud SDK version to the `version` output, which can be accessed in subsequent steps. ```bash - name: 'Print installed version' run: echo "Installed gcloud ${{ steps.setup.outputs.version }}" ``` -------------------------------- ### Authenticate Multiple Service Accounts Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md To use multiple service accounts, run the auth action sequentially for each account before setting up the Cloud SDK. This example demonstrates authenticating two different accounts. ```yaml 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 ``` -------------------------------- ### Specify gcloud SDK Version Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Use the `version` input to specify a version or version constraint for the Cloud SDK. If no installed version matches, the latest matching version will be downloaded. ```yaml - uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 416.0.0' ``` -------------------------------- ### Setup Cloud SDK on Self-hosted GCP Runners Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md For self-hosted runners on Google Cloud Platform, credentials are automatically obtained from the attached service account. No explicit auth action is needed. ```yaml jobs: job_id: steps: - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v3' - name: 'Use gcloud CLI' run: 'gcloud info' ``` -------------------------------- ### Set up Cloud SDK with caching Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Enable caching for the downloaded SDK to speed up repeated runs on self-hosted runners. ```yaml - name: 'Set up Cloud SDK with caching' uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 416.0.0' cache: true ``` -------------------------------- ### Handle Multiple Service Accounts in a Single Job Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Switch active credentials by running a second `auth` step before each `setup-gcloud` invocation. ```yaml jobs: multi-account: permissions: contents: 'read' id-token: 'write' steps: - id: 'auth-sa1' 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 gcloud as SA1' uses: 'google-github-actions/setup-gcloud@v3' - run: | gcloud auth list --filter=status:ACTIVE --format="value(account)" # service-account-1@my-project.iam.gserviceaccount.com - id: 'auth-sa2' uses: 'google-github-actions/auth@v2' with: credentials_json: '${{ secrets.SA2_KEY_JSON }}' - name: 'Set up gcloud as SA2' uses: 'google-github-actions/setup-gcloud@v3' - run: | gcloud auth list --filter=status:ACTIVE --format="value(account)" # service-account-2@my-project.iam.gserviceaccount.com ``` -------------------------------- ### Pin setup-gcloud to Latest Major Version Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Pinning to the latest major version (e.g., @v3) ensures you receive updates and new features within that major release. ```yaml - uses: 'google-github-actions/setup-gcloud@v3' ``` -------------------------------- ### Override default project for a single command Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Demonstrates how to specify a different project for a single gcloud command, overriding the default set by the action. ```bash - name: 'Override project for a single command' run: 'gcloud run services list --region=us-central1 --project=other-project-456' ``` -------------------------------- ### Pin setup-gcloud to Specific Version Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Pinning to a specific version (e.g., @v3.0.0) provides stability but means you won't receive automatic security updates or new features without manual version updates. ```yaml - uses: 'google-github-actions/setup-gcloud@v3.0.0' ``` -------------------------------- ### Authenticate with Workload Identity Federation Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Use this snippet to authenticate using Workload Identity Federation. Ensure your Cloud SDK version is 390.0.0 or later. Requires 'id-token' permissions. ```yaml 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' ``` -------------------------------- ### Authenticate using Workload Identity Federation Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Recommended keyless authentication for GitHub Actions. Requires `id-token: write` permission and Cloud SDK version >= 390.0.0. ```yaml jobs: deploy: permissions: contents: 'read' id-token: 'write' steps: - uses: 'actions/checkout@v4' - id: 'auth' uses: 'google-github-actions/auth@v2' with: workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' service_account: 'deployer@my-project.iam.gserviceaccount.com' - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 390.0.0' - name: 'Deploy to Cloud Run' run: | gcloud run deploy my-service \ --image=gcr.io/my-project/my-image:latest \ --region=us-central1 \ --platform=managed ``` -------------------------------- ### Authenticate with Service Account Key JSON Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md Authenticate using a service account key JSON stored as a GitHub secret. This method is suitable when Workload Identity Federation is not an option. ```yaml 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' ``` -------------------------------- ### Authenticate using Service Account Key JSON Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Secret-based authentication requires storing the service account key JSON as a GitHub Actions secret. ```yaml jobs: deploy: steps: - id: 'auth' uses: 'google-github-actions/auth@v2' with: credentials_json: '${{ secrets.GCP_SA_KEY }}' - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v3' - name: 'Verify authentication' run: | gcloud auth list --filter=status:ACTIVE --format="value(account)" # Output: deployer@my-project.iam.gserviceaccount.com ``` -------------------------------- ### Configure gcloud for Workload Identity Federation Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md To enable Workload Identity Federation, ensure you specify a Cloud SDK version of 363.0.0 or newer. ```yaml - uses: 'google-github-actions/setup-gcloud@v3' with: version: '>= 363.0.0' ``` -------------------------------- ### Strict Pin for Reproducibility (YAML) Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt For stricter reproducibility, pin to a specific patch-level version. This ensures no automatic updates occur. ```yaml - uses: 'google-github-actions/setup-gcloud@v3.0.1' ``` -------------------------------- ### Cache gcloud Artifacts Source: https://github.com/google-github-actions/setup-gcloud/blob/main/README.md The `cache` input transfers downloaded artifacts to the runner's tool cache. This can speed up future runs on self-hosted runners by skipping re-installation. ```yaml cache: 'true' ``` -------------------------------- ### Set default project ID for gcloud commands Source: https://context7.com/google-github-actions/setup-gcloud/llms.txt Configure the default project for all subsequent gcloud commands in the workflow. Individual commands can still override this. ```yaml - name: 'Set up Cloud SDK with project' uses: 'google-github-actions/setup-gcloud@v3' with: project_id: 'my-gcp-project-123' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.