2024-08-21 11:21:42 -07:00
# This workflow will deploy source code on Cloud Run when a commit is pushed to
# the $default-branch branch.
2022-03-16 15:00:00 -04:00
#
# To configure this workflow:
#
2024-08-21 11:21:42 -07:00
# 1. Enable the following Google Cloud APIs:
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# - Artifact Registry (artifactregistry.googleapis.com)
# - Cloud Build (cloudbuild.googleapis.com)
# - Cloud Run (run.googleapis.com)
# - IAM Credentials API (iamcredentials.googleapis.com)
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# You can learn more about enabling APIs at
# https://support.google.com/googleapi/answer/6158841.
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# 2. Create and configure a Workload Identity Provider for GitHub:
# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation.
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# Depending on how you authenticate, you will need to grant an IAM principal
# permissions on Google Cloud:
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# - Artifact Registry Administrator (roles/artifactregistry.admin)
# - Cloud Run Source Developer (roles/run.sourceDeveloper)
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# You can learn more about setting IAM permissions at
# https://cloud.google.com/iam/docs/manage-access-other-resources.
2022-03-16 15:00:00 -04:00
#
2024-08-21 11:21:42 -07:00
# 3. Change the values in the "env" block to match your values.
2022-03-16 15:00:00 -04:00
2024-08-21 11:21:42 -07:00
name : 'Deploy to Cloud Run from Source'
2022-03-16 15:00:00 -04:00
on :
push :
2024-08-21 11:21:42 -07:00
branches :
- '$default-branch'
2022-03-16 15:00:00 -04:00
env :
2024-08-21 11:21:42 -07:00
PROJECT_ID: 'my-project' # TODO : update to your Google Cloud project ID
REGION: 'us-central1' # TODO : update to your region
SERVICE: 'my-service' # TODO : update to your service name
2022-03-16 15:00:00 -04:00
jobs :
deploy :
2024-08-21 11:21:42 -07:00
runs-on : 'ubuntu-latest'
2022-03-16 15:00:00 -04:00
permissions :
contents : 'read'
id-token : 'write'
steps :
2024-08-21 11:21:42 -07:00
- name : 'Checkout'
uses : 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' # actions/checkout@v4
2022-03-16 15:00:00 -04:00
2024-08-21 11:21:42 -07:00
# Configure Workload Identity Federation and generate an access token.
#
# See https://github.com/google-github-actions/auth for more options,
# including authenticating via a JSON credentials file.
- id : 'auth'
name : 'Authenticate to Google Cloud'
uses : 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' # google-github-actions/auth@v2
2022-03-16 15:00:00 -04:00
with :
2024-08-21 11:21:42 -07:00
workload_identity_provider: 'projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider' # TODO : replace with your workload identity provider
2022-03-16 15:00:00 -04:00
2024-08-21 11:21:42 -07:00
- name : 'Deploy to Cloud Run'
uses : 'google-github-actions/deploy-cloudrun@33553064113a37d688aa6937bacbdc481580be17' # google-github-actions/deploy-cloudrun@v2
2022-03-16 15:00:00 -04:00
with :
2024-08-21 11:21:42 -07:00
service : '${{ env.SERVICE }}'
region : '${{ env.REGION }}'
# NOTE: If using a different source folder, update the image name below:
source : './'
2022-03-16 15:00:00 -04:00
2024-08-21 11:21:42 -07:00
# If required, use the Cloud Run URL output in later steps
- name : 'Show output'
run : |-
echo ${{ steps.deploy.outputs.url }}