From 4e79446dc91e2ff84fe52aa79e16f501bb30b7bf Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 27 Mar 2020 11:49:32 +0100 Subject: [PATCH] cli/commands/build-cache: run build command --- packages/cli/src/commands/build-cache/index.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/build-cache/index.ts b/packages/cli/src/commands/build-cache/index.ts index 5fe9852a28..6ae1844412 100644 --- a/packages/cli/src/commands/build-cache/index.ts +++ b/packages/cli/src/commands/build-cache/index.ts @@ -25,6 +25,7 @@ import { exec as execCb } from 'child_process'; import { Command } from 'commander'; import tar from 'tar'; import { ExitCodeError } from '../../helpers/errors'; +import { run } from '../../helpers/run'; const exec = promisify(execCb); const INFO_FILE = '.backstage-build-cache'; @@ -38,7 +39,7 @@ type Options = { }; async function parseOptions(cmd: Command): Promise { - const repoRoot = await run('git rev-parse --show-toplevel'); + const repoRoot = await cmdOutput('git rev-parse --show-toplevel'); const argTransformer = (arg: string) => resolvePath(arg.replace(//g, repoRoot).replace(/'/g, '')); @@ -67,11 +68,11 @@ export default async (cmd: Command, args: string[]) => { const cacheHit = cache.readable && cache.trees?.join(',') === trees.join(','); if (cacheHit) { - print('cache hit, no need to build'); - if (cache.needsCopy) { - print('copying external cache to build output dir'); + print('external cache hit, copying from external cache'); await copyFromExternalCache(cache, options); + } else { + print('cache hit, nothing to be done'); } } else { print('cache miss, need to build'); @@ -108,11 +109,11 @@ async function copyFromExternalCache( await tar.extract({ file: cache.archivePath, cwd: options.output }); } -async function build(args: string[]): Promise { - console.log(`Will build using '${args.join(' ')}'`); +async function build([prog, ...args]: string[]): Promise { + await run(prog, args); } -async function run(cmd: string) { +async function cmdOutput(cmd: string) { try { const { stdout } = await exec(cmd); return stdout.trim(); @@ -219,7 +220,7 @@ async function readInfoFileFromArchive( async function getInputHashes(options: Options): Promise { const trees = []; for (const input of options.inputs) { - const output = await run(`git ls-tree HEAD '${input}'`); + const output = await cmdOutput(`git ls-tree HEAD '${input}'`); const [, , sha] = output.split(/\s+/, 3); trees.push(sha); }