Skip to content

Commit 8a984fe

Browse files
rochdevtlhunter
authored andcommitted
add summary and slack message to flakiness report (#6252)
1 parent 867d919 commit 8a984fe

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

.github/workflows/flakiness.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
name: Flakiness Report
1+
name: '[Flakiness Report]'
22

33
on:
4+
workflow_dispatch:
45
schedule:
56
- cron: '0 6 * * 1'
67

@@ -25,3 +26,18 @@ jobs:
2526
version: ''
2627
- run: npm install octokit
2728
- run: node scripts/flakiness.mjs
29+
- run: cat flakiness.md >> $GITHUB_STEP_SUMMARY
30+
- id: slack
31+
run: echo "report=$(cat flakiness.txt)" >> $GITHUB_OUTPUT
32+
- uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.0
33+
if: github.event_name == 'schedule'
34+
with:
35+
method: chat.postMessage
36+
token: ${{ secrets.SLACK_BOT_TOKEN }}
37+
payload: |
38+
channel: ${{ secrets.SLACK_CHANNEL_ID }}
39+
blocks:
40+
- type: "section"
41+
text:
42+
type: "mrkdwn"
43+
text: "${{ steps.slack.outputs.report }}"

scripts/flakiness.mjs

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* eslint-disable no-console */
22

3+
import { writeFileSync } from 'fs'
34
import { Octokit } from 'octokit'
45

56
const {
67
BRANCH,
8+
CI,
79
DAYS = '1',
810
OCCURRENCES = '1',
911
UNTIL
@@ -111,7 +113,7 @@ await Promise.all(workflows.map(w => checkWorkflowRuns(w)))
111113
// TODO: Report this somewhere useful instead.
112114

113115
const dateRange = startDate === endDate ? `on ${endDate}` : `from ${startDate} to ${endDate}`
114-
const logString = `jobs with at least ${OCCURRENCES} occurrences seen ${dateRange} (UTC)*`
116+
const logString = `jobs with at least ${OCCURRENCES} occurrences seen ${dateRange} (UTC)`
115117

116118
if (Object.keys(flaky).length === 0) {
117119
console.log(`*No flaky ${logString}`)
@@ -120,21 +122,48 @@ if (Object.keys(flaky).length === 0) {
120122
const pipelineSuccessRate = +((workflowSuccessRate / 100) ** workflows.length * 100).toFixed(1)
121123
const pipelineBadge = pipelineSuccessRate >= 85 ? '🟢' : pipelineSuccessRate >= 75 ? '🟡' : '🔴'
122124

123-
console.log(`*Flaky ${logString}`)
125+
let markdown = ''
126+
let slack = ''
127+
128+
markdown += `**Flaky ${logString}**\n`
129+
slack += `*Flaky ${logString}*\\n`
130+
124131
for (const [workflow, jobs] of Object.entries(flaky).sort()) {
125132
if (!reported.has(workflow)) continue
126-
console.log(`* ${workflow}`)
133+
134+
markdown += `* ${workflow}\n`
135+
slack += ` ● ${workflow}\\n`
136+
127137
for (const [job, urls] of Object.entries(jobs).sort()) {
128138
if (urls.length < OCCURRENCES) continue
129139
// Padding is needed because Slack doesn't show single digits as links.
130-
const links = urls.map((url, idx) => `[${String(idx + 1).padStart(2, '0')}](${url})`)
140+
const markdownLinks = urls.map((url, idx) => `[${String(idx + 1).padStart(2, '0')}](${url})`)
141+
const slackLinks = urls.map((url, idx) => `<${url}|${String(idx + 1).padStart(2, '0')}>`)
131142
const runsBadge = urls.length >= 3 ? ' 🔴' : urls.length === 2 ? ' 🟡' : ''
132-
console.log(` * ${job} (${links.join(', ')})${runsBadge}`)
143+
markdown += ` * ${job} (${markdownLinks.join(', ')})${runsBadge}\n`
144+
slack += ` ○ ${job} (${slackLinks.join(', ')})${runsBadge}\\n`
133145
}
134146
}
135-
console.log('*Flakiness stats*')
136-
console.log(`* Total runs: ${totalCount}`)
137-
console.log(`* Flaky runs: ${flakeCount}`)
138-
console.log(`* Workflow success rate: ${workflowSuccessRate}%`)
139-
console.log(`* Pipeline success rate (approx): ${pipelineSuccessRate}% ${pipelineBadge}`)
147+
148+
markdown += '\n'
149+
markdown += '**Flakiness stats**\n'
150+
markdown += `* Total runs: ${totalCount}\n`
151+
markdown += `* Flaky runs: ${flakeCount}\n`
152+
markdown += `* Workflow success rate: ${workflowSuccessRate}%\n`
153+
markdown += `* Pipeline success rate (approx): ${pipelineSuccessRate}% ${pipelineBadge}`
154+
155+
slack += '\\n'
156+
slack += '*Flakiness stats*\\n'
157+
slack += ` ● Total runs: ${totalCount}\\n`
158+
slack += ` ● Flaky runs: ${flakeCount}\\n`
159+
slack += ` ● Workflow success rate: ${workflowSuccessRate}%\\n`
160+
slack += ` ● Pipeline success rate (approx): ${pipelineSuccessRate}% ${pipelineBadge}`
161+
162+
console.log(markdown)
163+
164+
// TODO: Make this an option instead.
165+
if (CI) {
166+
writeFileSync('flakiness.md', markdown)
167+
writeFileSync('flakiness.txt', slack)
168+
}
140169
}

0 commit comments

Comments
 (0)