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, andsource_dir. - Enable
gen2: trueand 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-central1Gotchas
- 2nd gen functions need the Cloud Run, Cloud Build, and Artifact Registry APIs enabled.
- The build account needs
roles/cloudfunctions.developerplus Artifact Registry write access.
Related guides
How to Deploy a Pub/Sub-Triggered Cloud Function With GitHub ActionsDeploy a Cloud Function triggered by a Pub/Sub topic from GitHub Actions with gcloud functions deploy --trigg…
How to Deploy a Container to Cloud Run From Source in GitHub ActionsBuild and deploy to Cloud Run straight from source in GitHub Actions with gcloud run deploy --source, letting…