mirror of
https://github.com/actions/setup-go.git
synced 2025-04-24 01:50:52 +00:00
Add functionality for caching with GHES
This commit is contained in:
parent
e72fc4648f
commit
1466d1b901
4 changed files with 74 additions and 24 deletions
22
dist/cache-save/index.js
vendored
22
dist/cache-save/index.js
vendored
|
@ -3924,7 +3924,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
||||
const cache = __importStar(__webpack_require__(692));
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const exec = __importStar(__webpack_require__(986));
|
||||
const package_managers_1 = __webpack_require__(813);
|
||||
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
|
@ -3951,6 +3953,24 @@ exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0
|
|||
}
|
||||
return stdout;
|
||||
});
|
||||
function isGhes() {
|
||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
exports.isGhes = isGhes;
|
||||
function isCacheFeatureAvailable() {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
|
||||
}
|
||||
else {
|
||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
35
dist/setup/index.js
vendored
35
dist/setup/index.js
vendored
|
@ -3689,9 +3689,9 @@ const installer = __importStar(__webpack_require__(923));
|
|||
const semver = __importStar(__webpack_require__(280));
|
||||
const path_1 = __importDefault(__webpack_require__(622));
|
||||
const cache_restore_1 = __webpack_require__(409);
|
||||
const cache_utils_1 = __webpack_require__(143);
|
||||
const child_process_1 = __importDefault(__webpack_require__(129));
|
||||
const fs_1 = __importDefault(__webpack_require__(747));
|
||||
const url_1 = __webpack_require__(835);
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
|
@ -3704,7 +3704,7 @@ function run() {
|
|||
core.info(`Setup go version spec ${versionSpec}`);
|
||||
if (versionSpec) {
|
||||
let token = core.getInput('token');
|
||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||
let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`;
|
||||
const checkLatest = core.getBooleanInput('check-latest');
|
||||
const installDir = yield installer.getGo(versionSpec, checkLatest, auth);
|
||||
core.addPath(path_1.default.join(installDir, 'bin'));
|
||||
|
@ -3719,10 +3719,7 @@ function run() {
|
|||
core.debug(`add bin ${added}`);
|
||||
core.info(`Successfully setup go version ${versionSpec}`);
|
||||
}
|
||||
if (cache) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
|
||||
const packageManager = 'default';
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
yield cache_restore_1.restoreCache(packageManager, cacheDependencyPath);
|
||||
|
@ -3775,10 +3772,6 @@ function addBinToPath() {
|
|||
});
|
||||
}
|
||||
exports.addBinToPath = addBinToPath;
|
||||
function isGhes() {
|
||||
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
@ -4171,7 +4164,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
||||
exports.isCacheFeatureAvailable = exports.isGhes = exports.getCacheDirectoryPath = exports.getPackageManagerInfo = exports.getCommandOutput = void 0;
|
||||
const cache = __importStar(__webpack_require__(692));
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const exec = __importStar(__webpack_require__(986));
|
||||
const package_managers_1 = __webpack_require__(813);
|
||||
exports.getCommandOutput = (toolCommand) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
|
@ -4198,6 +4193,24 @@ exports.getCacheDirectoryPath = (packageManagerInfo) => __awaiter(void 0, void 0
|
|||
}
|
||||
return stdout;
|
||||
});
|
||||
function isGhes() {
|
||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
exports.isGhes = isGhes;
|
||||
function isCacheFeatureAvailable() {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.');
|
||||
}
|
||||
else {
|
||||
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
||||
|
||||
|
@ -42,3 +44,28 @@ export const getCacheDirectoryPath = async (
|
|||
|
||||
return stdout;
|
||||
};
|
||||
|
||||
export function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
||||
export function isCacheFeatureAvailable(): boolean {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
throw new Error(
|
||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'
|
||||
);
|
||||
} else {
|
||||
core.warning(
|
||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -4,9 +4,9 @@ import * as installer from './installer';
|
|||
import * as semver from 'semver';
|
||||
import path from 'path';
|
||||
import {restoreCache} from './cache-restore';
|
||||
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
|
||||
import cp from 'child_process';
|
||||
import fs from 'fs';
|
||||
import {URL} from 'url';
|
||||
|
||||
export async function run() {
|
||||
try {
|
||||
|
@ -41,10 +41,7 @@ export async function run() {
|
|||
core.info(`Successfully setup go version ${versionSpec}`);
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
if (isGhes()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
const packageManager = 'default';
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(packageManager, cacheDependencyPath);
|
||||
|
@ -98,10 +95,3 @@ export async function addBinToPath(): Promise<boolean> {
|
|||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
);
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue