From 3dbcc2713eb9efe971ee17fa8520176e064312e6 Mon Sep 17 00:00:00 2001 From: spalger Date: Sat, 13 Feb 2021 13:26:29 -0700 Subject: [PATCH] [dev/ts-refs] don't use cache when building a new cache or when using --clean --- src/dev/typescript/build_ts_refs_cli.ts | 22 +++++++++++-------- .../typescript/ref_output_cache/repo_info.ts | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/dev/typescript/build_ts_refs_cli.ts b/src/dev/typescript/build_ts_refs_cli.ts index 0c4f312126762..fc8911a251773 100644 --- a/src/dev/typescript/build_ts_refs_cli.ts +++ b/src/dev/typescript/build_ts_refs_cli.ts @@ -23,13 +23,18 @@ export async function runBuildRefsCli() { async ({ log, flags }) => { const outDirs = getOutputsDeep(REF_CONFIG_PATHS); - if (flags.clean) { + const cacheEnabled = process.env.BUILD_TS_REFS_CACHE_ENABLE === 'true' || !!flags.cache; + const doCapture = process.env.BUILD_TS_REFS_CACHE_CAPTURE === 'true'; + const doClean = !!flags.clean || doCapture; + const doInitCache = cacheEnabled && !doClean; + + if (doClean) { log.info('deleting', outDirs.length, 'ts output directories'); await concurrentMap(100, outDirs, (outDir) => del(outDir)); } let outputCache; - if (flags.cache) { + if (cacheEnabled) { outputCache = await RefOutputCache.create({ log, outDirs, @@ -37,17 +42,19 @@ export async function runBuildRefsCli() { workingDir: CACHE_WORKING_DIR, upstreamUrl: 'https://github.com/elastic/kibana.git', }); + } + if (outputCache && doInitCache) { await outputCache.initCaches(); } await buildAllTsRefs(log); - if (outputCache) { - if (process.env.BUILD_TS_REFS_CACHE_CAPTURE === 'true') { - await outputCache.captureCache(Path.resolve(REPO_ROOT, 'target/ts_refs_cache')); - } + if (outputCache && doCapture) { + await outputCache.captureCache(Path.resolve(REPO_ROOT, 'target/ts_refs_cache')); + } + if (outputCache) { await outputCache.cleanup(); } }, @@ -55,9 +62,6 @@ export async function runBuildRefsCli() { description: 'Build TypeScript projects', flags: { boolean: ['clean', 'cache'], - default: { - cache: process.env.BUILD_TS_REFS_CACHE_ENABLE === 'true' ? true : false, - }, }, log: { defaultLevel: 'debug', diff --git a/src/dev/typescript/ref_output_cache/repo_info.ts b/src/dev/typescript/ref_output_cache/repo_info.ts index 5ca792332bafa..9a51f3f75182b 100644 --- a/src/dev/typescript/ref_output_cache/repo_info.ts +++ b/src/dev/typescript/ref_output_cache/repo_info.ts @@ -31,7 +31,7 @@ export class RepoInfo { this.log.info('determining merge base with upstream'); - const mergeBase = this.git(['merge-base', ref, 'FETCH_HEAD']); + const mergeBase = await this.git(['merge-base', ref, 'FETCH_HEAD']); this.log.info('merge base with', upstreamBranch, 'is', mergeBase); return mergeBase;