only hash Cargo.toml/Cargo.lock that belong to a configured workspace

This commit is contained in:
Lucas Nogueira 2022-11-05 11:34:55 -03:00
parent b5ec9edd91
commit 88f224fae6
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1
3 changed files with 84 additions and 61 deletions

45
dist/restore/index.js vendored
View File

@ -64603,25 +64603,6 @@ class CacheConfig {
// might create/overwrite lockfiles.
let lockHash = lib_core.getState(STATE_LOCKFILE_HASH);
let keyFiles = JSON.parse(lib_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 = external_crypto_default().createHash("sha1");
for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) {
hasher.update(chunk);
}
}
lockHash = hasher.digest("hex");
lib_core.saveState(STATE_LOCKFILE_HASH, lockHash);
lib_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.
const workspaces = [];
@ -64633,6 +64614,32 @@ class CacheConfig {
workspaces.push(new Workspace(root, target));
}
self.workspaces = workspaces;
if (!lockHash) {
hasher = external_crypto_default().createHash("sha1");
async function globHash(pattern) {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
keyFiles = keyFiles.concat(await globber.glob());
keyFiles.sort((a, b) => a.localeCompare(b));
for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) {
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");
lib_core.saveState(STATE_LOCKFILE_HASH, lockHash);
lib_core.saveState(STATE_LOCKFILES, JSON.stringify(keyFiles));
}
self.keyFiles = keyFiles;
key += `-${lockHash}`;
self.cacheKey = key;
self.cachePaths = [config_CARGO_HOME];
const cacheTargets = lib_core.getInput("cache-targets").toLowerCase();
if (cacheTargets === "true") {

45
dist/save/index.js vendored
View File

@ -64603,25 +64603,6 @@ class CacheConfig {
// might create/overwrite lockfiles.
let lockHash = core.getState(STATE_LOCKFILE_HASH);
let keyFiles = 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 = external_crypto_default().createHash("sha1");
for (const file of keyFiles) {
for await (const chunk of external_fs_default().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.
const workspaces = [];
@ -64633,6 +64614,32 @@ class CacheConfig {
workspaces.push(new Workspace(root, target));
}
self.workspaces = workspaces;
if (!lockHash) {
hasher = external_crypto_default().createHash("sha1");
async function globHash(pattern) {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
keyFiles = keyFiles.concat(await globber.glob());
keyFiles.sort((a, b) => a.localeCompare(b));
for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) {
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");
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") {

View File

@ -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,38 @@ export class CacheConfig {
}
self.workspaces = workspaces;
if (!lockHash) {
hasher = crypto.createHash("sha1");
async function globHash(pattern: string): Promise<void> {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
keyFiles = keyFiles.concat(await globber.glob());
keyFiles.sort((a, b) => a.localeCompare(b));
for (const file of keyFiles) {
for await (const chunk of fs.createReadStream(file)) {
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");
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") {