Skip to content

Commit

Permalink
Add error handling for saving and restoring cache (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-shibanov committed Mar 10, 2023
1 parent b41aaf9 commit 03eb867
Show file tree
Hide file tree
Showing 8 changed files with 695 additions and 1,057 deletions.
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/cache.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .licenses/npm/@azure/abort-controller.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions __tests__/cache-save.test.ts
Expand Up @@ -225,7 +225,7 @@ describe('run', () => {
expect(setFailedSpy).not.toHaveBeenCalled();
});

it('saves with error from toolkit, should fail workflow', async () => {
it('saves with error from toolkit, should not fail the workflow', async () => {
inputs['cache'] = 'npm';
getStateSpy.mockImplementation((name: string) => {
if (name === State.STATE_CACHE_PRIMARY_KEY) {
Expand All @@ -247,7 +247,7 @@ describe('run', () => {
expect(getStateSpy).toHaveBeenCalledTimes(3);
expect(infoSpy).not.toHaveBeenCalledWith();
expect(saveCacheSpy).toHaveBeenCalled();
expect(setFailedSpy).toHaveBeenCalled();
expect(setFailedSpy).not.toHaveBeenCalled();
});
});

Expand Down
843 changes: 329 additions & 514 deletions dist/cache-save/index.js

Large diffs are not rendered by default.

835 changes: 321 additions & 514 deletions dist/setup/index.js

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions src/cache-distributions/cache-distributor.ts
Expand Up @@ -39,13 +39,18 @@ abstract class CacheDistributor {
const cachePath = await this.getCacheGlobalDirectories();

core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);

const matchedKey = await cache.restoreCache(
cachePath,
primaryKey,
restoreKey
);
let matchedKey: string | undefined;
try {
matchedKey = await cache.restoreCache(cachePath, primaryKey, restoreKey);
} catch (err) {
const message = (err as Error).message;
core.info(`[warning]${message}`);
core.setOutput('cache-hit', false);
return;
}

core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);

await this.handleLoadedCache();

Expand Down
11 changes: 10 additions & 1 deletion src/cache-save.ts
Expand Up @@ -43,7 +43,16 @@ async function saveCache(packageManager: string) {
return;
}

const cacheId = await cache.saveCache(cachePaths, primaryKey);
let cacheId = 0;

try {
cacheId = await cache.saveCache(cachePaths, primaryKey);
} catch (err) {
const message = (err as Error).message;
core.info(`[warning]${message}`);
return;
}

if (cacheId == -1) {
return;
}
Expand Down

0 comments on commit 03eb867

Please sign in to comment.