Skip to content

Commit ccbcadc

Browse files
authored
Show CI logs if run is longer than 1 hour (#3665)
1 parent 3b26db4 commit ccbcadc

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

.github/workflows/test-all.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ jobs:
2323
yarn
2424
- name: yarn build
2525
run: yarn build
26+
- name: Set start timestamp env var
27+
run: echo "::set-env name=FIREBASE_CI_TEST_START_TIME::$(date +%s)"
2628
- name: Run unit tests
27-
run: xvfb-run yarn test:ci
29+
run: |
30+
xvfb-run yarn test:ci
31+
node scripts/print_test_logs.js
2832
- name: Generate coverage file
2933
run: yarn ci:coverage
3034
- name: Run coverage

scripts/print_test_logs.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
const glob = require('glob');
21+
22+
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
23+
24+
const EXCESSIVE_RUN_TIME = 1000 * 60 * 60; // 1 hour
25+
26+
(async () => {
27+
const now = Date.now();
28+
const startTimeMillis = process.env.FIREBASE_CI_TEST_START_TIME
29+
? process.env.FIREBASE_CI_TEST_START_TIME * 1000
30+
: null;
31+
if (startTimeMillis && now - startTimeMillis > EXCESSIVE_RUN_TIME) {
32+
console.log(
33+
`Runtime of ${
34+
(now - startTimeMillis) / 1000
35+
} seconds exceeded threshold of ${EXCESSIVE_RUN_TIME / 1000} seconds.`
36+
);
37+
console.log(`Printing full logs.`);
38+
39+
const summaryFiles = glob.sync(path.join(LOGDIR, '*-ci-summary.txt'));
40+
const logFiles = glob.sync(path.join(LOGDIR, '*-ci-log.txt'));
41+
for (const file of summaryFiles.concat(logFiles)) {
42+
if (existsSync(file)) {
43+
console.log(readFileSync(file, { encoding: 'utf8' }));
44+
unlinkSync(file);
45+
}
46+
}
47+
}
48+
})();

scripts/run_tests_in_ci.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
const yargs = require('yargs');
1919
const path = require('path');
2020
const { spawn } = require('child-process-promise');
21+
const { writeFileSync } = require('fs');
22+
23+
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
24+
25+
function writeLogs(status, name, logText) {
26+
const safeName = name.replace(/@/g, 'at_').replace(/\//g, '_');
27+
writeFileSync(path.join(LOGDIR, `${safeName}-ci-log.txt`), logText, {
28+
encoding: 'utf8'
29+
});
30+
writeFileSync(
31+
path.join(LOGDIR, `${safeName}-ci-summary.txt`),
32+
`${status}: ${name}`,
33+
{ encoding: 'utf8' }
34+
);
35+
}
2136

2237
const argv = yargs.options({
2338
d: {
@@ -52,10 +67,12 @@ const argv = yargs.options({
5267

5368
await testProcess;
5469
console.log('Success: ' + name);
70+
writeLogs('Success', name, stdout + '\n' + stderr);
5571
} catch (e) {
5672
console.error('Failure: ' + name);
5773
console.log(stdout);
5874
console.error(stderr);
75+
writeLogs('Failure', name, stdout + '\n' + stderr);
5976
process.exit(1);
6077
}
6178
})();

0 commit comments

Comments
 (0)