如何自动合并 dependentabot 更新(配置版本 2)?

and*_*ndy 18 python yaml github github-actions dependabot

在“Dependabot 正在原生迁移到 GitHub!”之后,我必须更新我的 dependentabot 配置文件以使用版本 2 格式。

我的.dependabot/config.yaml确实看起来像:

version: 1
update_configs:
  - package_manager: "python"
    directory: "/"
    update_schedule: "live"
    automerged_updates:
      - match:
          dependency_type: "all"
          update_type: "all"
Run Code Online (Sandbox Code Playgroud)

我有以下工作:

version: 2
updates:
- package-ecosystem: pip
  directory: "/"
  schedule:
    interval: daily
Run Code Online (Sandbox Code Playgroud)

但我似乎无法再次添加自动合并选项(在使用dependentabot 验证器检查时)?

koj*_*iro 14

现在,这已成为正式记录的功能。您可以批准 Dependabot 拉取请求并将其设置为自动与 GitHub Actions 工作流程合并,例如\xe2\x80\xa6

\n
name: Dependabot auto-approve\non: pull_request_target\n    \npermissions:\n  contents: write\n  pull-requests: write\n    \njobs:\n  dependabot:\n    runs-on: ubuntu-latest\n    if: ${{ github.actor == \'dependabot[bot]\' }}\n    steps:\n      - name: Dependabot metadata\n        id: metadata\n        uses: dependabot/fetch-metadata@v1.1.1\n        with:\n          github-token: "${{ secrets.GITHUB_TOKEN }}"\n      - name: Enable auto-merge for Dependabot PRs\n        if: ${{contains(steps.metadata.outputs.dependency-names, \'my-dependency\') && steps.metadata.outputs.update-type == \'version-update:semver-patch\'}}\n        run: gh pr merge --auto --merge "$PR_URL"\n        env:\n          PR_URL: ${{github.event.pull_request.html_url}}\n          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}\n
Run Code Online (Sandbox Code Playgroud)\n

更新:毕竟 CODEOWNERS 确实允许否定

\n

如果您使用代码所有者并且分支受到保护,您可能会发现这仍会等待代码所有者审核才能合并。您可以要求代码所有者审查除相关文件之外的所有文件,其.github/CODEOWNERS文件如下所示:

\n
* owner1 owner2 @org/team1\nsetup.cfg  # setup.cfg is not owned\n
Run Code Online (Sandbox Code Playgroud)\n

  • 两个注意事项:1. 您必须在存储库设置中启用自动合并,2. 您必须使用“合并之前必须通过检查”来保护目标分支。如果您不执行这两项操作,上面的命令行(出于某种原因)会在运行后立即合并 PR (5认同)

and*_*ndy 12

这是一种不需要任何额外市场安装的解决方案(最初可以在此处找到)。只需创建一个新的 GitHub 工作流程(例如.github/workflows/dependabotautomerge.yml),其中包含:

name: "Dependabot Automerge - Action"

on:
  pull_request:

jobs:
  worker:
    runs-on: ubuntu-latest

    if: github.actor == 'dependabot[bot]'
    steps:
      - name: automerge
        uses: actions/github-script@0.2.0
        with:
          script: |
            github.pullRequests.createReview({
              owner: context.payload.repository.owner.login,
              repo: context.payload.repository.name,
              pull_number: context.payload.pull_request.number,
              event: 'APPROVE'
            })
            github.pullRequests.merge({
              owner: context.payload.repository.owner.login,
              repo: context.payload.repository.name,
              pull_number: context.payload.pull_request.number
            })
          github-token: ${{github.token}}
Run Code Online (Sandbox Code Playgroud)

GitHub Marketplace上还提供各种第三方解决方案。

  • 该代码片段应该被记入。这是原始来源:https://secopslab.medium.com/automerge-github-dependabot-alerts-with-github-actions-7cd6f5763750 (3认同)

Mil*_*tro 10

Dependabot 上的自动合并已禁用到 GitHub:

\n
\n

在可预见的将来,GitHub 原生 Dependabot 将不支持自动合并。我们知道你们中的一些人已经构建了依赖自动合并的出色工作流程,但现在,我们\xe2\x80\x99担心自动合并被用来在整个生态系统中快速传播恶意包。我们建议在合并依赖项之前始终验证它们。

\n
\n

有一些技巧可以完成这项工作,您可以查看 GitHub dependabot-core Issue #1973以获取一些想法。

\n