-
Notifications
You must be signed in to change notification settings - Fork 2.4k
396 lines (322 loc) · 16.3 KB
/
dependency-ci-dashboard.yml
File metadata and controls
396 lines (322 loc) · 16.3 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
name: Ecosystem CI Dashboard
on:
schedule:
- cron: '15 6 * * *' # 06:15 UTC daily
workflow_dispatch:
permissions:
issues: write
contents: write
jobs:
update-dashboard:
name: Update Ecosystem CI Dashboard
runs-on: ubuntu-latest
if: ${{ github.repository == 'spring-projects/spring-ai' }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Load configuration
id: config
run: |
CONFIG=$(cat src/ecosystem-ci/ci-alert-config.json)
echo "issue_number=$(echo "$CONFIG" | jq -r '.issue_number')" >> $GITHUB_OUTPUT
echo "tracked_branch=$(echo "$CONFIG" | jq -r '.tracked_branch')" >> $GITHUB_OUTPUT
echo "alert_after_days=$(echo "$CONFIG" | jq -r '.alert_after_days')" >> $GITHUB_OUTPUT
echo "heartbeat_days=$(echo "$CONFIG" | jq -r '.heartbeat_days')" >> $GITHUB_OUTPUT
echo "dependencies<<EOF" >> $GITHUB_OUTPUT
echo "$CONFIG" | jq -c '.dependencies' >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Query CI status for all dependencies
id: query-status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEPENDENCIES: ${{ steps.config.outputs.dependencies }}
TRACKED_BRANCH: ${{ steps.config.outputs.tracked_branch }}
run: |
RESULTS="[]"
for row in $(echo "$DEPENDENCIES" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
OWNER=$(_jq '.owner')
REPO=$(_jq '.repo')
echo "Querying status for $OWNER/$REPO..."
# Query workflow runs for the branch (most reliable for GitHub Actions)
RUNS_RESPONSE=$(curl -s -H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs?branch=$TRACKED_BRANCH&per_page=10")
# Find the most recent completed workflow run
LATEST_RUN=$(echo "$RUNS_RESPONSE" | jq '[.workflow_runs[] | select(.status == "completed")] | .[0]')
if [ "$LATEST_RUN" != "null" ] && [ -n "$LATEST_RUN" ]; then
CONCLUSION=$(echo "$LATEST_RUN" | jq -r '.conclusion // "unknown"')
COMMIT_SHA=$(echo "$LATEST_RUN" | jq -r '.head_sha // "unknown"' | head -c 7)
COMMIT_DATE=$(echo "$LATEST_RUN" | jq -r '.created_at // ""')
# Map conclusion to state
case "$CONCLUSION" in
"success") STATE="success" ;;
"failure"|"timed_out"|"cancelled") STATE="failure" ;;
*) STATE="unknown" ;;
esac
else
# Check if there are any in-progress runs
IN_PROGRESS=$(echo "$RUNS_RESPONSE" | jq '[.workflow_runs[] | select(.status == "in_progress" or .status == "queued")] | length')
if [ "$IN_PROGRESS" -gt 0 ]; then
STATE="pending"
# Get commit from in-progress run
COMMIT_SHA=$(echo "$RUNS_RESPONSE" | jq -r '.workflow_runs[0].head_sha // "unknown"' | head -c 7)
COMMIT_DATE=$(echo "$RUNS_RESPONSE" | jq -r '.workflow_runs[0].created_at // ""')
else
STATE="unknown"
# Fall back to HEAD commit info
COMMIT_RESPONSE=$(curl -s -H "Authorization: token $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$OWNER/$REPO/commits/$TRACKED_BRANCH")
COMMIT_SHA=$(echo "$COMMIT_RESPONSE" | jq -r '.sha // "unknown"' | head -c 7)
COMMIT_DATE=$(echo "$COMMIT_RESPONSE" | jq -r '.commit.committer.date // ""')
fi
fi
RESULT=$(jq -n \
--arg owner "$OWNER" \
--arg repo "$REPO" \
--arg state "$STATE" \
--arg sha "$COMMIT_SHA" \
--arg date "$COMMIT_DATE" \
'{owner: $owner, repo: $repo, state: $state, sha: $sha, commit_date: $date}')
RESULTS=$(echo "$RESULTS" | jq --argjson result "$RESULT" '. + [$result]')
done
echo "results<<EOF" >> $GITHUB_OUTPUT
echo "$RESULTS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update dashboard and check alerts
uses: actions/github-script@v7
env:
RESULTS: ${{ steps.query-status.outputs.results }}
ISSUE_NUMBER: ${{ steps.config.outputs.issue_number }}
ALERT_AFTER_DAYS: ${{ steps.config.outputs.alert_after_days }}
HEARTBEAT_DAYS: ${{ steps.config.outputs.heartbeat_days }}
TRACKED_BRANCH: ${{ steps.config.outputs.tracked_branch }}
with:
script: |
const results = JSON.parse(process.env.RESULTS);
const issueNumber = parseInt(process.env.ISSUE_NUMBER);
const alertAfterDays = parseInt(process.env.ALERT_AFTER_DAYS);
const heartbeatDays = parseInt(process.env.HEARTBEAT_DAYS);
const trackedBranch = process.env.TRACKED_BRANCH;
const now = new Date();
const timestamp = now.toISOString();
// Status emoji mapping
const statusEmoji = {
'success': ':white_check_mark:',
'failure': ':x:',
'pending': ':yellow_circle:',
'unknown': ':grey_question:'
};
// Find dashboard comment (contains hidden state marker)
const STATE_MARKER = '<!-- ECOSYSTEM-CI-DASHBOARD-STATE:';
const DASHBOARD_MARKER = '<!-- ECOSYSTEM-CI-DASHBOARD -->';
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
let dashboardComment = comments.find(c => c.body.includes(DASHBOARD_MARKER));
// Parse previous state from comment
let previousState = {};
if (dashboardComment) {
const stateMatch = dashboardComment.body.match(/<!-- ECOSYSTEM-CI-DASHBOARD-STATE:(.*?)-->/s);
if (stateMatch) {
try {
previousState = JSON.parse(stateMatch[1]);
} catch (e) {
console.log('Failed to parse previous state:', e);
}
}
}
// Update state with current results
const newState = {};
const alertsNeeded = [];
for (const result of results) {
const key = `${result.owner}/${result.repo}`;
const prevEntry = previousState[key] || {};
if (result.state === 'failure') {
// Track when it first failed
const failedSince = prevEntry.failedSince || timestamp;
const failedDays = Math.floor((now - new Date(failedSince)) / (1000 * 60 * 60 * 24));
const lastAlerted = prevEntry.lastAlerted;
newState[key] = {
state: result.state,
failedSince: failedSince,
failedDays: failedDays,
lastAlerted: lastAlerted
};
// Check if we need to alert
if (failedDays >= alertAfterDays) {
// Only alert if we haven't alerted in the last heartbeat period
const shouldAlert = !lastAlerted ||
(now - new Date(lastAlerted)) >= (heartbeatDays * 24 * 60 * 60 * 1000);
if (shouldAlert) {
alertsNeeded.push({
owner: result.owner,
repo: result.repo,
failedDays: failedDays,
sha: result.sha
});
newState[key].lastAlerted = timestamp;
}
}
} else {
// Not failing - clear failure tracking
newState[key] = {
state: result.state
};
}
}
// Build dashboard table
let dashboardTable = `| Repository | Status | Branch | Latest Commit | Last Run |\n`;
dashboardTable += `|------------|--------|--------|---------------|----------|\n`;
for (const result of results) {
const key = `${result.owner}/${result.repo}`;
const emoji = statusEmoji[result.state] || statusEmoji['unknown'];
const stateEntry = newState[key];
let statusText = emoji;
if (result.state === 'failure' && stateEntry.failedDays > 0) {
statusText += ` (${stateEntry.failedDays}d)`;
}
const repoLink = `[${result.owner}/${result.repo}](https://github.com/${result.owner}/${result.repo})`;
const commitLink = result.sha !== 'unknown'
? `[\`${result.sha}\`](https://github.com/${result.owner}/${result.repo}/commit/${result.sha})`
: 'N/A';
const actionsLink = `[${trackedBranch}](https://github.com/${result.owner}/${result.repo}/actions?query=branch%3A${trackedBranch})`;
// Format date as YYYY-MM-DD
const lastRun = result.commit_date
? new Date(result.commit_date).toISOString().split('T')[0]
: 'N/A';
dashboardTable += `| ${repoLink} | ${statusText} | ${actionsLink} | ${commitLink} | ${lastRun} |\n`;
}
// Build dashboard comment body
const stateJson = JSON.stringify(newState);
const dashboardBody = `${DASHBOARD_MARKER}
## Ecosystem CI Dashboard
**Last updated:** ${timestamp}
${dashboardTable}
### Legend
- :white_check_mark: All checks passing
- :x: CI failing (days in parentheses)
- :yellow_circle: Checks in progress
- :grey_question: Status unknown
### Alert Policy
- Alerts are posted when a dependency has been failing for **${alertAfterDays}+ days**
- Subscribe to this issue to receive CI failure notifications
${STATE_MARKER}${stateJson}-->
`.split('\n').map(line => line.trim()).join('\n');
// Update or create dashboard comment
if (dashboardComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: dashboardComment.id,
body: dashboardBody
});
console.log('Updated dashboard comment');
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: dashboardBody
});
console.log('Created dashboard comment');
}
// Post alert comments if needed
for (const alert of alertsNeeded) {
const alertBody = `:rotating_light: **CI Alert**: [${alert.owner}/${alert.repo}](https://github.com/${alert.owner}/${alert.repo}) has been failing for **${alert.failedDays} days**
- **Branch:** ${trackedBranch}
- **Latest commit:** [\`${alert.sha}\`](https://github.com/${alert.owner}/${alert.repo}/commit/${alert.sha})
- **CI Status:** [View Actions](https://github.com/${alert.owner}/${alert.repo}/actions?query=branch%3A${trackedBranch})
Please investigate and fix the CI failure.`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: alertBody
});
console.log(`Posted alert for ${alert.owner}/${alert.repo}`);
}
// Set outputs for wiki update
core.setOutput('dashboard_table', dashboardTable);
core.setOutput('timestamp', timestamp);
core.setOutput('alert_after_days', alertAfterDays);
- name: Update Wiki Dashboard
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RESULTS: ${{ steps.query-status.outputs.results }}
TRACKED_BRANCH: ${{ steps.config.outputs.tracked_branch }}
ALERT_AFTER_DAYS: ${{ steps.config.outputs.alert_after_days }}
run: |
# Configure git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Clone wiki repo
WIKI_DIR=$(mktemp -d)
git clone "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.wiki.git" "$WIKI_DIR"
# Generate wiki page content
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Status emoji mapping for wiki (GitHub wiki renders these)
cat > "$WIKI_DIR/Ecosystem-CI-Dashboard.md" << 'WIKI_HEADER'
# Ecosystem CI Dashboard
This dashboard monitors the CI health of Spring AI ecosystem dependencies.
WIKI_HEADER
echo "**Last updated:** $TIMESTAMP" >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md"
echo "" >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md"
# Build table
echo "| Repository | Status | Branch | Latest Commit | Last Run |" >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md"
echo "|------------|--------|--------|---------------|----------|" >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md"
echo "$RESULTS" | jq -r '.[] | @base64' | while read row; do
OWNER=$(echo "$row" | base64 --decode | jq -r '.owner')
REPO=$(echo "$row" | base64 --decode | jq -r '.repo')
STATE=$(echo "$row" | base64 --decode | jq -r '.state')
SHA=$(echo "$row" | base64 --decode | jq -r '.sha')
COMMIT_DATE=$(echo "$row" | base64 --decode | jq -r '.commit_date')
case "$STATE" in
"success") EMOJI=":white_check_mark:" ;;
"failure") EMOJI=":x:" ;;
"pending") EMOJI=":yellow_circle:" ;;
*) EMOJI=":grey_question:" ;;
esac
REPO_LINK="[$OWNER/$REPO](https://github.com/$OWNER/$REPO)"
COMMIT_LINK="[\`$SHA\`](https://github.com/$OWNER/$REPO/commit/$SHA)"
ACTIONS_LINK="[$TRACKED_BRANCH](https://github.com/$OWNER/$REPO/actions?query=branch%3A$TRACKED_BRANCH)"
# Format date as YYYY-MM-DD
if [ -n "$COMMIT_DATE" ] && [ "$COMMIT_DATE" != "null" ]; then
LAST_RUN=$(echo "$COMMIT_DATE" | cut -d'T' -f1)
else
LAST_RUN="N/A"
fi
echo "| $REPO_LINK | $EMOJI | $ACTIONS_LINK | $COMMIT_LINK | $LAST_RUN |" >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md"
done
cat >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md" << WIKI_FOOTER
## Legend
- :white_check_mark: All checks passing
- :x: CI failing
- :yellow_circle: Checks in progress
- :grey_question: Status unknown
## Alert Policy
Alerts are posted to [Issue #${{ steps.config.outputs.issue_number }}](https://github.com/${{ github.repository }}/issues/${{ steps.config.outputs.issue_number }}) when a dependency has been failing for **${ALERT_AFTER_DAYS}+ days**.
Subscribe to that issue to receive CI failure notifications.
## Monitored Repositories
The following repositories are monitored as part of the Spring AI ecosystem:
WIKI_FOOTER
echo "$RESULTS" | jq -r '.[] | "- [`\(.owner)/\(.repo)`](https://github.com/\(.owner)/\(.repo))"' >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md"
cat >> "$WIKI_DIR/Ecosystem-CI-Dashboard.md" << 'WIKI_END'
---
*This page is automatically updated by the [Ecosystem CI Dashboard workflow](https://github.com/spring-projects/spring-ai/actions/workflows/dependency-ci-dashboard.yml).*
WIKI_END
# Commit and push wiki changes
cd "$WIKI_DIR"
git add Ecosystem-CI-Dashboard.md
if git diff --staged --quiet; then
echo "No changes to wiki"
else
git commit -m "Update Ecosystem CI Dashboard - $TIMESTAMP"
git push
echo "Wiki updated successfully"
fi