mirror of
https://github.com/Swatinem/rust-cache.git
synced 2024-11-23 06:16:07 +08:00
only hash Cargo.toml/Cargo.lock that belong to a configured workspace (#90)
This commit is contained in:
parent
b5ec9edd91
commit
ccdddcc049
@ -118,29 +118,6 @@ export class CacheConfig {
|
||||
let lockHash = core.getState(STATE_LOCKFILE_HASH);
|
||||
let keyFiles: Array<string> = JSON.parse(core.getState(STATE_LOCKFILES) || "[]");
|
||||
|
||||
if (!lockHash) {
|
||||
const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", {
|
||||
followSymbolicLinks: false,
|
||||
});
|
||||
keyFiles = await globber.glob();
|
||||
keyFiles.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
hasher = crypto.createHash("sha1");
|
||||
for (const file of keyFiles) {
|
||||
for await (const chunk of fs.createReadStream(file)) {
|
||||
hasher.update(chunk);
|
||||
}
|
||||
}
|
||||
lockHash = hasher.digest("hex");
|
||||
|
||||
core.saveState(STATE_LOCKFILE_HASH, lockHash);
|
||||
core.saveState(STATE_LOCKFILES, JSON.stringify(keyFiles));
|
||||
}
|
||||
|
||||
self.keyFiles = keyFiles;
|
||||
key += `-${lockHash}`;
|
||||
self.cacheKey = key;
|
||||
|
||||
// Constructs the workspace config and paths to restore:
|
||||
// The workspaces are given using a `$workspace -> $target` syntax.
|
||||
|
||||
@ -154,6 +131,41 @@ export class CacheConfig {
|
||||
}
|
||||
self.workspaces = workspaces;
|
||||
|
||||
if (!lockHash) {
|
||||
hasher = crypto.createHash("sha1");
|
||||
|
||||
async function globHash(pattern: string): Promise<string[]> {
|
||||
const globber = await glob.create(pattern, {
|
||||
followSymbolicLinks: false,
|
||||
});
|
||||
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\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`));
|
||||
}
|
||||
|
||||
keyFiles.sort((a, b) => a.localeCompare(b));
|
||||
|
||||
for (const file of keyFiles) {
|
||||
for await (const chunk of fs.createReadStream(file)) {
|
||||
hasher.update(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
lockHash = hasher.digest("hex");
|
||||
|
||||
core.saveState(STATE_LOCKFILE_HASH, lockHash);
|
||||
core.saveState(STATE_LOCKFILES, JSON.stringify(keyFiles));
|
||||
}
|
||||
|
||||
self.keyFiles = keyFiles;
|
||||
|
||||
key += `-${lockHash}`;
|
||||
self.cacheKey = key;
|
||||
|
||||
self.cachePaths = [CARGO_HOME];
|
||||
const cacheTargets = core.getInput("cache-targets").toLowerCase();
|
||||
if (cacheTargets === "true") {
|
||||
|
Loading…
Reference in New Issue
Block a user