* Runs an AMP task with logging and timing after installing its subpackages. * @param {string} taskName * @param {TaskFuncDef} taskFunc * @return {Promise }
(taskName, taskFunc)
| 87 | * @return {Promise<void>} |
| 88 | */ |
| 89 | async function runTask(taskName, taskFunc) { |
| 90 | const taskFile = path.relative(os.homedir(), 'amp.js'); |
| 91 | log('Using task file', magenta(taskFile)); |
| 92 | const start = Date.now(); |
| 93 | try { |
| 94 | log(`Starting '${cyan(taskName)}'...`); |
| 95 | await taskFunc(); |
| 96 | log('Finished', `'${cyan(taskName)}'`, 'after', magenta(getTime(start))); |
| 97 | // For some reason, the `e2e` and `unit` tasks get stuck on CircleCI after |
| 98 | // testing is finishing, despite reaching this point in the code. This is a |
| 99 | // temporary workaround until we understand exactly why and fix the root |
| 100 | // cause. TODO(@ampproject/wg-infra): fix this. |
| 101 | if (isCircleciBuild() && ['e2e', 'unit'].includes(taskName)) { |
| 102 | process.exit(); // process.exitCode is set in ../tasks/e2e/index.js:171 |
| 103 | } |
| 104 | } catch (err) { |
| 105 | log(`'${cyan(taskName)}'`, red('errored after'), magenta(getTime(start))); |
| 106 | log(err); |
| 107 | process.exit(1); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Prints an error if the task file and / or function are invalid, and exits. |
no test coverage detected