GitHub Actions - 忽略或排除 Dependabot 拉取请求

26
我有一个存储库,其中包含 Dependabot,它会打开版本更新等PR,我希望保留这些内容。
在同一存储库中,我为我的团队编写了GitHub拉取请求操作。
我的问题是,无论我尝试什么,Dependabot都会触发Pull Request操作。
我的PR操作必须在暂存分支的拉取请求上触发,如下所示:
name: Pull Request
on:
  pull_request:
    branches:
      - staging

根据文档所述,我不能同时使用pull_reuqest和branches_ignore。

迄今为止我尝试过的工作流尝试都没有成功:

name: Pull Request
on:
  pull_request:
    branches:
      - staging
      - '!dependabot/**'

name: Pull Request
on:
  pull_request:
    branches:
      - staging

jobs:
  Build:
    if: github.actor!= 'dependabot-preview[bot]'
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: Check out code
      uses: actions/checkout@v2

我还尝试过像这样排除 Dependabot 用户:
if: github.actor!= 'depbot'

希望您能提供有关如何解决这个问题的见解或答案。

谢谢!


1
你能打印出 github.actor 吗?像这样:- run: echo ${{ github.actor }}。它会输出什么? - rethab
你可能需要检查dependabot是否触发了其他工作流条件,比如push。当它创建PR时,这也可以被视为对你的存储库的推送,这就是我遇到的情况。 - Abel Cheung
1个回答

42

我猜多年来有很多变化,你可以在整个网络上找到过时的方法。实际的方法在 Dependabot文档中有记录。

if: ${{ github.actor != 'dependabot[bot]' }}

请注意现在您也可以检查github.triggering_actor - 如果您希望工作流在 Dependabot 触发它时跳过,但是想要能够手动在由 Dependabot 打开的 PR 上触发它。

这是一个链接,指向包含条件检查的部分:https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#common-dependabot-automations - CTS_AE

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接