mirror of
https://github.com/Swatinem/rust-cache
synced 2025-07-31 18:33:20 +00:00
cause save state if no incrementa.json
This commit is contained in:
parent
0381560ff9
commit
36c8b73442
5 changed files with 229 additions and 119 deletions
|
@ -10,6 +10,7 @@ import * as toml from "smol-toml";
|
|||
import { getCargoBins } from "./cleanup";
|
||||
import { CacheProvider, exists, getCmdOutput } from "./utils";
|
||||
import { Workspace } from "./workspace";
|
||||
import { isIncrementalMissing } from "./incremental";
|
||||
|
||||
const HOME = os.homedir();
|
||||
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
|
||||
|
@ -62,8 +63,6 @@ export class CacheConfig {
|
|||
|
||||
let key = core.getInput("prefix-key") || "v0-rust";
|
||||
|
||||
|
||||
|
||||
const sharedKey = core.getInput("shared-key");
|
||||
if (sharedKey) {
|
||||
key += `-${sharedKey}`;
|
||||
|
@ -120,7 +119,6 @@ export class CacheConfig {
|
|||
|
||||
self.keyEnvs = keyEnvs;
|
||||
|
||||
|
||||
// Make sure we consider incremental builds
|
||||
self.incremental = core.getInput("incremental").toLowerCase() == "true";
|
||||
hasher.update(`incremental=${self.incremental}`);
|
||||
|
@ -275,6 +273,14 @@ export class CacheConfig {
|
|||
self.cachePaths.push(dir);
|
||||
}
|
||||
|
||||
if (self.incremental) {
|
||||
if (cacheTargets === "true") {
|
||||
for (const target of self.workspaces.map((ws) => ws.target)) {
|
||||
self.cachePaths.push(path.join(target, "incremental"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bins = await getCargoBins();
|
||||
self.cargoBins = Array.from(bins.values());
|
||||
|
||||
|
@ -343,6 +349,14 @@ export class CacheConfig {
|
|||
saveState() {
|
||||
core.saveState(STATE_CONFIG, this);
|
||||
}
|
||||
|
||||
isIncrementalMissing(): boolean {
|
||||
if (this.incremental) {
|
||||
return isIncrementalMissing();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,11 +7,15 @@ import path from "path";
|
|||
import { exists } from "./utils";
|
||||
// import { Packages } from "./workspace";
|
||||
|
||||
let incremental_missing = false;
|
||||
|
||||
export function isIncrementalMissing(): boolean {
|
||||
return incremental_missing;
|
||||
}
|
||||
|
||||
export async function restoreIncremental(targetDir: string) {
|
||||
core.debug(`restoring incremental directory "${targetDir}"`);
|
||||
|
||||
|
||||
let dir = await fs.promises.opendir(targetDir);
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isDirectory()) {
|
||||
|
@ -46,5 +50,8 @@ async function restoreIncrementalProfile(dirName: string) {
|
|||
const filePath = path.join(dirName, fileName);
|
||||
await fs.promises.utimes(filePath, new Date(mtime), new Date(mtime));
|
||||
}
|
||||
} else {
|
||||
core.debug(`incremental-restore.json not found for ${dirName}`);
|
||||
incremental_missing = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ async function run() {
|
|||
}
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
if (!match || config.isIncrementalMissing()) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
for (const workspace of config.workspaces) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue