|
| 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 | +})(); |
0 commit comments