如何配置GitHub Actions Job的if条件仅在上游触发时运行?
解决方案
你可以给Job添加如下if条件来实现需求:
jobs: your-job-name: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository # 其他Job配置内容...
条件说明:
github.event_name != 'pull_request':匹配push事件,这类事件都是直接推送到上游main分支的操作,会直接运行Jobgithub.event.pull_request.head.repo.full_name == github.repository:当事件是pull_request时,只有PR的发起仓库(head.repo)和当前工作流所在的上游仓库(github.repository)完全一致时,才运行Job;如果是fork仓库发起的PR,这两个仓库名称会不一致,Job就会被跳过
内容的提问来源于stack exchange,提问作者LuMa
相关产品推荐
相关产品推荐

