Skip to content

Show CI logs if run is longer than 1 hour #3665

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

Merged
merged 5 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ jobs:
yarn
- name: yarn build
run: yarn build
- name: Set start timestamp env var
run: echo "::set-env name=FIREBASE_CI_TEST_START_TIME::$(date +%s)"
- name: Run unit tests
run: xvfb-run yarn test:ci
run: |
xvfb-run yarn test:ci
node scripts/print_test_logs.js
- name: Generate coverage file
run: yarn ci:coverage
- name: Run coverage
Expand Down
48 changes: 48 additions & 0 deletions scripts/print_test_logs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const path = require('path');
const { existsSync, unlinkSync, readFileSync } = require('fs');
const glob = require('glob');

const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';

const EXCESSIVE_RUN_TIME = 1000 * 60 * 60; // 1 hour

(async () => {
const now = Date.now();
const startTimeMillis = process.env.FIREBASE_CI_TEST_START_TIME
? process.env.FIREBASE_CI_TEST_START_TIME * 1000
: null;
if (startTimeMillis && now - startTimeMillis > EXCESSIVE_RUN_TIME) {
console.log(
`Runtime of ${
(now - startTimeMillis) / 1000
} seconds exceeded threshold of ${EXCESSIVE_RUN_TIME / 1000} seconds.`
);
console.log(`Printing full logs.`);

const summaryFiles = glob.sync(path.join(LOGDIR, '*-ci-summary.txt'));
const logFiles = glob.sync(path.join(LOGDIR, '*-ci-log.txt'));
for (const file of summaryFiles.concat(logFiles)) {
if (existsSync(file)) {
console.log(readFileSync(file, { encoding: 'utf8' }));
unlinkSync(file);
}
}
}
})();
17 changes: 17 additions & 0 deletions scripts/run_tests_in_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
const yargs = require('yargs');
const path = require('path');
const { spawn } = require('child-process-promise');
const { writeFileSync } = require('fs');

const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';

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: {
Expand Down Expand Up @@ -52,10 +67,12 @@ const argv = yargs.options({

await testProcess;
console.log('Success: ' + name);
writeLogs('Success', name, stdout + '\n' + stderr);
} catch (e) {
console.error('Failure: ' + name);
console.log(stdout);
console.error(stderr);
writeLogs('Failure', name, stdout + '\n' + stderr);
process.exit(1);
}
})();