Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling for saving and restoring cache #618

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -241,7 +241,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 @@ -263,7 +263,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