cache: gracefully handle cache restore failures with warning
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
54
src/cache.ts
54
src/cache.ts
@@ -64,8 +64,12 @@ export class Cache {
|
|||||||
|
|
||||||
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
|
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
|
||||||
if (skipState) {
|
if (skipState) {
|
||||||
core.debug(`Cache.save caching ${this.ghaCacheKey} to GitHub Actions cache`);
|
try {
|
||||||
await cache.saveCache([this.cacheDir], this.ghaCacheKey);
|
core.debug(`Cache.save caching ${this.ghaCacheKey} to GitHub Actions cache`);
|
||||||
|
await cache.saveCache([this.cacheDir], this.ghaCacheKey);
|
||||||
|
} catch (e) {
|
||||||
|
core.warning(`Failed to save cache: ${e}`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
core.debug(`Cache.save sending ${this.ghaCacheKey} to post state`);
|
core.debug(`Cache.save sending ${this.ghaCacheKey} to post state`);
|
||||||
core.saveState(
|
core.saveState(
|
||||||
@@ -82,26 +86,28 @@ export class Cache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async find(): Promise<string> {
|
public async find(): Promise<string> {
|
||||||
let htcPath = tc.find(this.opts.htcName, this.opts.htcVersion, this.platform());
|
try {
|
||||||
if (htcPath) {
|
let htcPath = tc.find(this.opts.htcName, this.opts.htcVersion, this.platform());
|
||||||
core.info(`Restored from hosted tool cache ${htcPath}`);
|
if (htcPath) {
|
||||||
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
core.info(`Restored from hosted tool cache ${htcPath}`);
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
|
|
||||||
core.debug(`GitHub Actions cache feature available`);
|
|
||||||
if (await cache.restoreCache([this.cacheDir], this.ghaCacheKey)) {
|
|
||||||
core.info(`Restored ${this.ghaCacheKey} from GitHub Actions cache`);
|
|
||||||
htcPath = await tc.cacheDir(this.cacheDir, this.opts.htcName, this.opts.htcVersion, this.platform());
|
|
||||||
core.info(`Cached to hosted tool cache ${htcPath}`);
|
|
||||||
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
||||||
}
|
}
|
||||||
} else if (this.ghaNoCache) {
|
if (!this.ghaNoCache && cache.isFeatureAvailable()) {
|
||||||
core.info(`GitHub Actions cache disabled`);
|
core.debug(`GitHub Actions cache feature available`);
|
||||||
} else {
|
if (await cache.restoreCache([this.cacheDir], this.ghaCacheKey)) {
|
||||||
core.info(`GitHub Actions cache feature not available`);
|
core.info(`Restored ${this.ghaCacheKey} from GitHub Actions cache`);
|
||||||
|
htcPath = await tc.cacheDir(this.cacheDir, this.opts.htcName, this.opts.htcVersion, this.platform());
|
||||||
|
core.info(`Cached to hosted tool cache ${htcPath}`);
|
||||||
|
return this.copyToCache(`${htcPath}/${this.opts.cacheFile}`);
|
||||||
|
}
|
||||||
|
} else if (this.ghaNoCache) {
|
||||||
|
core.info(`GitHub Actions cache disabled`);
|
||||||
|
} else {
|
||||||
|
core.info(`GitHub Actions cache feature not available`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
core.warning(`Failed to restore cache: ${e}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,13 +126,17 @@ export class Cache {
|
|||||||
if (!cacheState.dir || !cacheState.key) {
|
if (!cacheState.dir || !cacheState.key) {
|
||||||
throw new Error(`Invalid cache post state: ${state}`);
|
throw new Error(`Invalid cache post state: ${state}`);
|
||||||
}
|
}
|
||||||
core.info(`Caching ${cacheState.key} to GitHub Actions cache`);
|
try {
|
||||||
await cache.saveCache([cacheState.dir], cacheState.key);
|
core.info(`Caching ${cacheState.key} to GitHub Actions cache`);
|
||||||
|
await cache.saveCache([cacheState.dir], cacheState.key);
|
||||||
|
} catch (e) {
|
||||||
|
core.warning(`Failed to save cache: ${e}`);
|
||||||
|
}
|
||||||
return cacheState;
|
return cacheState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private copyToCache(file: string): string {
|
private copyToCache(file: string): string {
|
||||||
core.debug(`Copying ${file} to ${this.cachePath}`);
|
core.info(`Copying ${file} to ${this.cachePath}`);
|
||||||
fs.copyFileSync(file, this.cachePath);
|
fs.copyFileSync(file, this.cachePath);
|
||||||
return this.cachePath;
|
return this.cachePath;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user