mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 01:50:52 +00:00
Change behavior of the exception throwing
This commit is contained in:
parent
c64d0e04b0
commit
8c8442b8f8
5 changed files with 52 additions and 37 deletions
32
dist/cache-save/index.js
vendored
32
dist/cache-save/index.js
vendored
|
@ -4036,14 +4036,10 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
|
|||
return obtainedPackageManager;
|
||||
});
|
||||
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let pathList = [];
|
||||
for (let command of packageManagerInfo.cacheFolderCommandList) {
|
||||
pathList.push(yield exports.getCommandOutput(command));
|
||||
}
|
||||
for (let path of pathList) {
|
||||
if (!path) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
|
||||
const emptyPaths = pathList.filter(item => !item);
|
||||
if (emptyPaths.length) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
return pathList;
|
||||
});
|
||||
|
@ -49173,7 +49169,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.run = void 0;
|
||||
exports.logWarning = exports.run = void 0;
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const cache = __importStar(__webpack_require__(692));
|
||||
const fs_1 = __importDefault(__webpack_require__(747));
|
||||
|
@ -49206,18 +49202,23 @@ const cachePackages = () => __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 packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
|
||||
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
||||
for (let path of cachePath) {
|
||||
const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
||||
let pathsCounter = cachePaths.length;
|
||||
for (let path of cachePaths) {
|
||||
if (!fs_1.default.existsSync(path)) {
|
||||
throw new Error(`Cache folder path is retrieved but doesn't exist on disk: ${path}`);
|
||||
logWarning(`Cache folder path is retrieved but doesn't exist on disk: ${path}`);
|
||||
pathsCounter--;
|
||||
}
|
||||
}
|
||||
if (!pathsCounter) {
|
||||
throw `Cache folder paths are retrieved but don't exist on disk`;
|
||||
}
|
||||
if (primaryKey === state) {
|
||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
yield cache.saveCache(cachePath, primaryKey);
|
||||
yield cache.saveCache(cachePaths, primaryKey);
|
||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||
}
|
||||
catch (error) {
|
||||
|
@ -49232,6 +49233,11 @@ const cachePackages = () => __awaiter(void 0, void 0, void 0, function* () {
|
|||
}
|
||||
}
|
||||
});
|
||||
function logWarning(message) {
|
||||
const warningPrefix = '[warning]';
|
||||
core.info(`${warningPrefix}${message}`);
|
||||
}
|
||||
exports.logWarning = logWarning;
|
||||
run();
|
||||
|
||||
|
||||
|
|
16
dist/setup/index.js
vendored
16
dist/setup/index.js
vendored
|
@ -4298,14 +4298,10 @@ exports.getPackageManagerInfo = (packageManager) => __awaiter(void 0, void 0, vo
|
|||
return obtainedPackageManager;
|
||||
});
|
||||
exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let pathList = [];
|
||||
for (let command of packageManagerInfo.cacheFolderCommandList) {
|
||||
pathList.push(yield exports.getCommandOutput(command));
|
||||
}
|
||||
for (let path of pathList) {
|
||||
if (!path) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
let pathList = yield Promise.all(packageManagerInfo.cacheFolderCommandList.map((command) => __awaiter(void 0, void 0, void 0, function* () { return exports.getCommandOutput(command); })));
|
||||
const emptyPaths = pathList.filter(item => !item);
|
||||
if (emptyPaths.length) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
return pathList;
|
||||
});
|
||||
|
@ -37253,7 +37249,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
|
|||
const packageManagerInfo = yield cache_utils_1.getPackageManagerInfo(packageManager);
|
||||
const platform = process.env.RUNNER_OS;
|
||||
const versionSpec = core.getInput('go-version');
|
||||
const cachePath = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
||||
const cachePaths = yield cache_utils_1.getCacheDirectoryPath(packageManagerInfo);
|
||||
const dependencyFilePath = cacheDependencyPath
|
||||
? cacheDependencyPath
|
||||
: findDependencyFile(packageManagerInfo);
|
||||
|
@ -37264,7 +37260,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0
|
|||
const primaryKey = `${platform}-go${versionSpec}-${fileHash}`;
|
||||
core.debug(`primary key is ${primaryKey}`);
|
||||
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
|
||||
const cacheKey = yield cache.restoreCache(cachePath, primaryKey);
|
||||
const cacheKey = yield cache.restoreCache(cachePaths, primaryKey);
|
||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||
if (!cacheKey) {
|
||||
core.info(`Cache is not found`);
|
||||
|
|
|
@ -16,7 +16,7 @@ export const restoreCache = async (
|
|||
const platform = process.env.RUNNER_OS;
|
||||
const versionSpec = core.getInput('go-version');
|
||||
|
||||
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
|
||||
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
||||
|
||||
const dependencyFilePath = cacheDependencyPath
|
||||
? cacheDependencyPath
|
||||
|
@ -34,7 +34,7 @@ export const restoreCache = async (
|
|||
|
||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
||||
|
||||
const cacheKey = await cache.restoreCache(cachePath, primaryKey);
|
||||
const cacheKey = await cache.restoreCache(cachePaths, primaryKey);
|
||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||
|
||||
if (!cacheKey) {
|
||||
|
|
|
@ -33,16 +33,23 @@ const cachePackages = async () => {
|
|||
|
||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
||||
|
||||
const cachePath = await getCacheDirectoryPath(packageManagerInfo);
|
||||
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
||||
|
||||
for (let path of cachePath) {
|
||||
let pathsCounter = cachePaths.length;
|
||||
|
||||
for (let path of cachePaths) {
|
||||
if (!fs.existsSync(path)) {
|
||||
throw new Error(
|
||||
logWarning(
|
||||
`Cache folder path is retrieved but doesn't exist on disk: ${path}`
|
||||
);
|
||||
pathsCounter--;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pathsCounter) {
|
||||
throw `Cache folder paths are retrieved but don't exist on disk`;
|
||||
}
|
||||
|
||||
if (primaryKey === state) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
|
@ -51,7 +58,7 @@ const cachePackages = async () => {
|
|||
}
|
||||
|
||||
try {
|
||||
await cache.saveCache(cachePath, primaryKey);
|
||||
await cache.saveCache(cachePaths, primaryKey);
|
||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||
} catch (error) {
|
||||
if (error.name === cache.ValidationError.name) {
|
||||
|
@ -64,4 +71,9 @@ const cachePackages = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
export function logWarning(message: string): void {
|
||||
const warningPrefix = '[warning]';
|
||||
core.info(`${warningPrefix}${message}`);
|
||||
}
|
||||
|
||||
run();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import path from 'path';
|
||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
||||
|
||||
export const getCommandOutput = async (toolCommand: string) => {
|
||||
|
@ -34,16 +35,16 @@ export const getPackageManagerInfo = async (packageManager: string) => {
|
|||
export const getCacheDirectoryPath = async (
|
||||
packageManagerInfo: PackageManagerInfo
|
||||
) => {
|
||||
let pathList: string[] = [];
|
||||
let pathList = await Promise.all(
|
||||
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
||||
getCommandOutput(command)
|
||||
)
|
||||
);
|
||||
|
||||
for (let command of packageManagerInfo.cacheFolderCommandList) {
|
||||
pathList.push(await getCommandOutput(command));
|
||||
}
|
||||
const emptyPaths = pathList.filter(item => !item);
|
||||
|
||||
for (let path of pathList) {
|
||||
if (!path) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
if (emptyPaths.length) {
|
||||
throw new Error(`Could not get cache folder paths.`);
|
||||
}
|
||||
|
||||
return pathList;
|
||||
|
|
Loading…
Add table
Reference in a new issue