Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use 8 character hash components #143

Merged
merged 1 commit into from May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## 2.3.1

- Fix cache key stability.
- Use 8 character hash components to reduce the key length, making it more readable.

## 2.3.0

Expand Down
14 changes: 12 additions & 2 deletions dist/restore/index.js
Expand Up @@ -60028,6 +60028,7 @@ class Workspace {
const HOME = external_os_default().homedir();
const config_CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
const STATE_CONFIG = "RUST_CACHE_CONFIG";
const HASH_LENGTH = 8;
class CacheConfig {
constructor() {
/** All the paths we want to cache */
Expand Down Expand Up @@ -60103,7 +60104,7 @@ class CacheConfig {
}
}
self.keyEnvs = keyEnvs;
key += `-${hasher.digest("hex")}`;
key += `-${digest(hasher)}`;
self.restoreKey = key;
// Construct the lockfiles portion of the key:
// This considers all the files found via globbing for various manifests
Expand Down Expand Up @@ -60132,7 +60133,7 @@ class CacheConfig {
hasher.update(chunk);
}
}
let lockHash = hasher.digest("hex");
let lockHash = digest(hasher);
self.keyFiles = keyFiles;
key += `-${lockHash}`;
self.cacheKey = key;
Expand Down Expand Up @@ -60214,6 +60215,15 @@ class CacheConfig {
function isCacheUpToDate() {
return core.getState(STATE_CONFIG) === "";
}
/**
* Returns a hex digest of the given hasher truncated to `HASH_LENGTH`.
*
* @param hasher The hasher to digest.
* @returns The hex digest.
*/
function digest(hasher) {
return hasher.digest("hex").substring(0, HASH_LENGTH);
}
async function getRustVersion() {
const stdout = await getCmdOutput("rustc", ["-vV"]);
let splits = stdout
Expand Down
14 changes: 12 additions & 2 deletions dist/save/index.js
Expand Up @@ -60028,6 +60028,7 @@ class Workspace {
const HOME = external_os_default().homedir();
const CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
const STATE_CONFIG = "RUST_CACHE_CONFIG";
const HASH_LENGTH = 8;
class CacheConfig {
constructor() {
/** All the paths we want to cache */
Expand Down Expand Up @@ -60103,7 +60104,7 @@ class CacheConfig {
}
}
self.keyEnvs = keyEnvs;
key += `-${hasher.digest("hex")}`;
key += `-${digest(hasher)}`;
self.restoreKey = key;
// Construct the lockfiles portion of the key:
// This considers all the files found via globbing for various manifests
Expand Down Expand Up @@ -60132,7 +60133,7 @@ class CacheConfig {
hasher.update(chunk);
}
}
let lockHash = hasher.digest("hex");
let lockHash = digest(hasher);
self.keyFiles = keyFiles;
key += `-${lockHash}`;
self.cacheKey = key;
Expand Down Expand Up @@ -60214,6 +60215,15 @@ class CacheConfig {
function isCacheUpToDate() {
return core.getState(STATE_CONFIG) === "";
}
/**
* Returns a hex digest of the given hasher truncated to `HASH_LENGTH`.
*
* @param hasher The hasher to digest.
* @returns The hex digest.
*/
function digest(hasher) {
return hasher.digest("hex").substring(0, HASH_LENGTH);
}
async function getRustVersion() {
const stdout = await getCmdOutput("rustc", ["-vV"]);
let splits = stdout
Expand Down
15 changes: 13 additions & 2 deletions src/config.ts
Expand Up @@ -13,6 +13,7 @@ const HOME = os.homedir();
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");

const STATE_CONFIG = "RUST_CACHE_CONFIG";
const HASH_LENGTH = 8;

export class CacheConfig {
/** All the paths we want to cache */
Expand Down Expand Up @@ -105,7 +106,7 @@ export class CacheConfig {

self.keyEnvs = keyEnvs;

key += `-${hasher.digest("hex")}`;
key += `-${digest(hasher)}`;

self.restoreKey = key;

Expand Down Expand Up @@ -144,7 +145,7 @@ export class CacheConfig {
hasher.update(chunk);
}
}
let lockHash = hasher.digest("hex");
let lockHash = digest(hasher);

self.keyFiles = keyFiles;

Expand Down Expand Up @@ -239,6 +240,16 @@ export function isCacheUpToDate(): boolean {
return core.getState(STATE_CONFIG) === "";
}

/**
* Returns a hex digest of the given hasher truncated to `HASH_LENGTH`.
*
* @param hasher The hasher to digest.
* @returns The hex digest.
*/
function digest(hasher: crypto.Hash): string {
return hasher.digest("hex").substring(0, HASH_LENGTH);
}

interface RustVersion {
host: string;
release: string;
Expand Down