mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 21:40:01 +00:00
Add restore cache.
This commit is contained in:
parent
7b19c2c567
commit
8cbd5dda6b
3 changed files with 54 additions and 18 deletions
31
post.ts
31
post.ts
|
@ -1,33 +1,30 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import { CARGO_HOME } from './helpers';
|
||||
import { getPathsToCache, getPrimaryCacheKey } from './helpers';
|
||||
|
||||
async function run() {
|
||||
async function saveCache() {
|
||||
const enabled = core.getBooleanInput('cache');
|
||||
|
||||
if (!cache.isFeatureAvailable() || !enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(CARGO_HOME)) {
|
||||
core.warning(`~/.cargo does not exist, not saving cache`);
|
||||
const primaryKey = getPrimaryCacheKey();
|
||||
const cacheHitKey = core.getState('cacheHitKey');
|
||||
|
||||
if (cacheHitKey === primaryKey) {
|
||||
core.info(`Cache hit occured on the key ${cacheHitKey}, not saving cache`);
|
||||
return;
|
||||
}
|
||||
|
||||
core.info(`Saving cache with key ${primaryKey}`);
|
||||
|
||||
await cache.saveCache(getPathsToCache(), primaryKey, {}, false);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const primaryKey = 'v0-test';
|
||||
const cacheHitKey = core.getState('cacheHitKey');
|
||||
|
||||
if (cacheHitKey === primaryKey) {
|
||||
core.info(`Cache hit occured on the key ${cacheHitKey}, not saving cache`);
|
||||
return;
|
||||
}
|
||||
|
||||
core.info(`Saving cache with key ${primaryKey}`);
|
||||
|
||||
await cache.saveCache([path.join(CARGO_HOME, 'registry')], primaryKey, {}, false);
|
||||
await saveCache();
|
||||
} catch (error: unknown) {
|
||||
core.setFailed((error as Error).message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue