Skip to content

Commit 3405007

Browse files
Add check for existing paths (#803)
1 parent f8aa08e commit 3405007

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

.github/workflows/e2e-cache.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jobs:
173173
- uses: actions/checkout@v3
174174

175175
- name: prepare sub-projects
176-
run: __tests__/prepare-yarn-subprojects.sh
176+
run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache
177177

178178
# expect
179179
# - no errors

dist/cache-save/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -60361,10 +60361,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6036160361
step((generator = generator.apply(thisArg, _arguments || [])).next());
6036260362
});
6036360363
};
60364+
var __importDefault = (this && this.__importDefault) || function (mod) {
60365+
return (mod && mod.__esModule) ? mod : { "default": mod };
60366+
};
6036460367
Object.defineProperty(exports, "__esModule", ({ value: true }));
6036560368
exports.run = void 0;
6036660369
const core = __importStar(__nccwpck_require__(2186));
6036760370
const cache = __importStar(__nccwpck_require__(7799));
60371+
const fs_1 = __importDefault(__nccwpck_require__(7147));
6036860372
const constants_1 = __nccwpck_require__(9042);
6036960373
const cache_utils_1 = __nccwpck_require__(1678);
6037060374
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
@@ -60389,13 +60393,14 @@ exports.run = run;
6038960393
const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
6039060394
const state = core.getState(constants_1.State.CacheMatchedKey);
6039160395
const primaryKey = core.getState(constants_1.State.CachePrimaryKey);
60392-
const cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]');
60396+
let cachePaths = JSON.parse(core.getState(constants_1.State.CachePaths) || '[]');
60397+
cachePaths = cachePaths.filter(fs_1.default.existsSync);
6039360398
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
6039460399
if (!packageManagerInfo) {
6039560400
core.debug(`Caching for '${packageManager}' is not supported`);
6039660401
return;
6039760402
}
60398-
if (cachePaths.length === 0) {
60403+
if (!cachePaths.length) {
6039960404
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
6040060405
// export declare function getInput(name: string, options?: InputOptions): string;
6040160406
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';

src/cache-save.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import * as core from '@actions/core';
22
import * as cache from '@actions/cache';
3+
4+
import fs from 'fs';
5+
36
import {State} from './constants';
47
import {getPackageManagerInfo} from './cache-utils';
58

@@ -23,15 +26,18 @@ export async function run() {
2326
const cachePackages = async (packageManager: string) => {
2427
const state = core.getState(State.CacheMatchedKey);
2528
const primaryKey = core.getState(State.CachePrimaryKey);
26-
const cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]');
29+
let cachePaths = JSON.parse(
30+
core.getState(State.CachePaths) || '[]'
31+
) as string[];
32+
cachePaths = cachePaths.filter(fs.existsSync);
2733

2834
const packageManagerInfo = await getPackageManagerInfo(packageManager);
2935
if (!packageManagerInfo) {
3036
core.debug(`Caching for '${packageManager}' is not supported`);
3137
return;
3238
}
3339

34-
if (cachePaths.length === 0) {
40+
if (!cachePaths.length) {
3541
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
3642
// export declare function getInput(name: string, options?: InputOptions): string;
3743
const cacheDependencyPath = core.getInput('cache-dependency-path') || '';

0 commit comments

Comments
 (0)