From 042dfad37c522a0e2e3472f4ef6cadd060caccdd Mon Sep 17 00:00:00 2001 From: Rares Matei Date: Fri, 2 Aug 2024 13:59:08 +0100 Subject: [PATCH] add source files --- workflow-steps/cache/output/main.js | 3 +-- workflow-steps/cache/output/post.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/workflow-steps/cache/output/main.js b/workflow-steps/cache/output/main.js index 9d24c66..4214d58 100644 --- a/workflow-steps/cache/output/main.js +++ b/workflow-steps/cache/output/main.js @@ -5991,7 +5991,7 @@ function hash(input) { // main.ts var import_fs = require("fs"); var input_key = process.env.NX_CLOUD_INPUT_key; -var input_base_branch = process.env.NX_CLOUD_INPUT_base_branch; +var baseBranch = process.env.NX_CLOUD_INPUT_base_branch || process.env["NX_CLOUD_INPUT_base-branch"]; var cacheClient = createPromiseClient( CacheService, createConnectTransport({ @@ -5999,7 +5999,6 @@ var cacheClient = createPromiseClient( }) ); var currentBranch = process.env.NX_BRANCH; -var baseBranch = input_base_branch; if (!input_key) { throw new Error("No cache restore key provided."); } diff --git a/workflow-steps/cache/output/post.js b/workflow-steps/cache/output/post.js index 1a072fc..62f5a96 100644 --- a/workflow-steps/cache/output/post.js +++ b/workflow-steps/cache/output/post.js @@ -5975,6 +5975,33 @@ function hashKey(key) { function hash(input) { return crypto.createHash("sha256").update(input).digest("hex"); } +function buildCachePaths(inputPaths) { + const directories = Array.from( + new Set( + inputPaths.split("\n").filter((p) => p).reduce( + (allPaths, currPath) => [...allPaths, ...expandPath(currPath)], + [] + ) + ) + ); + const invalidDirectories = directories.filter( + (dir) => !fs.existsSync(dir) || !fs.statSync(dir).isDirectory() + ); + if (invalidDirectories.length > 0) { + throw `The following paths are not valid directories: +${invalidDirectories.join( + "\n" + )}`; + } + return directories; +} +function expandPath(pattern) { + const globExpandedPaths = import_glob.glob.sync(pattern); + if (globExpandedPaths.length == 0) { + return [pattern]; + } + return globExpandedPaths; +} // post.ts var input_key = process.env.NX_CLOUD_INPUT_key; @@ -5993,7 +6020,7 @@ if (!!cacheWasHit) { throw new Error("No cache restore key or paths provided."); } const key = hashKey(input_key); - const paths = input_paths.split("\n").filter((p) => p); + const paths = buildCachePaths(input_paths); cacheClient.storeV2( new StoreRequest({ key,