Skip to content

Commit

Permalink
add source files
Browse files Browse the repository at this point in the history
  • Loading branch information
rarmatei committed Aug 2, 2024
1 parent 5b346fa commit 042dfad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 1 addition & 2 deletions workflow-steps/cache/output/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5991,15 +5991,14 @@ 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({
baseUrl: "http://127.0.0.1:9000"
})
);
var currentBranch = process.env.NX_BRANCH;
var baseBranch = input_base_branch;
if (!input_key) {
throw new Error("No cache restore key provided.");
}
Expand Down
29 changes: 28 additions & 1 deletion workflow-steps/cache/output/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 042dfad

Please sign in to comment.