-
Notifications
You must be signed in to change notification settings - Fork 1k
ci: add test workflow step to output logs #10347
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
base: main
Are you sure you want to change the base?
Changes from all commits
1b3b5d3
35d625f
f9366f4
5462612
b286522
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ logs | |
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .ci-logs | ||
|
|
||
| # Runtime data | ||
| pids | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,4 +106,13 @@ | |
| testLog(message, 'warn', false); | ||
| testLog(message, 'error', false); | ||
| }); | ||
|
|
||
| it('deliberate crash for CI verification', () => { | ||
| console.log('MARKER: executing deliberate crash in logger.test.ts'); | ||
| if (typeof process !== 'undefined' && process.kill) { | ||
| process.kill(process.pid, 'SIGKILL'); | ||
| } else { | ||
| throw new Error('DELIBERATE_CI_TEST_CRASH'); | ||
|
Check failure on line 115 in packages/logger/test/logger.test.ts
|
||
| } | ||
| }); | ||
|
Comment on lines
+110
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,13 @@ | |
|
|
||
| const yargs = require('yargs'); | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
| const { spawn } = require('child-process-promise'); | ||
| const { writeFileSync } = require('fs'); | ||
|
|
||
| const LOGDIR = process.env.CI ? process.env.HOME : '/tmp'; | ||
| const LOGDIR = | ||
| process.env.FIREBASE_CI_LOG_DIR || | ||
| (process.env.CI ? process.env.HOME : '/tmp'); | ||
|
|
||
| // Maps the packages where we should not run `test:all` and instead isolate the cross-browser tests. | ||
| // TODO(dwyfrequency): Update object with `storage` and `firestore` packages. | ||
| const crossBrowserPackages = { | ||
|
|
@@ -32,18 +35,6 @@ const crossBrowserPackages = { | |
| 'packages/storage-compat': 'test:browser:unit' | ||
| }; | ||
|
|
||
| function writeLogs(status, name, logText) { | ||
| const safeName = name.replace(/@/g, 'at_').replace(/\//g, '_'); | ||
| writeFileSync(path.join(LOGDIR, `${safeName}-ci-log.txt`), logText, { | ||
| encoding: 'utf8' | ||
| }); | ||
| writeFileSync( | ||
| path.join(LOGDIR, `${safeName}-ci-summary.txt`), | ||
| `${status}: ${name}`, | ||
| { encoding: 'utf8' } | ||
| ); | ||
| } | ||
|
|
||
| const argv = yargs.options({ | ||
| d: { | ||
| type: 'string', | ||
|
|
@@ -63,49 +54,47 @@ const argv = yargs.options({ | |
| const dir = path.resolve(myPath); | ||
| const { name, scripts } = require(`${dir}/package.json`); | ||
|
|
||
| let testProcessOutput = ''; | ||
| try { | ||
| if (process.env?.BROWSERS) { | ||
| if (scripts['test:browser']) { | ||
| scriptName = 'test:browser'; | ||
| } | ||
| for (const package in crossBrowserPackages) { | ||
| if (dir.endsWith(package)) { | ||
| scriptName = crossBrowserPackages[package]; | ||
| } | ||
| if (process.env?.BROWSERS) { | ||
| if (scripts['test:browser']) { | ||
| scriptName = 'test:browser'; | ||
| } | ||
| for (const package in crossBrowserPackages) { | ||
| if (dir.endsWith(package)) { | ||
| scriptName = crossBrowserPackages[package]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const browser = process.env.BROWSERS ?? 'chrome/node'; | ||
| const safeName = name.replace(/@/g, 'at_').replace(/\//g, '_'); | ||
|
|
||
| console.log( | ||
| `[${name}][${ | ||
| process.env.BROWSERS ?? 'chrome/node' | ||
| }]: Running script ${scriptName}` | ||
| ); | ||
| const logFile = path.join(LOGDIR, `${safeName}-ci-log.txt`); | ||
| const summaryFile = path.join(LOGDIR, `${safeName}-ci-summary.txt`); | ||
| const logStream = fs.createWriteStream(logFile); | ||
|
|
||
| const testProcess = spawn('yarn', ['--cwd', dir, scriptName]); | ||
| console.log(`[${name}][${browser}]: Running script ${scriptName}`); | ||
|
|
||
| testProcess.childProcess.stdout.on('data', data => { | ||
| testProcessOutput += '[stdout]' + data.toString(); | ||
| }); | ||
| testProcess.childProcess.stderr.on('data', data => { | ||
| testProcessOutput += '[stderr]' + data.toString(); | ||
| }); | ||
| const testProcess = spawn('yarn', ['--cwd', dir, scriptName]); | ||
|
|
||
| testProcess.childProcess.stdout.pipe(logStream, { end: false }); | ||
| testProcess.childProcess.stderr.pipe(logStream, { end: false }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate lines expected? |
||
|
|
||
| try { | ||
| await testProcess; | ||
| await new Promise(resolve => logStream.end(resolve)); | ||
| fs.writeFileSync(summaryFile, `Success: ${name}`); | ||
| console.log('Success: ' + name); | ||
|
Comment on lines
+77
to
86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If To make this robust, we should define async function recordManifest(status, exitCode) {
try {
await new Promise(resolve => logStream.end(resolve));
} catch (e) {}
try {
const manifestPath = path.join(
manifestsDir,
`${safeName}-${safeScript}.json`
);
fs.writeFileSync(
manifestPath,
JSON.stringify({
packageName: name,
scriptName,
status,
exitCode,
logFile
})
);
} catch (e) {}
}
try {
const testProcess = spawn('yarn', ['--cwd', dir, scriptName]);
if (testProcess.childProcess) {
if (testProcess.childProcess.stdout) {
testProcess.childProcess.stdout.pipe(logStream, { end: false });
}
if (testProcess.childProcess.stderr) {
testProcess.childProcess.stderr.pipe(logStream, { end: false });
}
}
await testProcess;
await recordManifest('Success', 0);
console.log('Success: ' + name); |
||
| writeLogs('Success', name, testProcessOutput); | ||
| } catch (e) { | ||
| await new Promise(resolve => logStream.end(resolve)); | ||
| fs.writeFileSync(summaryFile, `Failure: ${name}`); | ||
| console.error('Failure: ' + name); | ||
| console.error(testProcessOutput); | ||
|
|
||
| if (process.env.CHROME_VERSION_NOTES) { | ||
| console.error(); | ||
| console.error(process.env.CHROME_VERSION_NOTES); | ||
| console.error(); | ||
| } | ||
|
|
||
| writeLogs('Failure', name, testProcessOutput); | ||
|
|
||
| process.exit(1); | ||
| } | ||
| })(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there value in printing the logs if the previous step failed?