Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03eb867

Browse filesBrowse files
Add error handling for saving and restoring cache (actions#618)
1 parent b41aaf9 commit 03eb867
Copy full SHA for 03eb867

File tree

Expand file treeCollapse file tree

8 files changed

+695
-1057
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+695
-1057
lines changed

‎.licenses/npm/@actions/cache.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@actions/cache.dep.yml
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.licenses/npm/@azure/abort-controller.dep.yml

Copy file name to clipboardExpand all lines: .licenses/npm/@azure/abort-controller.dep.yml
+2-2Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎__tests__/cache-save.test.ts

Copy file name to clipboardExpand all lines: __tests__/cache-save.test.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ describe('run', () => {
225225
expect(setFailedSpy).not.toHaveBeenCalled();
226226
});
227227

228-
it('saves with error from toolkit, should fail workflow', async () => {
228+
it('saves with error from toolkit, should not fail the workflow', async () => {
229229
inputs['cache'] = 'npm';
230230
getStateSpy.mockImplementation((name: string) => {
231231
if (name === State.STATE_CACHE_PRIMARY_KEY) {
@@ -247,7 +247,7 @@ describe('run', () => {
247247
expect(getStateSpy).toHaveBeenCalledTimes(3);
248248
expect(infoSpy).not.toHaveBeenCalledWith();
249249
expect(saveCacheSpy).toHaveBeenCalled();
250-
expect(setFailedSpy).toHaveBeenCalled();
250+
expect(setFailedSpy).not.toHaveBeenCalled();
251251
});
252252
});
253253

‎dist/cache-save/index.js

Copy file name to clipboardExpand all lines: dist/cache-save/index.js
+329-514Lines changed: 329 additions & 514 deletions
Large diffs are not rendered by default.

‎dist/setup/index.js

Copy file name to clipboardExpand all lines: dist/setup/index.js
+321-514Lines changed: 321 additions & 514 deletions
Large diffs are not rendered by default.

‎package-lock.json

Copy file name to clipboardExpand all lines: package-lock.json
+19-17Lines changed: 19 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/cache-distributions/cache-distributor.ts

Copy file name to clipboardExpand all lines: src/cache-distributions/cache-distributor.ts
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ abstract class CacheDistributor {
3939
const cachePath = await this.getCacheGlobalDirectories();
4040

4141
core.saveState(State.CACHE_PATHS, cachePath);
42-
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
4342

44-
const matchedKey = await cache.restoreCache(
45-
cachePath,
46-
primaryKey,
47-
restoreKey
48-
);
43+
let matchedKey: string | undefined;
44+
try {
45+
matchedKey = await cache.restoreCache(cachePath, primaryKey, restoreKey);
46+
} catch (err) {
47+
const message = (err as Error).message;
48+
core.info(`[warning]${message}`);
49+
core.setOutput('cache-hit', false);
50+
return;
51+
}
52+
53+
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
4954

5055
await this.handleLoadedCache();
5156

‎src/cache-save.ts

Copy file name to clipboardExpand all lines: src/cache-save.ts
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ async function saveCache(packageManager: string) {
4343
return;
4444
}
4545

46-
const cacheId = await cache.saveCache(cachePaths, primaryKey);
46+
let cacheId = 0;
47+
48+
try {
49+
cacheId = await cache.saveCache(cachePaths, primaryKey);
50+
} catch (err) {
51+
const message = (err as Error).message;
52+
core.info(`[warning]${message}`);
53+
return;
54+
}
55+
4756
if (cacheId == -1) {
4857
return;
4958
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.