Skip to content

Commit 9bc6ef8

Browse files
committed
Write CI logs and show if run is too long
1 parent 05f8002 commit 9bc6ef8

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

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 yargs = 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
const argv = yargs.options({
2328
d: {
@@ -52,10 +57,14 @@ const argv = yargs.options({
5257

5358
await testProcess;
5459
console.log('Success: ' + name);
60+
appendFileSync(LOGFILE, stdout + '\n' + stderr, { encoding: 'utf8' });
61+
appendFileSync(SUMMARY_FILE, `Success: ${name}\n`, { encoding: 'utf8' });
5562
} catch (e) {
5663
console.error('Failure: ' + name);
5764
console.log(stdout);
5865
console.error(stderr);
66+
appendFileSync(LOGFILE, stdout + '\n' + stderr, { encoding: 'utf8' });
67+
appendFileSync(SUMMARY_FILE, `Failure: ${name}\n`, { encoding: 'utf8' });
5968
process.exit(1);
6069
}
6170
})();

0 commit comments

Comments
 (0)