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 restore cache error handling #434

Closed
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/e2e-cache.yml
Expand Up @@ -43,12 +43,13 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup Python
id: setup-python
uses: ./
with:
python-version: ${{ matrix.python-version }}
cache: 'pipenv'
- name: Install pipenv
run: pipx install pipenv
run: pipx install pipenv --python ${{ steps.setup-python.outputs.python-path }}
- name: Install dependencies
run: |
cd __tests__/data
Expand Down
16 changes: 14 additions & 2 deletions dist/cache-save/index.js
Expand Up @@ -57529,8 +57529,20 @@ class CacheDistributor {
const cachePath = yield this.getCacheGlobalDirectories();
core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
this.handleMatchResult(matchedKey, primaryKey);
try {
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
this.handleMatchResult(matchedKey, primaryKey);
}
catch (error) {
const typedError = error;
if (typedError.name === cache.ValidationError.name) {
throw error;
}
else {
core.warning(typedError.message);
core.setOutput('cache-hit', false);
}
}
});
}
handleMatchResult(matchedKey, primaryKey) {
Expand Down
16 changes: 14 additions & 2 deletions dist/setup/index.js
Expand Up @@ -63600,8 +63600,20 @@ class CacheDistributor {
const cachePath = yield this.getCacheGlobalDirectories();
core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
this.handleMatchResult(matchedKey, primaryKey);
try {
const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey);
this.handleMatchResult(matchedKey, primaryKey);
}
catch (error) {
const typedError = error;
if (typedError.name === cache.ValidationError.name) {
throw error;
}
else {
core.warning(typedError.message);
core.setOutput('cache-hit', false);
}
}
});
}
handleMatchResult(matchedKey, primaryKey) {
Expand Down
22 changes: 16 additions & 6 deletions src/cache-distributions/cache-distributor.ts
Expand Up @@ -35,13 +35,23 @@ abstract class CacheDistributor {
core.saveState(State.CACHE_PATHS, cachePath);
core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey);

const matchedKey = await cache.restoreCache(
cachePath,
primaryKey,
restoreKey
);
try {
const matchedKey = await cache.restoreCache(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we push this fix into restoreCache from actions/cache? That way everything that uses caching will handle 503s correctly.

cachePath,
primaryKey,
restoreKey
);

this.handleMatchResult(matchedKey, primaryKey);
this.handleMatchResult(matchedKey, primaryKey);
} catch (error) {
const typedError = error as Error;
if (typedError.name === cache.ValidationError.name) {
throw error;
} else {
core.warning(typedError.message);
core.setOutput('cache-hit', false);
}
}
}

public handleMatchResult(matchedKey: string | undefined, primaryKey: string) {
Expand Down