compute hash after sorting keyFiles

This commit is contained in:
Lucas Nogueira 2022-11-05 16:18:37 -03:00
parent f9263a51b3
commit 4b699461db
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

View File

@ -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;