MCPcopy
hub / github.com/ampproject/amphtml / runTask

Function runTask

build-system/task-runner/amp-task-runner.js:89–109  ·  view source on GitHub ↗

* Runs an AMP task with logging and timing after installing its subpackages. * @param {string} taskName * @param {TaskFuncDef} taskFunc * @return {Promise }

(taskName, taskFunc)

Source from the content-addressed store, hash-verified

87 * @return {Promise<void>}
88 */
89async 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.

Callers 1

createTaskFunction · 0.70

Calls 7

cyanFunction · 0.85
isCircleciBuildFunction · 0.85
redFunction · 0.85
nowMethod · 0.80
exitMethod · 0.80
getTimeFunction · 0.70
logFunction · 0.50

Tested by

no test coverage detected