Skip to content

Commit 13a59d8

Browse files
chore: dependabot poc changes (#1798)
1 parent f5cbedb commit 13a59d8

File tree

2 files changed

+136
-11
lines changed

2 files changed

+136
-11
lines changed

.github/dependabot.yml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,63 @@
33
# Please see the documentation for all configuration options:
44
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
55
version: 2
6+
67
updates:
8+
# Grouped GitHub Actions updates
79
- package-ecosystem: "github-actions"
810
directory: "/"
911
schedule:
1012
interval: "monthly"
11-
1213
commit-message:
1314
prefix: "build"
1415
target-branch: "dependabotchanges"
16+
open-pull-requests-limit: 10
17+
groups:
18+
all-actions:
19+
patterns:
20+
- "*"
21+
22+
# Grouped Python dependencies
1523
- package-ecosystem: "pip"
1624
directory: "/"
1725
schedule:
1826
interval: "monthly"
19-
20-
2127
commit-message:
2228
prefix: "build"
29+
target-branch: "dependabotchanges"
30+
open-pull-requests-limit: 10
2331
groups:
2432
langchain:
2533
patterns:
2634
- "langchain*"
27-
open-pull-requests-limit: 100
28-
target-branch: "dependabotchanges"
35+
all-backend-deps:
36+
patterns:
37+
- "*"
38+
39+
# Grouped frontend npm dependencies (main app)
2940
- package-ecosystem: "npm"
3041
directory: "/code/frontend"
3142
schedule:
3243
interval: "monthly"
33-
34-
3544
commit-message:
3645
prefix: "build"
37-
open-pull-requests-limit: 100
3846
target-branch: "dependabotchanges"
47+
open-pull-requests-limit: 10
48+
groups:
49+
frontend-deps:
50+
patterns:
51+
- "*"
52+
53+
# Grouped frontend npm dependencies (UI tests)
3954
- package-ecosystem: "npm"
4055
directory: "/tests/integration/ui"
4156
schedule:
4257
interval: "monthly"
43-
44-
4558
commit-message:
4659
prefix: "build"
47-
open-pull-requests-limit: 100
4860
target-branch: "dependabotchanges"
61+
open-pull-requests-limit: 10
62+
groups:
63+
frontend-deps:
64+
patterns:
65+
- "*"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Scheduled Dependabot PRs Auto-Merge
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Runs once a day at midnight UTC
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
merge-dependabot:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install GitHub CLI
20+
run: |
21+
sudo apt update
22+
sudo apt install -y gh
23+
24+
- name: Fetch & Filter Dependabot PRs
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
run: |
28+
echo "🔍 Fetching all Dependabot PRs targeting 'dependabotchanges'..."
29+
> matched_prs.txt
30+
pr_batch=$(gh pr list --state open --json number,title,author,baseRefName,url \
31+
--jq '.[] | "\(.number)|\(.title)|\(.author.login)|\(.baseRefName)|\(.url)"')
32+
while IFS='|' read -r number title author base url; do
33+
author=$(echo "$author" | xargs)
34+
base=$(echo "$base" | xargs)
35+
if [[ "$author" == "app/dependabot" && "$base" == "dependabotchanges" ]]; then
36+
echo "$url" >> matched_prs.txt
37+
echo "✅ Matched PR #$number - $title"
38+
else
39+
echo "❌ Skipped PR #$number - $title (Author: $author, Base: $base)"
40+
fi
41+
done <<< "$pr_batch"
42+
echo "👉 Matched PRs:"
43+
cat matched_prs.txt || echo "None"
44+
45+
- name: Rebase PR if Conflicts Exist
46+
if: success()
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
if [[ ! -s matched_prs.txt ]]; then
51+
echo "⚠️ No matching PRs to process."
52+
exit 0
53+
fi
54+
while IFS= read -r pr_url; do
55+
pr_number=$(basename "$pr_url")
56+
echo "🔁 Rebasing PR #$pr_number if conflicts exist"
57+
mergeable=$(gh pr view "$pr_number" --json mergeable --jq '.mergeable')
58+
if [[ "$mergeable" == "CONFLICTING" ]]; then
59+
echo "❌ Merge conflicts detected. Rebasing PR #$pr_number"
60+
gh pr update-branch "$pr_url" || echo "❗ Rebase (update-branch) failed."
61+
fi
62+
done < matched_prs.txt
63+
64+
- name: Auto-Merge if Mergeable
65+
if: success()
66+
env:
67+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
run: |
69+
if [[ ! -s matched_prs.txt ]]; then
70+
echo "⚠️ No matching PRs to process."
71+
exit 0
72+
fi
73+
while IFS= read -r pr_url; do
74+
echo "🔍 Checking mergeability for $pr_url"
75+
pr_number=$(basename "$pr_url")
76+
attempt=0
77+
max_attempts=8
78+
mergeable=""
79+
sleep 5 # Initial delay to allow GitHub to compute mergeability
80+
while [[ $attempt -lt $max_attempts ]]; do
81+
mergeable=$(gh pr view "$pr_number" --json mergeable --jq '.mergeable' 2>/dev/null || echo "UNKNOWN")
82+
echo "🔁 Attempt $((attempt+1))/$max_attempts: mergeable=$mergeable"
83+
if [[ "$mergeable" == "MERGEABLE" ]]; then
84+
echo "🚀 Enabling auto-merge..."
85+
set -x
86+
merge_output=$(gh pr merge --auto --merge "$pr_url" 2>&1)
87+
merge_status=$?
88+
set +x
89+
echo "$merge_output"
90+
if [[ $merge_status -ne 0 ]]; then
91+
echo "❗ Auto-merge failed. Output: $merge_output"
92+
else
93+
echo "✅ Auto-merge succeeded!"
94+
fi
95+
break
96+
elif [[ "$mergeable" == "CONFLICTING" ]]; then
97+
echo "❌ Cannot merge due to conflicts. Skipping."
98+
break
99+
else
100+
echo "🕒 Waiting for GitHub to determine mergeable status..."
101+
sleep 15
102+
fi
103+
((attempt++))
104+
done
105+
if [[ "$mergeable" != "MERGEABLE" && "$mergeable" != "CONFLICTING" ]]; then
106+
echo "❌ Mergeability undetermined after $max_attempts attempts. Skipping PR #$pr_number"
107+
fi
108+
done < matched_prs.txt || echo "⚠️ Completed loop with some errors, but continuing gracefully."

0 commit comments

Comments
 (0)