mirror of
https://github.com/Swatinem/rust-cache.git
synced 2025-08-15 05:05:09 +00:00
compute hash after sorting keyFiles
This commit is contained in:
parent
f9263a51b3
commit
4b699461db
@ -36,7 +36,7 @@ export class CacheConfig {
|
|||||||
/** The files considered for the cache key */
|
/** The files considered for the cache key */
|
||||||
private keyFiles: Array<string> = [];
|
private keyFiles: Array<string> = [];
|
||||||
|
|
||||||
private constructor() {}
|
private constructor() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a [`CacheConfig`] with all the paths and keys.
|
* Constructs a [`CacheConfig`] with all the paths and keys.
|
||||||
@ -116,7 +116,6 @@ export class CacheConfig {
|
|||||||
// might create/overwrite lockfiles.
|
// might create/overwrite lockfiles.
|
||||||
|
|
||||||
let lockHash = core.getState(STATE_LOCKFILE_HASH);
|
let lockHash = core.getState(STATE_LOCKFILE_HASH);
|
||||||
let keyFiles: Array<string> = JSON.parse(core.getState(STATE_LOCKFILES) || "[]");
|
|
||||||
|
|
||||||
// Constructs the workspace config and paths to restore:
|
// Constructs the workspace config and paths to restore:
|
||||||
// The workspaces are given using a `$workspace -> $target` syntax.
|
// The workspaces are given using a `$workspace -> $target` syntax.
|
||||||
@ -131,14 +130,24 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
self.workspaces = workspaces;
|
self.workspaces = workspaces;
|
||||||
|
|
||||||
|
let keyFiles: Array<string> = JSON.parse(core.getState(STATE_LOCKFILES) || "[]");
|
||||||
|
|
||||||
if (!lockHash) {
|
if (!lockHash) {
|
||||||
hasher = crypto.createHash("sha1");
|
hasher = crypto.createHash("sha1");
|
||||||
|
|
||||||
async function globHash(pattern: string): Promise<void> {
|
async function globHash(pattern: string): Promise<string[]> {
|
||||||
const globber = await glob.create(pattern, {
|
const globber = await glob.create(pattern, {
|
||||||
followSymbolicLinks: false,
|
followSymbolicLinks: false,
|
||||||
});
|
});
|
||||||
keyFiles = keyFiles.concat(await globber.glob());
|
return await globber.glob();
|
||||||
|
}
|
||||||
|
|
||||||
|
keyFiles = keyFiles.concat(await globHash("rust-toolchain\nrust-toolchain.toml"));
|
||||||
|
for (const workspace of workspaces) {
|
||||||
|
const root = workspace.root;
|
||||||
|
keyFiles = keyFiles.concat(await globHash(`${root}/**/Cargo.toml\n${root}/**/Cargo.lock`));
|
||||||
|
}
|
||||||
|
|
||||||
keyFiles.sort((a, b) => a.localeCompare(b));
|
keyFiles.sort((a, b) => a.localeCompare(b));
|
||||||
|
|
||||||
for (const file of keyFiles) {
|
for (const file of keyFiles) {
|
||||||
@ -146,13 +155,7 @@ export class CacheConfig {
|
|||||||
hasher.update(chunk);
|
hasher.update(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await globHash("rust-toolchain\nrust-toolchain.toml");
|
|
||||||
for (const workspace of workspaces) {
|
|
||||||
const root = workspace.root;
|
|
||||||
await globHash(`${root}/**/Cargo.toml\n${root}/**/Cargo.lock`);
|
|
||||||
}
|
|
||||||
lockHash = hasher.digest("hex");
|
lockHash = hasher.digest("hex");
|
||||||
|
|
||||||
core.saveState(STATE_LOCKFILE_HASH, lockHash);
|
core.saveState(STATE_LOCKFILE_HASH, lockHash);
|
||||||
@ -160,6 +163,7 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.keyFiles = keyFiles;
|
self.keyFiles = keyFiles;
|
||||||
|
|
||||||
key += `-${lockHash}`;
|
key += `-${lockHash}`;
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user