Skip to content

Commit 339d26f

Browse files
committed
Write CI logs and show if run is too long
1 parent d03c5ad commit 339d26f

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"release": "ts-node-script scripts/release/cli.ts",
3333
"pretest": "node tools/pretest.js",
3434
"test": "lerna run --concurrency 4 --stream test",
35-
"test:ci": "lerna run --concurrency 4 --stream test:ci",
35+
"test:ci": "export FIREBASE_CI_TEST_START_TIME=$(date +%s); lerna run --concurrency 4 --stream test:ci; node scripts/print_test_logs.js",
3636
"test:release": "lerna run --concurrency 4 --ignore @firebase/*-exp --ignore firebase-exp --stream test:ci",
3737
"test:exp": "lerna run --concurrency 4 --stream --scope @firebase/*-exp --scope firebase-exp test",
3838
"pretest:coverage": "mkdirp coverage",

scripts/print_test_logs.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
const path = require('path');
19+
const { existsSync, unlinkSync, readFileSync } = require('fs');
20+
21+
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
22+
const LOGFILE = path.join(LOGDIR, 'firebase-ci-log.txt');
23+
const SUMMARY_FILE = path.join(LOGDIR, 'firebase-ci-summary.txt');
24+
25+
// const EXCESSIVE_RUN_TIME = 1000 * 60 * 60; // 1 hour
26+
const EXCESSIVE_RUN_TIME = 1000 * 5; // 5 seconds, TEST
27+
28+
(async () => {
29+
const now = Date.now();
30+
const startTimeMillis = process.env.FIREBASE_CI_TEST_START_TIME
31+
? process.env.FIREBASE_CI_TEST_START_TIME * 1000
32+
: null;
33+
if (startTimeMillis && now - startTimeMillis > EXCESSIVE_RUN_TIME) {
34+
console.log(
35+
`Runtime of ${
36+
(now - startTimeMillis) / 1000
37+
} seconds exceeded threshold of ${EXCESSIVE_RUN_TIME / 1000} seconds.`
38+
);
39+
console.log(`Printing full logs.`);
40+
if (existsSync(SUMMARY_FILE)) {
41+
console.log(readFileSync(SUMMARY_FILE, { encoding: 'utf8' }));
42+
unlinkSync(SUMMARY_FILE);
43+
}
44+
if (existsSync(LOGFILE)) {
45+
console.log(readFileSync(LOGFILE, { encoding: 'utf8' }));
46+
unlinkSync(LOGFILE);
47+
}
48+
}
49+
})();

scripts/run_tests_in_ci.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
const { argv } = require('yargs');
1919
const path = require('path');
2020
const { spawn } = require('child-process-promise');
21+
const { appendFileSync } = require('fs');
22+
23+
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
24+
const LOGFILE = path.join(LOGDIR, 'firebase-ci-log.txt');
25+
const SUMMARY_FILE = path.join(LOGDIR, 'firebase-ci-summary.txt');
2126

2227
(async () => {
2328
const myPath = argv._[0] || '.'; // default to the current directory
@@ -38,10 +43,14 @@ const { spawn } = require('child-process-promise');
3843

3944
await testProcess;
4045
console.log('Success: ' + name);
46+
appendFileSync(LOGFILE, stdout + '\n' + stderr, { encoding: 'utf8' });
47+
appendFileSync(SUMMARY_FILE, `Success: ${name}\n`, { encoding: 'utf8' });
4148
} catch (e) {
4249
console.error('Failure: ' + name);
4350
console.log(stdout);
4451
console.error(stderr);
52+
appendFileSync(LOGFILE, stdout + '\n' + stderr, { encoding: 'utf8' });
53+
appendFileSync(SUMMARY_FILE, `Failure: ${name}\n`, { encoding: 'utf8' });
4554
process.exit(1);
4655
}
4756
})();

0 commit comments

Comments
 (0)