Skip to content

Commit 563155a

Browse files
authored
Merge pull request #2846 from internetee/auto_merge
Automated pull request merging
2 parents 2b6ee09 + 1b21193 commit 563155a

File tree

4 files changed

+140
-4
lines changed

4 files changed

+140
-4
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "bundler"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
day: "monday"
8+
time: "09:00"
9+
allow:
10+
- dependency-type: "direct"
11+
open-pull-requests-limit: 10
12+

.github/workflows/auto-merge.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
uses: lewagon/[email protected]
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+

.github/workflows/ruby.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Github Testing
2-
on: [push]
2+
on: [push, pull_request]
33

44
jobs:
55
test:

renovate.json

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,57 @@
44
],
55
"packageRules": [
66
{
7-
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
7+
"matchUpdateTypes": ["patch", "pin", "digest"],
8+
"automerge": true,
9+
"automergeType": "pr",
10+
"addLabels": ["patch", "dependencies"],
11+
"requiredStatusChecks": null
12+
},
13+
{
14+
"matchUpdateTypes": ["minor"],
815
"automerge": false,
9-
"automergeType": "pr"
16+
"addLabels": ["minor"]
17+
},
18+
{
19+
"matchUpdateTypes": ["major"],
20+
"automerge": false,
21+
"addLabels": ["major"]
22+
},
23+
{
24+
"matchDepTypes": ["ruby", "bundler", "Gemfile", "Gemfile.lock"],
25+
"matchUpdateTypes": ["patch"],
26+
"addLabels": ["bundler", "dependencies"],
27+
"automerge": true,
28+
"automergeType": "pr",
29+
"requiredStatusChecks": null
1030
},
1131
{
1232
"matchDepTypes": ["ruby", "bundler", "Gemfile", "Gemfile.lock"],
13-
"addLabels": ["bundler"]
33+
"matchUpdateTypes": ["minor", "major"],
34+
"addLabels": ["bundler"],
35+
"automerge": false
1436
},
1537
{
1638
"matchDepTypes": [".ruby-version"],
39+
"matchUpdateTypes": ["patch"],
40+
"addLabels": ["ruby-version", "dependencies"],
41+
"automerge": true,
42+
"automergeType": "pr",
43+
"requiredStatusChecks": null
44+
},
45+
{
46+
"matchDepTypes": [".ruby-version"],
47+
"matchUpdateTypes": ["minor", "major"],
1748
"addLabels": ["ruby-version"],
1849
"automerge": false
50+
},
51+
{
52+
"matchFileNames": [".github/workflows/ruby.yml"],
53+
"matchUpdateTypes": ["patch", "minor"],
54+
"addLabels": ["github-actions", "dependencies"],
55+
"automerge": true,
56+
"automergeType": "pr",
57+
"requiredStatusChecks": null
1958
}
2059
],
2160
"docker": {

0 commit comments

Comments
 (0)