Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally auto-approve dependabot PRs #1117

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
41 changes: 41 additions & 0 deletions .github/workflows/dependabot-auto-approve.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Dependabot auto-approve
on: pull_request
permissions:
pull-requests: write
jobs:
validate_dependabot_opened_this_PR:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- run: echo "This PR was raised by Dependabot"
validate_this_is_an_allowed_dependency:
needs: validate_dependabot_opened_this_PR
runs-on: ubuntu-latest
steps:
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v2
- if: "!contains(steps.dependabot-metadata.outputs.package-ecosystem, 'npm') && (steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch')"
id: check_if_allowed_dependency
run: echo "is_allowed_dependency=1" >> "$GITHUB_OUTPUT"
auto_approve_and_merge:
runs-on: ubuntu-latest
needs: [validate_dependabot_opened_this_PR, validate_this_is_an_allowed_dependency]
if: ${{ needs.validate_this_is_an_allowed_dependency.outputs.is_allowed_dependency == 1 }}
steps:
- uses: actions/checkout@v4
- name: Approve a PR if not already approved
run: |
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
then gh pr review --approve "$PR_URL"
else echo "PR already approved, skipping additional approvals to minimize emails/notification noise.";
fi
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
# - name: Enable auto-merge for Dependabot PRs
# run: gh pr merge --auto --merge "$PR_URL"
# env:
# PR_URL: ${{github.event.pull_request.html_url}}
# GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
Loading