1
1
/* eslint-disable no-console */
2
2
3
+ import { writeFileSync } from 'fs'
3
4
import { Octokit } from 'octokit'
4
5
5
6
const {
6
7
BRANCH ,
8
+ CI ,
7
9
DAYS = '1' ,
8
10
OCCURRENCES = '1' ,
9
11
UNTIL
@@ -111,7 +113,7 @@ await Promise.all(workflows.map(w => checkWorkflowRuns(w)))
111
113
// TODO: Report this somewhere useful instead.
112
114
113
115
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)`
115
117
116
118
if ( Object . keys ( flaky ) . length === 0 ) {
117
119
console . log ( `*No flaky ${ logString } ` )
@@ -120,21 +122,48 @@ if (Object.keys(flaky).length === 0) {
120
122
const pipelineSuccessRate = + ( ( workflowSuccessRate / 100 ) ** workflows . length * 100 ) . toFixed ( 1 )
121
123
const pipelineBadge = pipelineSuccessRate >= 85 ? '🟢' : pipelineSuccessRate >= 75 ? '🟡' : '🔴'
122
124
123
- console . log ( `*Flaky ${ logString } ` )
125
+ let markdown = ''
126
+ let slack = ''
127
+
128
+ markdown += `**Flaky ${ logString } **\n`
129
+ slack += `*Flaky ${ logString } *\\n`
130
+
124
131
for ( const [ workflow , jobs ] of Object . entries ( flaky ) . sort ( ) ) {
125
132
if ( ! reported . has ( workflow ) ) continue
126
- console . log ( `* ${ workflow } ` )
133
+
134
+ markdown += `* ${ workflow } \n`
135
+ slack += ` ● ${ workflow } \\n`
136
+
127
137
for ( const [ job , urls ] of Object . entries ( jobs ) . sort ( ) ) {
128
138
if ( urls . length < OCCURRENCES ) continue
129
139
// 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' ) } >` )
131
142
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`
133
145
}
134
146
}
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
+ }
140
169
}
0 commit comments