({name, workflow, prepare, cleanup}: Workflow)
| 3 | import path from 'path'; |
| 4 | import {getBazelBin} from '../../utils/bazel-bin.js'; |
| 5 | import {ChildProcess} from '../../utils/child-process.js'; |
| 6 | import { |
| 7 | getExcludedDirsForCwd, |
| 8 | getPathFromEnvironment, |
| 9 | resolveSafeExecutable, |
| 10 | } from '../../utils/environment.js'; |
| 11 | import {Spinner} from '../../utils/spinner.js'; |
| 12 | import {Workflow} from './loader.js'; |
| 13 | |
| 14 | export async function measureWorkflow({name, workflow, prepare, cleanup}: Workflow) { |
| 15 | const spinner = new Spinner(); |
| 16 | const bazelShimDir = createFallbackBazelBinDir(); |
| 17 | const commandEnv = bazelShimDir |
| 18 | ? { |
| 19 | ...process.env, |
| 20 | PATH: [bazelShimDir, getPathFromEnvironment(process.env)] |
| 21 | .filter(Boolean) |
| 22 | .join(path.delimiter), |
| 23 | } |
| 24 | : undefined; |
| 25 | |
| 26 | try { |
| 27 | if (prepare) { |
| 28 | spinner.update('Preparing environment for workflow execution'); |
| 29 | // Run the `prepare` commands to establish the environment, caching, etc prior to running the |
| 30 | // workflow. |
| 31 | await runCommands(prepare, commandEnv); |
| 32 | spinner.update('Environment preperation completed'); |
| 33 | } |
| 34 | |
| 35 | spinner.update(`Executing workflow (${name})`); |
| 36 | // Mark the start time of the workflow, execute all of the commands provided in the workflow and |
| 37 | // then mark the ending time. |
| 38 | performance.mark('start'); |
| 39 | await runCommands(workflow, commandEnv); |
| 40 | performance.mark('end'); |
| 41 | |
| 42 | spinner.update('Workflow completed'); |
| 43 | |
| 44 | if (cleanup) { |
| 45 | spinner.update('Cleaning up environment after workflow'); |
| 46 | // Run the clean up commands to reset the environment and undo changes made during the workflow. |
no test coverage detected