feat(cache-restore): Find dependencies file in nested folder

Fix  "Dependencies file is not found" err if dep file is not in root dir
pull/288/head
Evgenii Korolevskii 2 years ago
parent 27b43e1b0d
commit 9160b5f5a9

@ -63020,16 +63020,11 @@ 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.restoreCache = void 0;
const cache = __importStar(__nccwpck_require__(7799));
const core = __importStar(__nccwpck_require__(2186));
const glob = __importStar(__nccwpck_require__(8090));
const path_1 = __importDefault(__nccwpck_require__(1017));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const constants_1 = __nccwpck_require__(9042);
const cache_utils_1 = __nccwpck_require__(1678);
exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () {
@ -63038,7 +63033,7 @@ exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __a
const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
const dependencyFilePath = cacheDependencyPath
? cacheDependencyPath
: findDependencyFile(packageManagerInfo);
: yield findDependencyFile(packageManagerInfo);
const fileHash = yield glob.hashFiles(dependencyFilePath);
if (!fileHash) {
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
@ -63056,16 +63051,15 @@ exports.restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __a
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);
core.info(`Cache restored from key: ${cacheKey}`);
});
const findDependencyFile = (packageManager) => {
const findDependencyFile = (packageManager) => __awaiter(void 0, void 0, void 0, function* () {
let dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE;
const rootContent = fs_1.default.readdirSync(workspace);
const goSumFileExists = rootContent.includes(dependencyFile);
if (!goSumFileExists) {
throw new Error(`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`);
const globber = yield glob.create(`**/${dependencyFile}`);
const files = yield globber.glob();
if (!files.length) {
throw new Error(`Dependencies file is not found in. Supported file pattern: ${dependencyFile}`);
}
return path_1.default.join(workspace, dependencyFile);
};
return files[0];
});
/***/ }),

@ -1,8 +1,6 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as glob from '@actions/glob';
import path from 'path';
import fs from 'fs';
import {State, Outputs} from './constants';
import {PackageManagerInfo} from './package-managers';
@ -20,7 +18,7 @@ export const restoreCache = async (
const dependencyFilePath = cacheDependencyPath
? cacheDependencyPath
: findDependencyFile(packageManagerInfo);
: await findDependencyFile(packageManagerInfo);
const fileHash = await glob.hashFiles(dependencyFilePath);
if (!fileHash) {
@ -47,17 +45,17 @@ export const restoreCache = async (
core.info(`Cache restored from key: ${cacheKey}`);
};
const findDependencyFile = (packageManager: PackageManagerInfo) => {
const findDependencyFile = async (packageManager: PackageManagerInfo) => {
let dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE!;
const rootContent = fs.readdirSync(workspace);
const goSumFileExists = rootContent.includes(dependencyFile);
if (!goSumFileExists) {
const globber = await glob.create(`**/${dependencyFile}`);
const files = await globber.glob();
if (!files.length) {
throw new Error(
`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`
`Dependencies file is not found. Supported file pattern: ${dependencyFile}`
);
}
return path.join(workspace, dependencyFile);
return files[0];
};

Loading…
Cancel
Save