Skip to content

Commit

Permalink
ci: add job summary to the test suite runs (#56742)
Browse files Browse the repository at this point in the history
This PR adds Github Actions summaries to the test suite that runs in the CI so that you can easily visualise which tests failed + what the relevant log was instead of parsing the logs yourself.

Example here https://github.com/vercel/next.js/actions/runs/6495658699

![CleanShot 2023-10-12 at 14 57 32@2x](https://github.com/vercel/next.js/assets/11064311/7d65496b-6e28-460a-8bef-3f2e91266d00)
  • Loading branch information
feedthejim committed Oct 12, 2023
1 parent b6cce9c commit 62ab0e3
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"update-google-fonts": "node ./scripts/update-google-fonts.js"
},
"devDependencies": {
"@actions/core": "1.10.1",
"@babel/core": "7.18.0",
"@babel/eslint-parser": "7.18.2",
"@babel/generator": "7.18.0",
Expand Down
34 changes: 34 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { spawn, exec: execOrig } = require('child_process')
const { createNextInstall } = require('./test/lib/create-next-install')
const glob = promisify(_glob)
const exec = promisify(execOrig)
const core = require('@actions/core')

function escapeRegexp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
Expand Down Expand Up @@ -73,6 +74,45 @@ const mockTrace = () => ({

// which types we have configured to run separate
const configuredTestTypes = Object.values(testFilters)
const errorsPerTests = new Map()

async function maybeLogSummary() {
if (process.env.CI && errorsPerTests.size > 0) {
const outputTemplate = `
${Array.from(errorsPerTests.entries())
.map(([test, output]) => {
return `
<details>
<summary>${test}</summary>
\`\`\`
${output}
\`\`\`
</details>
`
})
.join('\n')}`

await core.summary
.addHeading('Tests failures')
.addTable([
[
{
data: 'Test suite',
header: true,
},
],
...Array.from(errorsPerTests.entries()).map(([test]) => {
return [
`<a href="https://github.com/vercel/next.js/blob/canary/${test}">${test}</a>`,
]
}),
])
.addRaw(outputTemplate)
.write()
}
}

const cleanUpAndExit = async (code) => {
if (process.env.NEXT_TEST_STARTER) {
Expand All @@ -81,6 +121,9 @@ const cleanUpAndExit = async (code) => {
if (process.env.NEXT_TEST_TEMP_REPO) {
await fs.remove(process.env.NEXT_TEST_TEMP_REPO)
}
if (process.env.CI) {
await maybeLogSummary()
}
console.log(`exiting with code ${code}`)

setTimeout(() => {
Expand Down Expand Up @@ -472,11 +515,19 @@ ${ENDGROUP}`)
} else {
process.stdout.write(`${GROUP}${test.file} output\n`)
}

let output = ''
// limit out to last 64kb so that we don't
// run out of log room in CI
for (const { chunk } of outputChunks) {
process.stdout.write(chunk)
output += chunk.toString()
}

if (process.env.CI && !killed) {
errorsPerTests.set(test.file, output)
}

if (isExpanded) {
process.stdout.write(`end of ${test.file} output\n`)
} else {
Expand Down

0 comments on commit 62ab0e3

Please sign in to comment.