Skip to content

Commit d5c4d86

Browse files
committed
build: add Dependabot auto-approve workflow
1 parent 69bd5ab commit d5c4d86

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
name: "CodeQL Advanced"
1313

1414
on:
15+
workflow_dispatch:
1516
push:
1617
branches: [ "main", "sandbox" ]
1718
pull_request:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Dependabot Auto-Approve
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
branches:
8+
- main
9+
10+
permissions:
11+
pull-requests: write
12+
contents: write
13+
14+
jobs:
15+
auto-approve:
16+
runs-on: ubuntu-latest
17+
# Check for success, an associated PR, and the correct target branch
18+
if: |
19+
github.event.pull_request.base.ref == 'main' &&
20+
github.event.pull_request.user.login == 'dependabot[bot]'
21+
22+
steps:
23+
- name: Checkout PR Branch
24+
uses: actions/checkout@v5
25+
26+
- name: Fetch Dependabot Metadata
27+
id: dependabot-metadata
28+
uses: dependabot/fetch-metadata@v2
29+
with:
30+
github-token: "${{ secrets.GITHUB_TOKEN }}"
31+
32+
- name: Approve Dependabot PR
33+
if: |
34+
steps.dependabot-metadata.outputs.update-type == 'version-update:semver-minor' ||
35+
steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch'
36+
run: |
37+
REVIEW_COUNT=$(gh pr view "$PR_NUMBER" --json reviews | \
38+
jq --arg sha "$HEAD_SHA" '[.reviews[] | select(.author.login == "github-actions" and .commit.oid == $sha and .state == "APPROVED")] | length')
39+
40+
if [ "$REVIEW_COUNT" -eq 0 ]; then
41+
# Add Label
42+
gh pr edit "$PR_NUMBER" --add-label "auto-approved"
43+
# Approve PR
44+
gh pr review --approve --body "Approved automatically as a non-major update after all checks passed." "$PR_NUMBER"
45+
fi
46+
env:
47+
PR_NUMBER: ${{ github.event.pull_request.number }}
48+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
49+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)