Skip to content

Commit 532f26f

Browse files
authored
Add Dependabot auto-manage workflow
1 parent dd7c740 commit 532f26f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
name: Dependabot Auto Manage
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
inputs:
7+
pr_number:
8+
description: 'PR number to process'
9+
required: true
10+
type: number
11+
dependency_type:
12+
description: 'Dependency type to process'
13+
required: false
14+
default: 'direct:production'
15+
type: choice
16+
options:
17+
- 'direct:production'
18+
- 'direct:development'
19+
- 'all'
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
jobs:
26+
dependabot:
27+
runs-on: ubuntu-latest
28+
if: |
29+
(github.event_name == 'pull_request' && (github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.user.login == 'app/dependabot')) ||
30+
(github.event_name == 'workflow_dispatch')
31+
steps:
32+
- name: Checkout (for manual dispatch)
33+
if: github.event_name == 'workflow_dispatch'
34+
uses: actions/checkout@v4
35+
36+
- name: Check PR author (for manual dispatch)
37+
if: github.event_name == 'workflow_dispatch'
38+
env:
39+
GH_TOKEN: ${{ github.token }}
40+
run: |
41+
PR_AUTHOR=$(gh pr view ${{ github.event.inputs.pr_number }} --repo "${{ github.repository }}" --json author --jq '.author.login')
42+
if [[ "$PR_AUTHOR" != "dependabot[bot]" && "$PR_AUTHOR" != "app/dependabot" ]]; then
43+
echo "❌ PR #${{ github.event.inputs.pr_number }} is not from Dependabot (author: $PR_AUTHOR)"
44+
exit 1
45+
fi
46+
echo "✅ PR #${{ github.event.inputs.pr_number }} is from Dependabot"
47+
48+
- name: Simulate PR event for manual dispatch
49+
if: github.event_name == 'workflow_dispatch'
50+
id: pr_info
51+
env:
52+
GH_TOKEN: ${{ github.token }}
53+
run: |
54+
# Get PR details and set outputs
55+
PR_DATA=$(gh pr view ${{ github.event.inputs.pr_number }} --repo "${{ github.repository }}" --json number,url,author)
56+
echo "pr_number=$(echo $PR_DATA | jq -r '.number')" >> $GITHUB_OUTPUT
57+
echo "pr_url=$(echo $PR_DATA | jq -r '.url')" >> $GITHUB_OUTPUT
58+
59+
- uses: ad/[email protected]
60+
with:
61+
dependency-type: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dependency_type || 'direct:production' }}
62+
merge-method: 'squash'
63+
add-label: ${{ github.event_name == 'workflow_dispatch' && 'manual-approval' || 'dependabot-approved' }}
64+
pr-number: ${{ github.event_name == 'workflow_dispatch' && steps.pr_info.outputs.pr_number || '' }}
65+
pr-url: ${{ github.event_name == 'workflow_dispatch' && steps.pr_info.outputs.pr_url || '' }}
66+
github-token: ${{ secrets.PAT_TOKEN }}

0 commit comments

Comments
 (0)