Skip to content

Commit

Permalink
use keys in pre step as well
Browse files Browse the repository at this point in the history
  • Loading branch information
rarmatei committed Dec 19, 2024
1 parent 8ed9648 commit b9bc541
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
7 changes: 5 additions & 2 deletions workflow-steps/cache/hashing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ function hash(input: string) {
return crypto.createHash('sha256').update(input).digest('hex');
}

export function buildCachePaths(inputPaths: string) {
export function buildCachePaths(
inputPaths: string,
warnInvalidPaths: boolean = true,
) {
const directories = Array.from(
new Set(
inputPaths
Expand All @@ -63,7 +66,7 @@ export function buildCachePaths(inputPaths: string) {
);

const invalidDirectories = directories.filter((dir) => !fs.existsSync(dir));
if (invalidDirectories.length > 0) {
if (invalidDirectories.length > 0 && warnInvalidPaths) {
console.warn(
`The following paths are not valid or empty:\n${invalidDirectories.join(
'\n',
Expand Down
2 changes: 1 addition & 1 deletion workflow-steps/cache/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (!inputKey || !inputPaths) {
throw new Error('No cache restore key or paths provided.');
}

const paths = buildCachePaths(inputPaths);
const paths = buildCachePaths(inputPaths, false);
const stringifiedPaths = paths.join(',');
const key = hashKey(`${inputKey}|${stringifiedPaths}`);
const currentBranchKeys = [key].map((k) => `${currentBranch}-${k}`);
Expand Down
6 changes: 3 additions & 3 deletions workflow-steps/cache/output/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5987,7 +5987,7 @@ function hashKey(key2) {
function hash(input) {
return crypto.createHash("sha256").update(input).digest("hex");
}
function buildCachePaths(inputPaths2) {
function buildCachePaths(inputPaths2, warnInvalidPaths = true) {
const directories = Array.from(
new Set(
inputPaths2.split("\n").filter((p) => p).map((p) => p.replace(/^~/, "..")).reduce(
Expand All @@ -5997,7 +5997,7 @@ function buildCachePaths(inputPaths2) {
)
);
const invalidDirectories = directories.filter((dir) => !fs.existsSync(dir));
if (invalidDirectories.length > 0) {
if (invalidDirectories.length > 0 && warnInvalidPaths) {
console.warn(
`The following paths are not valid or empty:
${invalidDirectories.join(
Expand Down Expand Up @@ -6030,7 +6030,7 @@ var currentBranch = process.env.NX_BRANCH;
if (!inputKey || !inputPaths) {
throw new Error("No cache restore key or paths provided.");
}
var paths = buildCachePaths(inputPaths);
var paths = buildCachePaths(inputPaths, false);
var stringifiedPaths = paths.join(",");
var key = hashKey(`${inputKey}|${stringifiedPaths}`);
var currentBranchKeys = [key].map((k) => `${currentBranch}-${k}`);
Expand Down
4 changes: 2 additions & 2 deletions workflow-steps/cache/output/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -5975,7 +5975,7 @@ function hashKey(key) {
function hash(input) {
return crypto.createHash("sha256").update(input).digest("hex");
}
function buildCachePaths(inputPaths2) {
function buildCachePaths(inputPaths2, warnInvalidPaths = true) {
const directories = Array.from(
new Set(
inputPaths2.split("\n").filter((p) => p).map((p) => p.replace(/^~/, "..")).reduce(
Expand All @@ -5985,7 +5985,7 @@ function buildCachePaths(inputPaths2) {
)
);
const invalidDirectories = directories.filter((dir) => !fs.existsSync(dir));
if (invalidDirectories.length > 0) {
if (invalidDirectories.length > 0 && warnInvalidPaths) {
console.warn(
`The following paths are not valid or empty:
${invalidDirectories.join(
Expand Down
3 changes: 0 additions & 3 deletions workflow-steps/install-node-modules/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ function getInstallCommand() {
return 'yarn install --frozen-lockfile';
}
} else if (existsSync('pnpm-lock.yaml') || existsSync('pnpm-lock.yml')) {
if (platform === 'win32') {
return 'pnpm install --frozen-lockfile';
}
return 'pnpm install --frozen-lockfile';
}
}
Expand Down

0 comments on commit b9bc541

Please sign in to comment.