-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (120 loc) · 4.79 KB
/
discover-and-dispatch.yml
File metadata and controls
145 lines (120 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Discover and Dispatch PR Fixes
on:
schedule:
# Run daily at midnight UTC
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
target_repo:
description: 'Specific repo to check (optional, e.g., VectorInstitute/repo-name)'
required: false
dry_run:
description: 'Dry run - discover PRs but do not dispatch fixes'
type: boolean
default: false
permissions:
contents: read
actions: write
env:
ORG_NAME: VectorInstitute
jobs:
discover:
runs-on: ubuntu-latest
outputs:
prs: ${{ steps.find-prs.outputs.prs }}
steps:
- name: Checkout bot repository
uses: actions/checkout@v6
- name: Find bot PRs with failing checks
id: find-prs
run: |
# Determine which repos to check
if [ -n "${{ github.event.inputs.target_repo }}" ]; then
REPOS="${{ github.event.inputs.target_repo }}"
else
if [ -f repos-to-monitor.csv ]; then
REPOS=$(tail -n +2 repos-to-monitor.csv | grep -v '^$' | tr '\n' ' ')
echo "Reading repos from repos-to-monitor.csv"
else
echo "Error: repos-to-monitor.csv not found"
exit 1
fi
fi
PRS_TO_FIX="[]"
BOT_AUTHORS=("app/dependabot" "pre-commit-ci[bot]")
for REPO in $REPOS; do
# Skip the bot repository itself
if [ "$REPO" = "VectorInstitute/aieng-bot" ]; then
echo "Skipping $REPO (bot repository)"
continue
fi
echo "Checking $REPO for open bot PRs..."
for BOT_AUTHOR in "${BOT_AUTHORS[@]}"; do
# Get all open PRs from this bot author
REPO_PRS=$(gh pr list --repo "$REPO" \
--author "$BOT_AUTHOR" \
--state open \
--json number,title,url,headRefName 2>/dev/null || echo "[]")
if [ "$REPO_PRS" != "[]" ] && [ -n "$REPO_PRS" ]; then
BOT_PRS=$(echo "$REPO_PRS" | jq -c "[.[] | {repo: \"$REPO\", pr_number: .number, title: .title, head_ref: .headRefName}]")
echo "Found open PRs in $REPO from $BOT_AUTHOR:"
echo "$BOT_PRS" | jq '.'
PRS_TO_FIX=$(echo "$PRS_TO_FIX" | jq -c ". + $BOT_PRS")
fi
done
done
PRS_TO_FIX=$(echo "$PRS_TO_FIX" | jq -c 'unique_by({repo, pr_number})')
echo "Total PRs to fix: $(echo "$PRS_TO_FIX" | jq 'length')"
echo "$PRS_TO_FIX" | jq '.'
echo "prs=$(echo "$PRS_TO_FIX" | jq -c '.')" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.ORG_ACCESS_TOKEN }}
dispatch:
runs-on: ubuntu-latest
needs: discover
if: needs.discover.outputs.prs != '[]' && github.event.inputs.dry_run != 'true'
strategy:
matrix:
pr: ${{ fromJson(needs.discover.outputs.prs) }}
max-parallel: 5
fail-fast: false
steps:
- name: Dispatch fix job for ${{ matrix.pr.repo }}#${{ matrix.pr.pr_number }}
run: |
echo "Dispatching fix job for ${{ matrix.pr.repo }}#${{ matrix.pr.pr_number }}"
echo "Title: ${{ matrix.pr.title }}"
gh workflow run fix-pr-agent.yml \
--repo VectorInstitute/aieng-bot \
--field target_repo="${{ matrix.pr.repo }}" \
--field pr_number="${{ matrix.pr.pr_number }}" \
--field max_retries="3"
echo "Fix job dispatched"
env:
GH_TOKEN: ${{ secrets.ORG_ACCESS_TOKEN }}
report-summary:
runs-on: ubuntu-latest
needs: [discover, dispatch]
if: always()
steps:
- name: Generate summary
run: |
PR_COUNT=$(echo '${{ needs.discover.outputs.prs }}' | jq 'length')
DRY_RUN="${{ github.event.inputs.dry_run }}"
echo "## PR Fix Discovery Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Organization**: ${{ env.ORG_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "- **PRs Found**: $PR_COUNT" >> $GITHUB_STEP_SUMMARY
echo "- **Run Time**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> $GITHUB_STEP_SUMMARY
if [ "$DRY_RUN" = "true" ]; then
echo "- **Mode**: Dry Run (no fixes dispatched)" >> $GITHUB_STEP_SUMMARY
else
echo "- **Mode**: Active (fixes dispatched)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$PR_COUNT" -gt 0 ]; then
echo "### PRs Discovered" >> $GITHUB_STEP_SUMMARY
echo '${{ needs.discover.outputs.prs }}' | \
jq -r '.[] | "- [\(.repo)#\(.pr_number)](https://github.com/\(.repo)/pull/\(.pr_number)) - \(.title)"' >> $GITHUB_STEP_SUMMARY
else
echo "No open bot PRs found." >> $GITHUB_STEP_SUMMARY
fi