如何覆盖GitHub Actions或Cloud Build的[skip ci]逻辑?
解决方案
方法1:使用Cloud Build专属跳过关键词,避免影响GitHub Actions
Cloud Build支持自定义跳过构建的关键词,无需用通用的[skip ci],改用Cloud Build专属的[skip cloudbuild](或其他自定义关键词)即可:
- 配置Cloud Build触发器:在触发器的「构建配置」中,设置「跳过构建的关键词」为
[skip cloudbuild]。合并版本更新PR时,提交消息里写入该关键词,只会让Cloud Build跳过,GitHub Actions不会识别这个专属关键词,会正常触发运行。
方法2:强制GitHub Actions工作流忽略[skip ci]
如果必须使用[skip ci],可以在GitHub Actions的工作流文件中,通过条件判断强制工作流运行,不受[skip ci]影响:
on: push: branches: - main jobs: create-version-tag: # 强制运行该job,忽略commit消息中的[skip ci] if: true runs-on: ubuntu-latest steps: - name: 检出代码 uses: actions/checkout@v4 # 后续打标签等步骤...
也可以更精准地仅针对版本更新PR合并场景强制运行:
jobs: create-version-tag: # 当commit消息包含版本更新标识,或者无[skip ci]时运行 if: contains(github.event.head_commit.message, '版本更新') || !contains(github.event.head_commit.message, '[skip ci]') runs-on: ubuntu-latest steps: # ...
方法3:优化Cloud Build触发规则,自动排除版本更新PR
修改Cloud Build的触发器,添加过滤条件,让合并到main分支时,仅非版本更新的提交才触发构建:
- 基于文件路径过滤:如果版本更新仅修改特定文件(如
package.json、CHANGELOG.md),在触发器中设置「文件路径排除」,当仅这些文件变更时,不触发Cloud Build。 - 基于commit消息过滤:在触发器的「构建条件」中添加规则,当commit消息包含「版本更新」等特定标识时,跳过构建。
这种方式无需在提交消息中加任何跳过关键词,Cloud Build会自动过滤版本更新的合并提交,GitHub Actions正常触发打标签,之后标签创建事件再触发Cloud Build。
内容的提问来源于stack exchange,提问作者Greg McKelvey
相关产品推荐
相关产品推荐

