From 36d77bfde22a12f86abaddd78374df187b8f3c70 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 10 Jul 2023 12:00:57 +0200 Subject: [PATCH 1/3] add check for existing paths to cache --- dist/cache-save/index.js | 9 +++++++-- src/cache-save.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index a32351953..a247f1907 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60342,10 +60342,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.run = void 0; const core = __importStar(__nccwpck_require__(2186)); const cache = __importStar(__nccwpck_require__(7799)); +const fs_1 = __importDefault(__nccwpck_require__(7147)); const constants_1 = __nccwpck_require__(9042); const cache_utils_1 = __nccwpck_require__(1678); // Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in @@ -60370,13 +60374,14 @@ exports.run = run; const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () { const state = core.getState(constants_1.State.CacheMatchedKey); const primaryKey = core.getState(constants_1.State.CachePrimaryKey); - const cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]'); + let cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]'); + cachePaths = cachePaths.filter(fs_1.default.existsSync); const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager); if (!packageManagerInfo) { core.debug(`Caching for '${packageManager}' is not supported`); return; } - if (cachePaths.length === 0) { + if (!cachePaths.length) { // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) // export declare function getInput(name: string, options?: InputOptions): string; const cacheDependencyPath = core.getInput('cache-dependency-path') || ''; diff --git a/src/cache-save.ts b/src/cache-save.ts index 96f6a7d47..3d9d62aac 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -1,5 +1,8 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; + +import fs from 'fs'; + import {State} from './constants'; import {getPackageManagerInfo} from './cache-utils'; @@ -23,7 +26,8 @@ export async function run() { const cachePackages = async (packageManager: string) => { const state = core.getState(State.CacheMatchedKey); const primaryKey = core.getState(State.CachePrimaryKey); - const cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]'); + let cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]') as string[]; + cachePaths = cachePaths.filter(fs.existsSync) const packageManagerInfo = await getPackageManagerInfo(packageManager); if (!packageManagerInfo) { @@ -31,7 +35,7 @@ const cachePackages = async (packageManager: string) => { return; } - if (cachePaths.length === 0) { + if (!cachePaths.length) { // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) // export declare function getInput(name: string, options?: InputOptions): string; const cacheDependencyPath = core.getInput('cache-dependency-path') || ''; From 11883e881fbceb643f872fe3a0324a99a3532fc7 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 10 Jul 2023 13:05:16 +0200 Subject: [PATCH 2/3] run format --- src/cache-save.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cache-save.ts b/src/cache-save.ts index 3d9d62aac..9449fb85c 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -26,8 +26,10 @@ export async function run() { const cachePackages = async (packageManager: string) => { const state = core.getState(State.CacheMatchedKey); const primaryKey = core.getState(State.CachePrimaryKey); - let cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]') as string[]; - cachePaths = cachePaths.filter(fs.existsSync) + let cachePaths = JSON.parse( + core.getState(State.CachePaths) || '[]' + ) as string[]; + cachePaths = cachePaths.filter(fs.existsSync); const packageManagerInfo = await getPackageManagerInfo(packageManager); if (!packageManagerInfo) { From 1d6f7c8dd0f684e32d789cb3df9bb89b04c96102 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 10 Jul 2023 14:46:25 +0200 Subject: [PATCH 3/3] fix e2e tests --- .github/workflows/e2e-cache.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-cache.yml b/.github/workflows/e2e-cache.yml index c8324ee1e..ba3af16b7 100644 --- a/.github/workflows/e2e-cache.yml +++ b/.github/workflows/e2e-cache.yml @@ -173,7 +173,7 @@ jobs: - uses: actions/checkout@v3 - name: prepare sub-projects - run: __tests__/prepare-yarn-subprojects.sh + run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache # expect # - no errors