Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 827c240

Browse files
authored
fix: cache key dependency on installed packages (#138)
Add the installed packages to the environment element of the cache key so that CI tooling is considered. This ensures that rust CI tooling is cached correctly when changes occur. Prior to this a manual key change or cache expiry would need to occur before CI tools were correctly cached.
1 parent 5e9fae9 commit 827c240

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ This cache is automatically keyed by:
9595
- the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and
9696
- a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).
9797
- a hash of all `rust-toolchain` / `rust-toolchain.toml` files in the root of the repository (if present).
98+
- a hash of installed packages as generated by `cargo install --list`.
9899

99100
An additional input `key` can be provided if the builtin keys are not sufficient.
100101

dist/restore/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60055,6 +60055,9 @@ class CacheConfig {
6005560055
}
6005660056
}
6005760057
self.keyEnvs = keyEnvs;
60058+
// Installed packages and their versions are also considered for the key.
60059+
const packages = await getPackages();
60060+
hasher.update(packages);
6005860061
key += `-${hasher.digest("hex")}`;
6005960062
self.restoreKey = key;
6006060063
// Construct the lockfiles portion of the key:
@@ -60146,6 +60149,11 @@ async function getRustVersion() {
6014660149
.filter((s) => s.length === 2);
6014760150
return Object.fromEntries(splits);
6014860151
}
60152+
async function getPackages() {
60153+
let stdout = await getCmdOutput("cargo", ["install", "--list"]);
60154+
// Make OS independent.
60155+
return stdout.split(/[\n\r]+/).join("\n");
60156+
}
6014960157
async function globFiles(pattern) {
6015060158
const globber = await glob.create(pattern, {
6015160159
followSymbolicLinks: false,

dist/save/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60055,6 +60055,9 @@ class CacheConfig {
6005560055
}
6005660056
}
6005760057
self.keyEnvs = keyEnvs;
60058+
// Installed packages and their versions are also considered for the key.
60059+
const packages = await getPackages();
60060+
hasher.update(packages);
6005860061
key += `-${hasher.digest("hex")}`;
6005960062
self.restoreKey = key;
6006060063
// Construct the lockfiles portion of the key:
@@ -60146,6 +60149,11 @@ async function getRustVersion() {
6014660149
.filter((s) => s.length === 2);
6014760150
return Object.fromEntries(splits);
6014860151
}
60152+
async function getPackages() {
60153+
let stdout = await getCmdOutput("cargo", ["install", "--list"]);
60154+
// Make OS independent.
60155+
return stdout.split(/[\n\r]+/).join("\n");
60156+
}
6014960157
async function globFiles(pattern) {
6015060158
const globber = await glob.create(pattern, {
6015160159
followSymbolicLinks: false,

src/config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ export class CacheConfig {
103103
}
104104

105105
self.keyEnvs = keyEnvs;
106+
107+
// Installed packages and their versions are also considered for the key.
108+
const packages = await getPackages();
109+
hasher.update(packages);
110+
106111
key += `-${hasher.digest("hex")}`;
107112

108113
self.restoreKey = key;
@@ -220,6 +225,12 @@ async function getRustVersion(): Promise<RustVersion> {
220225
return Object.fromEntries(splits);
221226
}
222227

228+
async function getPackages(): Promise<string> {
229+
let stdout = await getCmdOutput("cargo", ["install", "--list"]);
230+
// Make OS independent.
231+
return stdout.split(/[\n\r]+/).join("\n");
232+
}
233+
223234
async function globFiles(pattern: string): Promise<string[]> {
224235
const globber = await glob.create(pattern, {
225236
followSymbolicLinks: false,

0 commit comments

Comments
 (0)