1+ name : Auto approve & merge Dependabot and Renovate PRs
2+
3+ on :
4+ pull_request :
5+ types : [opened, edited, synchronize, reopened, labeled]
6+ branches : [master]
7+
8+ permissions :
9+ contents : write
10+ pull-requests : write
11+
12+ jobs :
13+ auto-approve-merge :
14+ runs-on : ubuntu-latest
15+ if : (github.actor == 'dependabot[bot]' || github.actor == 'renovate[bot]') && github.repository == 'internetee/registry'
16+ steps :
17+ - name : Checkout repository
18+ uses : actions/checkout@v5
19+
20+ - name : Install GitHub CLI
21+ run : |
22+ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
23+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
24+ sudo apt update
25+ sudo apt install gh
26+
27+ - name : Auto approve PR
28+ uses : hmarr/auto-approve-action@v3
29+ with :
30+ github-token : ${{ secrets.GITHUB_TOKEN }}
31+
32+ - name : Fetch Dependabot metadata
33+ if : github.actor == 'dependabot[bot]'
34+ id : metadata
35+ uses : dependabot/fetch-metadata@v1
36+ with :
37+ github-token : ${{ secrets.GITHUB_TOKEN }}
38+
39+ - name : Check if PR should be auto-merged
40+ id : check_auto_merge
41+ run : |
42+ if [ "${{ github.actor }}" == "dependabot[bot]" ]; then
43+ if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-patch" ]]; then
44+ echo "auto_merge=true" >> $GITHUB_OUTPUT
45+ echo "Auto-merge: Dependabot patch update detected"
46+ else
47+ echo "auto_merge=false" >> $GITHUB_OUTPUT
48+ echo "Auto-merge: Dependabot non-patch update, skipping"
49+ fi
50+ elif [ "${{ github.actor }}" == "renovate[bot]" ]; then
51+ # Check if PR has patch label (set by renovate.json configuration)
52+ # Extract label names from the labels array
53+ LABEL_NAMES=$(echo '${{ toJson(github.event.pull_request.labels) }}' | jq -r '.[].name' | tr '\n' ' ')
54+ if [[ "$LABEL_NAMES" == *"patch"* ]] || [[ "$LABEL_NAMES" == *"bundler"* ]] || [[ "$LABEL_NAMES" == *"ruby-version"* ]] || [[ "$LABEL_NAMES" == *"github-actions"* ]]; then
55+ echo "auto_merge=true" >> $GITHUB_OUTPUT
56+ echo "Auto-merge: Renovate patch update detected (label-based): $LABEL_NAMES"
57+ else
58+ echo "auto_merge=false" >> $GITHUB_OUTPUT
59+ echo "Auto-merge: Renovate non-patch update, skipping. Labels: $LABEL_NAMES"
60+ fi
61+ else
62+ echo "auto_merge=false" >> $GITHUB_OUTPUT
63+ echo "Auto-merge: Unknown actor, skipping"
64+ fi
65+ shell : bash
66+
67+ - name : Wait for CI checks
68+ if : steps.check_auto_merge.outputs.auto_merge == 'true'
69+ 70+ with :
71+ ref : ${{ github.event.pull_request.head.sha }}
72+ repo-token : ${{ secrets.GITHUB_TOKEN }}
73+ wait-interval : 30
74+
75+ - name : Auto-merge PR
76+ if : steps.check_auto_merge.outputs.auto_merge == 'true'
77+ run : |
78+ echo "Attempting to auto-merge PR #${{ github.event.pull_request.number }}"
79+ gh pr merge --auto --merge ${{ github.event.pull_request.number }} || {
80+ echo "Auto-merge failed, but continuing..."
81+ exit 0
82+ }
83+ env :
84+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
85+
0 commit comments