Include env vars in the generated cache key

This commit is contained in:
Dominik Nakamura 2021-10-07 11:35:31 +09:00
parent f8f67b7515
commit 5f6b32160d
No known key found for this signature in database
GPG Key ID: E4C6A749B2491910
4 changed files with 591 additions and 558 deletions

10
dist/restore/index.js vendored
View File

@ -59564,6 +59564,7 @@ async function getCacheConfig() {
key += `${job}-`; key += `${job}-`;
} }
} }
key += `${getEnvKey()}-`;
key += await getRustKey(); key += await getRustKey();
return { return {
paths: [ paths: [
@ -59594,6 +59595,15 @@ async function getCargoBins() {
return new Set(); 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() { async function getRustKey() {
const rustc = await getRustVersion(); const rustc = await getRustVersion();
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;

10
dist/save/index.js vendored
View File

@ -59564,6 +59564,7 @@ async function getCacheConfig() {
key += `${job}-`; key += `${job}-`;
} }
} }
key += `${getEnvKey()}-`;
key += await getRustKey(); key += await getRustKey();
return { return {
paths: [ paths: [
@ -59594,6 +59595,15 @@ async function getCargoBins() {
return new Set(); 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() { async function getRustKey() {
const rustc = await getRustVersion(); const rustc = await getRustVersion();
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;

1
package-lock.json generated
View File

@ -5,6 +5,7 @@
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "rust-cache",
"version": "1.2.0", "version": "1.2.0",
"license": "LGPL-3.0", "license": "LGPL-3.0",
"dependencies": { "dependencies": {

View File

@ -71,6 +71,7 @@ export async function getCacheConfig(): Promise<CacheConfig> {
} }
} }
key += `${getEnvKey()}-`;
key += await getRustKey(); key += await getRustKey();
return { 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> { async function getRustKey(): Promise<string> {
const rustc = await getRustVersion(); const rustc = await getRustVersion();
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;