From 5d7223261bcae31f3583659e3637ca9a54b909d0 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Tue, 14 Jun 2022 12:05:49 +0200 Subject: [PATCH 1/3] add restore cache error handling --- dist/cache-save/index.js | 16 +++++++++++-- dist/setup/index.js | 16 +++++++++++-- src/cache-distributions/cache-distributor.ts | 24 +++++++++++++++----- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 35cedd908..3689f58f4 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -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) { diff --git a/dist/setup/index.js b/dist/setup/index.js index 2b2504b07..2a64dcb11 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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) { diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index f24c78dab..c1f5b769a 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/src/cache-distributions/cache-distributor.ts @@ -35,13 +35,25 @@ 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( + cachePath, + primaryKey, + restoreKey + ); + + 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); + } + } + - this.handleMatchResult(matchedKey, primaryKey); } public handleMatchResult(matchedKey: string | undefined, primaryKey: string) { From d91db0f679c2a22f3ba59dc946acd1495ba3c1c8 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Tue, 14 Jun 2022 12:23:38 +0200 Subject: [PATCH 2/3] apply linter --- src/cache-distributions/cache-distributor.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index c1f5b769a..548bc9055 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/src/cache-distributions/cache-distributor.ts @@ -43,7 +43,7 @@ abstract class CacheDistributor { ); this.handleMatchResult(matchedKey, primaryKey); - } catch(error) { + } catch (error) { const typedError = error as Error; if (typedError.name === cache.ValidationError.name) { throw error; @@ -52,8 +52,6 @@ abstract class CacheDistributor { core.setOutput('cache-hit', false); } } - - } public handleMatchResult(matchedKey: string | undefined, primaryKey: string) { From eb962b992545472a3850c451d849a4e35b0c8c20 Mon Sep 17 00:00:00 2001 From: panticmilos Date: Wed, 15 Jun 2022 09:34:58 +0200 Subject: [PATCH 3/3] update e2e --- .github/workflows/e2e-cache.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index ce3366a1f..b67494048 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -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