From 2bcc375de8fcb0976a623398884d55f91a8784c8 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Sat, 3 Oct 2020 17:33:09 +0200 Subject: [PATCH] key target by job id automatically --- README.md | 17 +++++------------ dist/restore/index.js | 6 +++++- dist/save/index.js | 6 +++++- src/common.ts | 6 +++++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ed0f254..cbf0869 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,10 @@ A GitHub Action that implements smart caching for rust/cargo projects -## Inputs - -- `key` - An optional key for the `target` cache. This is useful in case you - have different jobs for test / check / clippy, etc - ## Example usage ```yaml - uses: Swatinem/rust-cache@v1 - with: - key: test ``` ## Specifics @@ -26,9 +19,9 @@ target ``` It disables incremental compilation and only caches dependencies. The -assumption is that we will likely recompile the own crate(s) anyway. +assumption is that we will likely recompile our own crate(s) anyway. -It also separates the cache into 4 groups, each treated differently: +It also separates the cache into 3 groups, each treated differently: - Registry Index: `~/.cargo/registry/index/`: @@ -42,6 +35,6 @@ It also separates the cache into 4 groups, each treated differently: - target: `./target` - Automatically keyed by the lockfile/toml hash, and is being pruned to only - persist the dependencies that are being used. This is especially throwing - away any intermediate artifacts. + Automatically keyed by the lockfile, toml hash and job, and is being pruned + to only persist the dependencies that are being used. This is especially + throwing away any intermediate artifacts. diff --git a/dist/restore/index.js b/dist/restore/index.js index fde616b..cdbba47 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -54616,7 +54616,7 @@ const home = external_os_default().homedir(); const paths = { index: external_path_default().join(home, ".cargo/registry/index"), cache: external_path_default().join(home, ".cargo/registry/cache"), - git: external_path_default().join(home, ".cargo/git/db"), + // git: path.join(home, ".cargo/git/db"), target: "target", }; const RefKey = "GITHUB_REF"; @@ -54634,6 +54634,10 @@ async function getCaches() { if (targetKey) { targetKey = `${targetKey}-`; } + const job = process.env.GITHUB_JOB; + if (job) { + targetKey = `${job}-${targetKey}`; + } const registryIndex = `v0-registry-index`; const registryCache = `v0-registry-cache`; const target = `v0-target-${targetKey}${rustKey}`; diff --git a/dist/save/index.js b/dist/save/index.js index 16b1fe2..81bd5fe 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -54619,7 +54619,7 @@ const home = external_os_default().homedir(); const paths = { index: external_path_default().join(home, ".cargo/registry/index"), cache: external_path_default().join(home, ".cargo/registry/cache"), - git: external_path_default().join(home, ".cargo/git/db"), + // git: path.join(home, ".cargo/git/db"), target: "target", }; const RefKey = "GITHUB_REF"; @@ -54637,6 +54637,10 @@ async function getCaches() { if (targetKey) { targetKey = `${targetKey}-`; } + const job = process.env.GITHUB_JOB; + if (job) { + targetKey = `${job}-${targetKey}`; + } const registryIndex = `v0-registry-index`; const registryCache = `v0-registry-cache`; const target = `v0-target-${targetKey}${rustKey}`; diff --git a/src/common.ts b/src/common.ts index 45d90f5..9b31c08 100644 --- a/src/common.ts +++ b/src/common.ts @@ -10,7 +10,7 @@ const home = os.homedir(); export const paths = { index: path.join(home, ".cargo/registry/index"), cache: path.join(home, ".cargo/registry/cache"), - git: path.join(home, ".cargo/git/db"), + // git: path.join(home, ".cargo/git/db"), target: "target", }; @@ -45,6 +45,10 @@ export async function getCaches(): Promise { if (targetKey) { targetKey = `${targetKey}-`; } + const job = process.env.GITHUB_JOB; + if (job) { + targetKey = `${job}-${targetKey}`; + } const registryIndex = `v0-registry-index`; const registryCache = `v0-registry-cache`;