Cache multiple target directories from 'target-dir'
This commit is contained in:
committed by
Arpad Borsos
parent
fa61956921
commit
260a713186
@@ -1,5 +1,6 @@
|
||||
import * as cache from "@actions/cache";
|
||||
import * as core from "@actions/core";
|
||||
import path from "path";
|
||||
import { cleanTarget, getCacheConfig, getCargoBins, getPackages, stateBins, stateKey } from "./common";
|
||||
|
||||
async function run() {
|
||||
@@ -16,24 +17,29 @@ async function run() {
|
||||
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
||||
core.exportVariable("CARGO_INCREMENTAL", 0);
|
||||
|
||||
const { paths, key, restoreKeys } = await getCacheConfig();
|
||||
const { paths, key, restoreKeys, workspaces } = await getCacheConfig();
|
||||
const restorePaths = paths.concat(workspaces);
|
||||
|
||||
const bins = await getCargoBins();
|
||||
core.saveState(stateBins, JSON.stringify([...bins]));
|
||||
|
||||
core.info(`Restoring paths:\n ${paths.join("\n ")}`);
|
||||
core.info(`Restoring paths:\n ${restorePaths.join("\n ")}`);
|
||||
core.info(`In directory:\n ${process.cwd()}`);
|
||||
core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`);
|
||||
const restoreKey = await cache.restoreCache(paths, key, restoreKeys);
|
||||
const restoreKey = await cache.restoreCache(restorePaths, key, restoreKeys);
|
||||
if (restoreKey) {
|
||||
core.info(`Restored from cache key "${restoreKey}".`);
|
||||
core.saveState(stateKey, restoreKey);
|
||||
|
||||
if (restoreKey !== key) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
const packages = await getPackages();
|
||||
const packages = await getPackages(workspaces);
|
||||
core.info("Restoring the following repository packages: " + JSON.stringify(packages));
|
||||
|
||||
await cleanTarget(packages);
|
||||
for (const workspace of workspaces) {
|
||||
const target = path.join(workspace, "target");
|
||||
await cleanTarget(target, packages);
|
||||
}
|
||||
}
|
||||
|
||||
setCacheHitOutput(restoreKey === key);
|
||||
|
||||
Reference in New Issue
Block a user