Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 25 additions & 42 deletions .github/workflows/dependabot-auto-approve.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,33 @@
name: Dependabot auto-approve

name: Dependabot auto-approve and merge
on: pull_request

permissions:
contents: write
pull-requests: write

jobs:
auto-approve:
dependabot:
runs-on: ubuntu-latest
if: >-
github.event.pull_request.user.login == 'dependabot[bot]' &&
github.actor == 'dependabot[bot]'
permissions:
pull-requests: write
checks: read
statuses: read
actions: read
contents: read
if: ${{ github.actor == 'dependabot[bot]' }}
Comment thread
rharasani-sa marked this conversation as resolved.
steps:
- name: Verify all commits are from the bot
run: |
authors=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}/commits" --paginate --jq '.[].author.login' | sort -u)
if [ "$authors" != "$BOT_LOGIN" ]; then
echo "::error::Refusing to auto-approve: PR contains commits not authored by ${BOT_LOGIN} (authors: ${authors})"
exit 1
fi
env:
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BOT_LOGIN: dependabot[bot]
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Wait for required checks to pass
timeout-minutes: 30
run: |
set +e
output=$(gh pr checks "$PR_URL" --required --watch --fail-fast 2>&1)
code=$?
set -e
echo "$output"
if [ $code -ne 0 ] && echo "$output" | grep -qi "no required checks"; then
echo "No required checks configured on the base branch; skipping wait."
exit 0
fi
exit $code
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR - dependabot
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Approve the PR
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Second approval - golang deps only

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 master requires code-owner review, and CODEOWNERS grants that only to the three named maintainers. Neither github-actions[bot] nor the DevOps service account qualifies, so auto-merge stays blocked on "review required from code owners" and never completes. Add the service account to CODEOWNERS, or turn off require-code-owner-reviews on master.

if: steps.metadata.outputs.package-ecosystem == 'go_modules'
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.GH_SERVICE_ACCOUNT_DEVOPS_2_PAT1 }}
- name: Enable auto-merge
run: gh pr merge --auto --squash "$PR_URL"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 master has no required status checks configured, so auto-merge fires as soon as the approvals land and a failing build or lint will not block it. The removed gh pr checks --watch step was the only CI gate. Mark the build and lint jobs as required checks on master before enabling this.

env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}