mirror of
https://github.com/Swatinem/rust-cache
synced 2025-08-16 01:45:30 +00:00
Include env vars in the generated cache key
This commit is contained in:
parent
f8f67b7515
commit
5f6b32160d
4 changed files with 591 additions and 558 deletions
10
dist/restore/index.js
vendored
10
dist/restore/index.js
vendored
|
@ -59564,6 +59564,7 @@ async function getCacheConfig() {
|
|||
key += `${job}-`;
|
||||
}
|
||||
}
|
||||
key += `${getEnvKey()}-`;
|
||||
key += await getRustKey();
|
||||
return {
|
||||
paths: [
|
||||
|
@ -59594,6 +59595,15 @@ async function getCargoBins() {
|
|||
return new Set();
|
||||
}
|
||||
}
|
||||
function getEnvKey() {
|
||||
const hasher = external_crypto_default().createHash("sha1");
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (value) {
|
||||
hasher.update(`${key}=${value}`);
|
||||
}
|
||||
}
|
||||
return hasher.digest("hex").slice(0, 20);
|
||||
}
|
||||
async function getRustKey() {
|
||||
const rustc = await getRustVersion();
|
||||
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;
|
||||
|
|
10
dist/save/index.js
vendored
10
dist/save/index.js
vendored
|
@ -59564,6 +59564,7 @@ async function getCacheConfig() {
|
|||
key += `${job}-`;
|
||||
}
|
||||
}
|
||||
key += `${getEnvKey()}-`;
|
||||
key += await getRustKey();
|
||||
return {
|
||||
paths: [
|
||||
|
@ -59594,6 +59595,15 @@ async function getCargoBins() {
|
|||
return new Set();
|
||||
}
|
||||
}
|
||||
function getEnvKey() {
|
||||
const hasher = external_crypto_default().createHash("sha1");
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (value) {
|
||||
hasher.update(`${key}=${value}`);
|
||||
}
|
||||
}
|
||||
return hasher.digest("hex").slice(0, 20);
|
||||
}
|
||||
async function getRustKey() {
|
||||
const rustc = await getRustVersion();
|
||||
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;
|
||||
|
|
1
package-lock.json
generated
1
package-lock.json
generated
|
@ -5,6 +5,7 @@
|
|||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rust-cache",
|
||||
"version": "1.2.0",
|
||||
"license": "LGPL-3.0",
|
||||
"dependencies": {
|
||||
|
|
|
@ -71,6 +71,7 @@ export async function getCacheConfig(): Promise<CacheConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
key += `${getEnvKey()}-`;
|
||||
key += await getRustKey();
|
||||
|
||||
return {
|
||||
|
@ -105,6 +106,17 @@ export async function getCargoBins(): Promise<Set<string>> {
|
|||
}
|
||||
}
|
||||
|
||||
function getEnvKey(): string {
|
||||
const hasher = crypto.createHash("sha1");
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (value) {
|
||||
hasher.update(`${key}=${value}`);
|
||||
}
|
||||
}
|
||||
|
||||
return hasher.digest("hex").slice(0, 20);
|
||||
}
|
||||
|
||||
async function getRustKey(): Promise<string> {
|
||||
const rustc = await getRustVersion();
|
||||
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;
|
||||
|
@ -249,5 +261,5 @@ export async function rm(parent: string, dirent: fs.Dirent) {
|
|||
} else if (dirent.isDirectory()) {
|
||||
await io.rmRF(fileName);
|
||||
}
|
||||
} catch {}
|
||||
} catch { }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue