An example workflow that uses GitHub Actions to deploy a Hello World Python app to Cloud Funtions.
This code is intended to be an example. You will likely need to change or update values to match your setup.
For pushes to the main
branch, this workflow will:
-
Set up job
- Current runner version: '2.275.1'
- Operating System (Ubuntu 18.04.5)
- Virtual Environment
- Prepare workflow directory
- Prepare all required actions
- Getting action download info
- Download action repository 'actions/checkout@v2'
- Download action repository 'google-github-actions/deploy-cloud-functions@main'
-
Checkout Github Repo
- Run actions/checkout@v2
- Getting Git version info
- Initializing the repository
- Setting up auth
- Fetching the repository
- Checking out the ref
-
Run google-github-actions/deploy-cloud-functions
- Setting project Id from $GCLOUD_PROJECT
- Creating a function revision
- Creating or Updating function deployment
-
Run curl to the URL of the deployed Cloud Function service
-
Create a new Google Cloud Project (or select an existing project) and enable the Cloud Functions APIs.
-
Create a Google Cloud service account if one does not already exist.
-
Add the the following Cloud IAM roles to your service account:
Cloud Functions Admin
- allows for the creation of new functions
-
Download a JSON service account key for the service account.
-
Add the following secrets to your repository's secrets:
GCP_SA_KEY
: the downloaded service account key
-
Add and commit your changes:
$ git add . $ git commit -m "Set up GitHub workflow"
-
Push to the
main
branch:$ git push -u origin main
-
View the GitHub Actions Workflow by selecting the
Actions
tab at the top of your repository on GitHub. Then click on theBuild and Deploy to Cloud Run
element to see the details.