【问题标题】:Auto merge dependabot PR after all checks have passed所有检查通过后自动合并dependabot PR
【发布时间】:2022-10-25 20:35:15
【问题描述】:
一旦通过了 Dependabot PR 的所有检查(或工作流程),我想自动合并 Dependabot PR。
目前,我正在使用此逻辑来触发自动合并操作:
on:
workflow_run:
workflows: ["Lint and Unit tests"]
types:
- completed
一旦在 Dependabot PR 上通过了所有检查,它就会触发自动合并工作流程,但问题是由于工作流程中缺少 pull_request 有效负载,它无法工作。
自动合并工作流程的错误和警告:
【问题讨论】:
标签:
github
github-actions
dependabot
【解决方案1】:
以下工作流程为我们完成:
name: Dependabot auto-merge
on:
pull_request_target:
types: [review_requested]
permissions:
contents: write
pull-requests: write
packages: read
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.3.4
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
skip-commit-verification: true
- name: Checkout repository
uses: actions/checkout@v3
- name: Approve a PR if not already approved
run: |
gh pr checkout "$PR_URL"
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
then
gh pr review --approve "$PR_URL"
else
echo "PR already approved.";
fi
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Enable auto-merge for Dependabot PRs
if: ${{ contains(github.event.pull_request.title, 'bump')}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.RELEASE_TOKEN}}
RELEASE_TOKEN 具有扩展范围(工作流程、write:packages、admin:org),分支保护被激活(需要审查),dependabot 配置为设置“reviewers:”,在 org 和 repo 级别启用自动合并。