如何在.yaml中为部署谷歌云功能的Github操作定义主题触发器?
使用http(默认值(的工作文件是:
# This is a basic workflow to help you get started with Actions
name: CD
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "deploy"
deploy:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Add "id-token" with the intended permissions.
permissions:
contents: "read"
id-token: "write"
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- id: "auth"
name: "Authenticate to Google Cloud"
uses: "google-github-actions/auth@v0"
with:
# Replace with your Workload Identity Provider Location
workload_identity_provider: "${PROJECT_VALUE}"
# Replace with your GitHub Service Account
service_account: "github-actions-service-account@${PROJECT_NAME}.iam.gserviceaccount.com"
- id: "deploy"
uses: "google-github-actions/deploy-cloud-functions@v0"
with:
# Name of the Cloud Function, same as the entry point name
name: "${FUNCTION_NAME}"
# Runtime to use for the function
runtime: "nodejs16"
此线程有一些建议,但获取主题ID不清楚https://github.com/google-github-actions/deploy-cloud-functions/issues/5
添加以下作品
- id: "deploy"
uses: "google-github-actions/deploy-cloud-functions@v0"
with:
# Name of the Cloud Function, same as the entry point name
name: "${FUNCTION_NAME}"
# Runtime to use for the function
runtime: "nodejs16"
event_trigger_type: "google.pubsub.topic.publish"
event_trigger_resource: "projects/${PROJECT_VALUE}/topics/${TOPIC_ID}" //ie the string identifying the topic
event_trigger_service: "pubsub.googleapis.com"
最后一个问题是,在部署了带有http触发器的GCF后,必须删除该GCF才能成功部署