我有一些属于同一 API 系统的 GCP Cloud Functions,因此我将它们分组在同一个 GitHub 存储库中。
我的整个设置如下:
GitHub 存储库: 所有 API 云函数所在的真相来源。
/src
内Typescript中的所有函数以及编译好的JS到/out
镜像 GCP 云源存储库: 相同的 GitHub 存储库数据,但在 GCP 上(这对于云功能来说是必需的)
GCP Cloud Functions: 将其
Source
设置为 Cloud Source Repo
,将其 Directory with source code
设置为 GitHub 存储库中包名称的 /out
目录中的已编译 JS 以及他们自己的 Entry point
。例如:
func1
func2
云构建触发器:监听具有此
master
文件的GitHub存储库.yaml
分支的更改:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'functions'
- 'deploy'
- '--trigger-http'
- '--entry-point'
- 'func1'
- '--runtime'
- 'nodejs20'
dir: 'out/func-1'
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'functions'
- 'deploy'
- '--trigger-http'
- '--entry-point'
- 'func2'
- '--runtime'
- 'nodejs20'
dir: 'out/func-2'
问题是,当我推到
master
时,我正在重新部署所有功能,无论一个功能是否更改,而另一个功能没有更改。流程是这样的:
master
分支master
分支已更新,所以 Cloud Source Repo
的 master
分支也已更新,因为它是镜像的。master
分支已更新,因此会触发 Cloud Build 触发器并运行 .yaml
的命令,该命令使用 Cloud Source Repo
所以我的问题是在步骤 3 上,如何设置
.yaml
文件以仅更改 PR 中更改的功能?还有其他方法可以解决这个问题吗?也许是 Cloud Build 的 GitHub 操作或替换变量?也不知道如何设置。
我真的很想保留设置,因此所有相关的云功能都保留在同一个存储库中。