问题描述
在“ Dependabot正在本地迁移到GitHub!”之后,我不得不更新我的Dependabot配置文件以使用版本2格式。
我的 .dependabot / config.yaml 确实像这样:
version: 1
update_configs:
- package_manager: "python"
directory: "/"
update_schedule: "live"
automerged_updates:
- match:
dependency_type: "all"
update_type: "all"
我有以下工作:
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: daily
但是我似乎无法再次添加自动合并选项(使用dependabot validator检查时)?
解决方法
Dependabot上的自动合并已禁用到GitHub:
在可预见的将来,GitHub本地Dependabot将不支持自动合并。我们知道你们中的一些人已经建立了依靠自动合并的出色工作流程,但是现在,我们担心自动合并被用来在整个生态系统中快速传播恶意软件包。我们建议始终在合并依赖项之前先对其进行验证。
有一些技巧可以完成这项工作,您可以查看GitHub dependabot-core
issue #1973以获得一些想法。
这是一种不需要任何其他市场安装(最初是here)的解决方案。只需创建一个新的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,pull_number: context.payload.pull_request.number
})
github-token: ${{github.token}}
GitHub Marketplace上还有各种第三方解决方案。
,现在是 officially documented feature。您可以批准 Dependabot 拉取请求并将其设置为与 GitHub 操作工作流自动合并,例如……
name: Dependabot auto-approve
on: pull_request_target
permissions:
# The documentation has a typo here.
# It's `contents`,not `content`.
contents: write
pull-requests: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Enable auto-merge for Dependabot PRs
if: ${{contains(steps.metadata.outputs.dependency-names,'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
# The documentation incorrectly forgets `GITHUB_TOKEN` here.
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
如果您使用 code owners 并且分支受到保护,您可能会发现这仍将等待代码所有者审查合并。不幸的是,代码所有者不允许您否定受影响的文件,因此您需要在代码所有者中明确列出拥有的文件以启用完全非交互式合并步骤。