Repository navigation
ci(repo): post the Expo e2e flaky tests to Slack #10387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46b6dde
ci(repo): post the Expo e2e flaky tests to Slack once a day
wobsoriano 17691af
ci(repo): post the Expo e2e flaky tests to Slack after each release run
wobsoriano fe3d3df
ci(repo): pin download-artifact for the Expo e2e workflow
wobsoriano 61fbb80
ci(repo): send the Expo e2e flaky tests with the Slack action like th…
wobsoriano 74f8c0a
ci(repo): keep the flaky test record from failing the Expo e2e jobs
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const ERROR_CHARS = 300; | ||
|
|
||
| function flakesFromReport(report) { | ||
| return report.run.results | ||
| .filter(result => result.status === 'flaky') | ||
| .map(result => ({ | ||
| platform: result.platform, | ||
| file: result.file, | ||
| title: result.titlePath.join(' › '), | ||
| error: result.attempts.find(attempt => attempt.status === 'failed')?.error?.message ?? '', | ||
| })); | ||
| } | ||
|
|
||
| function normalizeError(message) { | ||
| const normalized = message | ||
| .replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, '<email>') | ||
| .replace(/\b(user|sess|ins|app|org)_[A-Za-z0-9]+/g, '$1_<id>') | ||
| .replace(/after launch [0-9a-f]+/g, 'after launch <id>') | ||
| .replace(/; passes: \d+;.*$/s, '') | ||
| .replace(/\s+/g, ' ') | ||
| .trim(); | ||
| return normalized.length > ERROR_CHARS ? `${normalized.slice(0, ERROR_CHARS)}…` : normalized; | ||
| } | ||
|
|
||
| const slackText = text => text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'); | ||
|
|
||
| const mostCommon = counts => [...counts.entries()].sort((a, b) => b[1] - a[1])[0][0]; | ||
|
|
||
| function flakyPayload(records) { | ||
| const tests = new Map(); | ||
| for (const record of records) { | ||
| for (const flake of record.flakes) { | ||
| const key = `${flake.file}\n${flake.title}`; | ||
| const test = tests.get(key) ?? { file: flake.file, title: flake.title, platforms: new Set(), errors: new Map() }; | ||
| const error = normalizeError(flake.error); | ||
| test.platforms.add(flake.platform); | ||
| test.errors.set(error, (test.errors.get(error) ?? 0) + 1); | ||
| tests.set(key, test); | ||
| } | ||
| } | ||
| if (tests.size === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const markdown = text => ({ type: 'section', text: { type: 'mrkdwn', text } }); | ||
| const runUrl = records.find(record => record.runUrl)?.runUrl; | ||
| const count = tests.size === 1 ? '1 test' : `${tests.size} tests`; | ||
| const header = [ | ||
| '*:warning: Expo E2E flaky tests*', | ||
| '*Pull request:* Version packages', | ||
| `*Flaky:* ${count} passed only on a retry`, | ||
| ...(runUrl ? [`*Run:* <${runUrl}|View logs>`] : []), | ||
| ]; | ||
| const sorted = [...tests.values()].sort((a, b) => a.file.localeCompare(b.file) || a.title.localeCompare(b.title)); | ||
| const blocks = [markdown(header.join('\n'))]; | ||
| for (const test of sorted) { | ||
| const lines = [ | ||
| `\`${test.file.replace(/^specs\/features\//, '')}\` ${slackText(test.title)}`, | ||
| `*Platforms:* ${[...test.platforms].sort().join(', ')}`, | ||
| ]; | ||
| const error = mostCommon(test.errors); | ||
| if (error !== '') { | ||
| lines.push(`*First attempt failed:* ${slackText(error)}`); | ||
| } | ||
| blocks.push(markdown(lines.join('\n'))); | ||
| } | ||
| return { blocks, unfurl_links: false, unfurl_media: false }; | ||
| } | ||
|
|
||
| const readJson = file => JSON.parse(fs.readFileSync(file, 'utf8')); | ||
|
|
||
| const byDirectory = (a, b) => path.dirname(a).localeCompare(path.dirname(b), 'en', { numeric: true }); | ||
|
|
||
| function recordStep(runsDir, outFile, env) { | ||
| const reports = fs.existsSync(runsDir) | ||
| ? fs | ||
| .globSync('*/e2e*/report.json', { cwd: runsDir }) | ||
| .sort(byDirectory) | ||
| .map(file => readJson(path.join(runsDir, file))) | ||
| : []; | ||
| const runUrl = | ||
| env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_RUN_ID | ||
| ? `${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}` | ||
| : null; | ||
| const record = { | ||
| runUrl, | ||
| commit: env.GITHUB_SHA || (reports[0]?.run.vcs?.commit ?? null), | ||
| flakes: reports.flatMap(flakesFromReport), | ||
| }; | ||
| fs.writeFileSync(outFile, `${JSON.stringify(record, null, 2)}\n`); | ||
| return record; | ||
| } | ||
|
|
||
| function readRecords(dir) { | ||
| return fs | ||
| .globSync('**/*.json', { cwd: dir }) | ||
| .sort(byDirectory) | ||
| .map(file => { | ||
| const record = readJson(path.join(dir, file)); | ||
| if (!Array.isArray(record?.flakes)) { | ||
| throw new Error(`${file} is not a record of flaky tests`); | ||
| } | ||
| return record; | ||
| }); | ||
| } | ||
|
|
||
| function main(argv, env, log = console.log) { | ||
| const [step, ...rest] = argv; | ||
| if (step === 'record' && rest.length === 2) { | ||
| const record = recordStep(rest[0], rest[1], env); | ||
| log(`Recorded ${record.flakes.length} flaky tests in ${rest[1]}.`); | ||
| return 0; | ||
| } | ||
| if (step === 'payload' && rest.length === 1) { | ||
| const payload = flakyPayload(readRecords(rest[0])); | ||
| if (payload !== null) { | ||
| log(JSON.stringify(payload)); | ||
| } | ||
| return 0; | ||
| } | ||
| log('usage: verify-flaky.mjs record <runsDir> <outFile> | payload <dir>'); | ||
| return 2; | ||
| } | ||
|
|
||
| export { flakesFromReport, flakyPayload, main, normalizeError }; | ||
|
|
||
| if (process.argv[1] !== undefined && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) { | ||
| process.exit(main(process.argv.slice(2), process.env)); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.