Skip to content
Latchkey

How to Deploy a 2nd Gen Cloud Function With GitHub Actions

deploy-cloud-functions builds and deploys a 2nd gen function, which runs on Cloud Run under the hood.

Authenticate via WIF, then use google-github-actions/deploy-cloud-functions with runtime, entry_point, and a trigger. Set gen2: true for the 2nd gen environment.

Steps

  • Authenticate via WIF.
  • Set name, runtime, entry_point, and source_dir.
  • Enable gen2: true and choose an HTTP or event trigger.

Workflow

.github/workflows/deploy.yml
permissions:
  id-token: write
  contents: read
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: google-github-actions/auth@v2
        with:
          workload_identity_provider: ${{ vars.WIF_PROVIDER }}
          service_account: ${{ vars.DEPLOY_SA }}
      - uses: google-github-actions/deploy-cloud-functions@v3
        with:
          name: api
          runtime: nodejs20
          entry_point: handler
          source_dir: ./functions
          region: us-central1

Gotchas

  • 2nd gen functions need the Cloud Run, Cloud Build, and Artifact Registry APIs enabled.
  • The build account needs roles/cloudfunctions.developer plus Artifact Registry write access.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →