mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-05-17 05:30:01 +00:00
new: Support custom target dirs. (#19)
This commit is contained in:
parent
c91b4202a2
commit
dcab3dcf9f
7 changed files with 183 additions and 124 deletions
12
src/cache.ts
12
src/cache.ts
|
@ -18,12 +18,22 @@ export function getCacheTarget(): string {
|
|||
return core.getInput('cache-target') || 'debug';
|
||||
}
|
||||
|
||||
export function getTargetPaths(): string[] {
|
||||
const profile = getCacheTarget();
|
||||
const dirs = core.getInput('target-dirs', { required: true }).split(',');
|
||||
|
||||
return dirs
|
||||
.map((dir) => dir.trim())
|
||||
.filter(Boolean)
|
||||
.map((dir) => path.join(WORKSPACE_ROOT, dir, profile));
|
||||
}
|
||||
|
||||
export function getCachePaths(): string[] {
|
||||
return [
|
||||
// ~/.cargo/registry
|
||||
path.join(CARGO_HOME, 'registry'),
|
||||
// /workspace/target/debug
|
||||
path.join(WORKSPACE_ROOT, 'target', getCacheTarget()),
|
||||
...getTargetPaths(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
32
src/cargo.ts
32
src/cargo.ts
|
@ -165,12 +165,33 @@ export async function saveCache() {
|
|||
return;
|
||||
}
|
||||
|
||||
const cachePaths = getCachePaths().filter((cachePath) => {
|
||||
if (!fs.existsSync(cachePath)) {
|
||||
core.info(`Cache path ${cachePath} does not exist, skipping`);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (cachePaths.length === 0) {
|
||||
core.info('No paths to cache, skipping save entirely');
|
||||
return;
|
||||
}
|
||||
|
||||
await cleanCargoRegistry();
|
||||
await cleanTargetProfile();
|
||||
|
||||
core.info(`Saving cache with key ${primaryKey}`);
|
||||
|
||||
await cache.saveCache(getCachePaths(), primaryKey);
|
||||
core.debug(`Cache key: ${primaryKey}`);
|
||||
core.debug('Cache paths:');
|
||||
|
||||
for (const cachePath of cachePaths) {
|
||||
core.debug(`- ${cachePath}`);
|
||||
}
|
||||
|
||||
await cache.saveCache(cachePaths, primaryKey);
|
||||
}
|
||||
|
||||
export async function restoreCache() {
|
||||
|
@ -181,6 +202,15 @@ export async function restoreCache() {
|
|||
core.info('Attempting to restore cache');
|
||||
|
||||
const primaryKey = await getPrimaryCacheKey();
|
||||
const cachePaths = getCachePaths();
|
||||
|
||||
core.debug(`Cache key: ${primaryKey}`);
|
||||
core.debug('Cache paths:');
|
||||
|
||||
for (const cachePath of cachePaths) {
|
||||
core.debug(`- ${cachePath}`);
|
||||
}
|
||||
|
||||
const cacheKey = await cache.restoreCache(getCachePaths(), primaryKey, getCachePrefixes());
|
||||
|
||||
if (cacheKey) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue