mirror of
https://github.com/actions/setup-node.git
synced 2024-11-10 05:31:07 +07:00
Caching on GHES (#452)
* add support for ghes caching * fix licesnses * work on resolving comments * change internal error to warning * fix warning for internal errors * update version
This commit is contained in:
parent
bed538bd04
commit
bacd6b4b3a
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
@ -1,37 +1,28 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import * as cache from '@actions/cache';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as utils from '../src/cache-utils';
|
import * as utils from '../src/cache-utils';
|
||||||
import {PackageManagerInfo} from '../src/cache-utils';
|
import {PackageManagerInfo, isCacheFeatureAvailable} from '../src/cache-utils';
|
||||||
|
|
||||||
describe('cache-utils', () => {
|
describe('cache-utils', () => {
|
||||||
const commonPath = '/some/random/path';
|
|
||||||
const versionYarn1 = '1.2.3';
|
const versionYarn1 = '1.2.3';
|
||||||
const versionYarn2 = '2.3.4';
|
|
||||||
|
|
||||||
let debugSpy: jest.SpyInstance;
|
let debugSpy: jest.SpyInstance;
|
||||||
let getCommandOutputSpy: jest.SpyInstance;
|
let getCommandOutputSpy: jest.SpyInstance;
|
||||||
|
let isFeatureAvailable: jest.SpyInstance;
|
||||||
function getPackagePath(name: string) {
|
let info: jest.SpyInstance;
|
||||||
if (name === utils.supportedPackageManagers.npm.getCacheFolderCommand) {
|
let warningSpy: jest.SpyInstance;
|
||||||
return `${commonPath}/npm`;
|
|
||||||
} else if (
|
|
||||||
name === utils.supportedPackageManagers.pnpm.getCacheFolderCommand
|
|
||||||
) {
|
|
||||||
return `${commonPath}/pnpm`;
|
|
||||||
} else {
|
|
||||||
if (name === utils.supportedPackageManagers.yarn1.getCacheFolderCommand) {
|
|
||||||
return `${commonPath}/yarn1`;
|
|
||||||
} else {
|
|
||||||
return `${commonPath}/yarn2`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
|
||||||
debugSpy = jest.spyOn(core, 'debug');
|
debugSpy = jest.spyOn(core, 'debug');
|
||||||
debugSpy.mockImplementation(msg => {});
|
debugSpy.mockImplementation(msg => {});
|
||||||
|
|
||||||
|
info = jest.spyOn(core, 'info');
|
||||||
|
warningSpy = jest.spyOn(core, 'warning');
|
||||||
|
|
||||||
|
isFeatureAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
||||||
|
|
||||||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,7 +42,32 @@ describe('cache-utils', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('isCacheFeatureAvailable for GHES is false', () => {
|
||||||
|
isFeatureAvailable.mockImplementation(() => false);
|
||||||
|
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
|
||||||
|
|
||||||
|
expect(() => isCacheFeatureAvailable()).toThrowError(
|
||||||
|
'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.'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isCacheFeatureAvailable for GHES has an interhal error', () => {
|
||||||
|
isFeatureAvailable.mockImplementation(() => false);
|
||||||
|
process.env['GITHUB_SERVER_URL'] = '';
|
||||||
|
isCacheFeatureAvailable();
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isCacheFeatureAvailable for GHES is available', () => {
|
||||||
|
isFeatureAvailable.mockImplementation(() => true);
|
||||||
|
|
||||||
|
expect(isCacheFeatureAvailable()).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
process.env['GITHUB_SERVER_URL'] = '';
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as im from '../src/installer';
|
import * as im from '../src/installer';
|
||||||
|
import * as cache from '@actions/cache';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import osm = require('os');
|
import osm = require('os');
|
||||||
@ -36,6 +37,7 @@ describe('setup-node', () => {
|
|||||||
let execSpy: jest.SpyInstance;
|
let execSpy: jest.SpyInstance;
|
||||||
let authSpy: jest.SpyInstance;
|
let authSpy: jest.SpyInstance;
|
||||||
let parseNodeVersionSpy: jest.SpyInstance;
|
let parseNodeVersionSpy: jest.SpyInstance;
|
||||||
|
let isCacheActionAvailable: jest.SpyInstance;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// @actions/core
|
// @actions/core
|
||||||
@ -67,6 +69,9 @@ describe('setup-node', () => {
|
|||||||
existsSpy = jest.spyOn(fs, 'existsSync');
|
existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
||||||
|
|
||||||
|
// @actions/tool-cache
|
||||||
|
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
||||||
|
|
||||||
// disable authentication portion for installer tests
|
// disable authentication portion for installer tests
|
||||||
authSpy = jest.spyOn(auth, 'configAuthentication');
|
authSpy = jest.spyOn(auth, 'configAuthentication');
|
||||||
authSpy.mockImplementation(() => {});
|
authSpy.mockImplementation(() => {});
|
||||||
@ -644,6 +649,49 @@ describe('setup-node', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('cache on GHES', () => {
|
||||||
|
it('Should throw an error, because cache is not supported', async () => {
|
||||||
|
inputs['node-version'] = '12';
|
||||||
|
inputs['cache'] = 'npm';
|
||||||
|
|
||||||
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
|
let toolPath = path.normalize('/cache/node/12.16.1/x64');
|
||||||
|
findSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
|
// expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
|
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
|
||||||
|
isCacheActionAvailable.mockImplementation(() => false);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(cnSpy).toHaveBeenCalledWith(
|
||||||
|
`::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.${osm.EOL}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should throw an internal error', async () => {
|
||||||
|
inputs['node-version'] = '12';
|
||||||
|
inputs['cache'] = 'npm';
|
||||||
|
|
||||||
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
|
let toolPath = path.normalize('/cache/node/12.16.1/x64');
|
||||||
|
findSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
|
// expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
|
process.env['GITHUB_SERVER_URL'] = '';
|
||||||
|
isCacheActionAvailable.mockImplementation(() => false);
|
||||||
|
|
||||||
|
await main.run();
|
||||||
|
|
||||||
|
expect(warningSpy).toHaveBeenCalledWith(
|
||||||
|
'The runner was not able to contact the cache service. Caching will be skipped'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('LTS version', () => {
|
describe('LTS version', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
|
36
dist/cache-save/index.js
vendored
36
dist/cache-save/index.js
vendored
@ -3139,10 +3139,7 @@ const options_1 = __webpack_require__(248);
|
|||||||
const requestUtils_1 = __webpack_require__(826);
|
const requestUtils_1 = __webpack_require__(826);
|
||||||
const versionSalt = '1.0';
|
const versionSalt = '1.0';
|
||||||
function getCacheApiUrl(resource) {
|
function getCacheApiUrl(resource) {
|
||||||
// Ideally we just use ACTIONS_CACHE_URL
|
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
|
||||||
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
|
|
||||||
process.env['ACTIONS_RUNTIME_URL'] ||
|
|
||||||
'').replace('pipelines', 'artifactcache');
|
|
||||||
if (!baseUrl) {
|
if (!baseUrl) {
|
||||||
throw new Error('Cache Service Url not found, unable to restore cache.');
|
throw new Error('Cache Service Url not found, unable to restore cache.');
|
||||||
}
|
}
|
||||||
@ -3811,6 +3808,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const exec = __importStar(__webpack_require__(986));
|
const exec = __importStar(__webpack_require__(986));
|
||||||
|
const cache = __importStar(__webpack_require__(692));
|
||||||
exports.supportedPackageManagers = {
|
exports.supportedPackageManagers = {
|
||||||
npm: {
|
npm: {
|
||||||
lockFilePatterns: ['package-lock.json', 'yarn.lock'],
|
lockFilePatterns: ['package-lock.json', 'yarn.lock'],
|
||||||
@ -3875,6 +3873,24 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
|
|||||||
core.debug(`${packageManager} path is ${stdOut}`);
|
core.debug(`${packageManager} path is ${stdOut}`);
|
||||||
return stdOut;
|
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;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -5703,7 +5719,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
|
|||||||
//
|
//
|
||||||
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
|
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
|
||||||
// on 64-bit systems), split the download into multiple segments
|
// on 64-bit systems), split the download into multiple segments
|
||||||
const maxSegmentSize = buffer.constants.MAX_LENGTH;
|
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
|
||||||
|
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH);
|
||||||
const downloadProgress = new DownloadProgress(contentLength);
|
const downloadProgress = new DownloadProgress(contentLength);
|
||||||
const fd = fs.openSync(archivePath, 'w');
|
const fd = fs.openSync(archivePath, 'w');
|
||||||
try {
|
try {
|
||||||
@ -43258,6 +43275,15 @@ function checkKey(key) {
|
|||||||
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
|
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* isFeatureAvailable to check the presence of Actions cache service
|
||||||
|
*
|
||||||
|
* @returns boolean return true if Actions cache service feature is available, otherwise false
|
||||||
|
*/
|
||||||
|
function isFeatureAvailable() {
|
||||||
|
return !!process.env['ACTIONS_CACHE_URL'];
|
||||||
|
}
|
||||||
|
exports.isFeatureAvailable = isFeatureAvailable;
|
||||||
/**
|
/**
|
||||||
* Restores cache from keys
|
* Restores cache from keys
|
||||||
*
|
*
|
||||||
|
49
dist/setup/index.js
vendored
49
dist/setup/index.js
vendored
@ -5410,10 +5410,7 @@ const options_1 = __webpack_require__(161);
|
|||||||
const requestUtils_1 = __webpack_require__(246);
|
const requestUtils_1 = __webpack_require__(246);
|
||||||
const versionSalt = '1.0';
|
const versionSalt = '1.0';
|
||||||
function getCacheApiUrl(resource) {
|
function getCacheApiUrl(resource) {
|
||||||
// Ideally we just use ACTIONS_CACHE_URL
|
const baseUrl = process.env['ACTIONS_CACHE_URL'] || '';
|
||||||
const baseUrl = (process.env['ACTIONS_CACHE_URL'] ||
|
|
||||||
process.env['ACTIONS_RUNTIME_URL'] ||
|
|
||||||
'').replace('pipelines', 'artifactcache');
|
|
||||||
if (!baseUrl) {
|
if (!baseUrl) {
|
||||||
throw new Error('Cache Service Url not found, unable to restore cache.');
|
throw new Error('Cache Service Url not found, unable to restore cache.');
|
||||||
}
|
}
|
||||||
@ -6588,7 +6585,7 @@ const fs_1 = __importDefault(__webpack_require__(747));
|
|||||||
const auth = __importStar(__webpack_require__(749));
|
const auth = __importStar(__webpack_require__(749));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const cache_restore_1 = __webpack_require__(409);
|
const cache_restore_1 = __webpack_require__(409);
|
||||||
const url_1 = __webpack_require__(835);
|
const cache_utils_1 = __webpack_require__(570);
|
||||||
const os = __webpack_require__(87);
|
const os = __webpack_require__(87);
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -6610,7 +6607,7 @@ function run() {
|
|||||||
}
|
}
|
||||||
if (version) {
|
if (version) {
|
||||||
let token = core.getInput('token');
|
let token = core.getInput('token');
|
||||||
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
let auth = !token || cache_utils_1.isGhes() ? undefined : `token ${token}`;
|
||||||
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||||
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
|
||||||
yield installer.getNode(version, stable, checkLatest, auth, arch);
|
yield installer.getNode(version, stable, checkLatest, auth, arch);
|
||||||
@ -6620,10 +6617,7 @@ function run() {
|
|||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
if (cache) {
|
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
|
||||||
if (isGhes()) {
|
|
||||||
throw new Error('Caching is not supported on GHES');
|
|
||||||
}
|
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
yield cache_restore_1.restoreCache(cache, cacheDependencyPath);
|
yield cache_restore_1.restoreCache(cache, cacheDependencyPath);
|
||||||
}
|
}
|
||||||
@ -6638,10 +6632,6 @@ function run() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.run = run;
|
exports.run = run;
|
||||||
function isGhes() {
|
|
||||||
const ghUrl = new url_1.URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
||||||
}
|
|
||||||
function resolveVersionInput() {
|
function resolveVersionInput() {
|
||||||
let version = core.getInput('node-version');
|
let version = core.getInput('node-version');
|
||||||
const versionFileInput = core.getInput('node-version-file');
|
const versionFileInput = core.getInput('node-version-file');
|
||||||
@ -9525,7 +9515,8 @@ function downloadCacheStorageSDK(archiveLocation, archivePath, options) {
|
|||||||
//
|
//
|
||||||
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
|
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
|
||||||
// on 64-bit systems), split the download into multiple segments
|
// on 64-bit systems), split the download into multiple segments
|
||||||
const maxSegmentSize = buffer.constants.MAX_LENGTH;
|
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
|
||||||
|
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH);
|
||||||
const downloadProgress = new DownloadProgress(contentLength);
|
const downloadProgress = new DownloadProgress(contentLength);
|
||||||
const fd = fs.openSync(archivePath, 'w');
|
const fd = fs.openSync(archivePath, 'w');
|
||||||
try {
|
try {
|
||||||
@ -46070,6 +46061,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const exec = __importStar(__webpack_require__(986));
|
const exec = __importStar(__webpack_require__(986));
|
||||||
|
const cache = __importStar(__webpack_require__(638));
|
||||||
exports.supportedPackageManagers = {
|
exports.supportedPackageManagers = {
|
||||||
npm: {
|
npm: {
|
||||||
lockFilePatterns: ['package-lock.json', 'yarn.lock'],
|
lockFilePatterns: ['package-lock.json', 'yarn.lock'],
|
||||||
@ -46134,6 +46126,24 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
|
|||||||
core.debug(`${packageManager} path is ${stdOut}`);
|
core.debug(`${packageManager} path is ${stdOut}`);
|
||||||
return stdOut;
|
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;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -47526,6 +47536,15 @@ function checkKey(key) {
|
|||||||
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
|
throw new ValidationError(`Key Validation Error: ${key} cannot contain commas.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* isFeatureAvailable to check the presence of Actions cache service
|
||||||
|
*
|
||||||
|
* @returns boolean return true if Actions cache service feature is available, otherwise false
|
||||||
|
*/
|
||||||
|
function isFeatureAvailable() {
|
||||||
|
return !!process.env['ACTIONS_CACHE_URL'];
|
||||||
|
}
|
||||||
|
exports.isFeatureAvailable = isFeatureAvailable;
|
||||||
/**
|
/**
|
||||||
* Restores cache from keys
|
* Restores cache from keys
|
||||||
*
|
*
|
||||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "2.0.0",
|
"version": "3.1.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "2.0.0",
|
"version": "3.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^1.0.8",
|
"@actions/cache": "^2.0.0",
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.6.0",
|
||||||
"@actions/exec": "^1.1.0",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
@ -32,17 +32,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/cache": {
|
"node_modules/@actions/cache": {
|
||||||
"version": "1.0.8",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.0.tgz",
|
||||||
"integrity": "sha512-GWNNB67w93HGJRQXlsV56YqrdAuDoP3esK/mo5mzU8WoDCVjtQgJGsTdkYUX7brswtT7xnI30bWNo1WLKQ8FZQ==",
|
"integrity": "sha512-d7n8ul6HjWX6oDrNEPoqn8ZvqyyDhp9Uek6WOxALyxGVsXU+8+ND+viD3UfrXVWfs/GQiqI5Eq4cOozZj0yRFQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "^1.0.1",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/glob": "^0.1.0",
|
"@actions/glob": "^0.1.0",
|
||||||
"@actions/http-client": "^1.0.9",
|
"@actions/http-client": "^1.0.9",
|
||||||
"@actions/io": "^1.0.1",
|
"@actions/io": "^1.0.1",
|
||||||
"@azure/ms-rest-js": "^2.0.7",
|
"@azure/ms-rest-js": "^2.6.0",
|
||||||
"@azure/storage-blob": "^12.1.2",
|
"@azure/storage-blob": "^12.8.0",
|
||||||
"semver": "^6.1.0",
|
"semver": "^6.1.0",
|
||||||
"uuid": "^3.3.3"
|
"uuid": "^3.3.3"
|
||||||
}
|
}
|
||||||
@ -5077,17 +5077,17 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": {
|
"@actions/cache": {
|
||||||
"version": "1.0.8",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/cache/-/cache-2.0.0.tgz",
|
||||||
"integrity": "sha512-GWNNB67w93HGJRQXlsV56YqrdAuDoP3esK/mo5mzU8WoDCVjtQgJGsTdkYUX7brswtT7xnI30bWNo1WLKQ8FZQ==",
|
"integrity": "sha512-d7n8ul6HjWX6oDrNEPoqn8ZvqyyDhp9Uek6WOxALyxGVsXU+8+ND+viD3UfrXVWfs/GQiqI5Eq4cOozZj0yRFQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "^1.0.1",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/glob": "^0.1.0",
|
"@actions/glob": "^0.1.0",
|
||||||
"@actions/http-client": "^1.0.9",
|
"@actions/http-client": "^1.0.9",
|
||||||
"@actions/io": "^1.0.1",
|
"@actions/io": "^1.0.1",
|
||||||
"@azure/ms-rest-js": "^2.0.7",
|
"@azure/ms-rest-js": "^2.6.0",
|
||||||
"@azure/storage-blob": "^12.1.2",
|
"@azure/storage-blob": "^12.8.0",
|
||||||
"semver": "^6.1.0",
|
"semver": "^6.1.0",
|
||||||
"uuid": "^3.3.3"
|
"uuid": "^3.3.3"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-node",
|
"name": "setup-node",
|
||||||
"version": "2.0.0",
|
"version": "3.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup node action",
|
"description": "setup node action",
|
||||||
"main": "lib/setup-node.js",
|
"main": "lib/setup-node.js",
|
||||||
@ -23,7 +23,7 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^1.0.8",
|
"@actions/cache": "^2.0.0",
|
||||||
"@actions/core": "^1.6.0",
|
"@actions/core": "^1.6.0",
|
||||||
"@actions/exec": "^1.1.0",
|
"@actions/exec": "^1.1.0",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as cache from '@actions/cache';
|
||||||
|
|
||||||
type SupportedPackageManagers = {
|
type SupportedPackageManagers = {
|
||||||
[prop: string]: PackageManagerInfo;
|
[prop: string]: PackageManagerInfo;
|
||||||
@ -95,3 +96,28 @@ export const getCacheDirectoryPath = async (
|
|||||||
|
|
||||||
return stdOut;
|
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,7 +4,7 @@ import fs from 'fs';
|
|||||||
import * as auth from './authutil';
|
import * as auth from './authutil';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {URL} from 'url';
|
import {isGhes, isCacheFeatureAvailable} from './cache-utils';
|
||||||
import os = require('os');
|
import os = require('os');
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
@ -45,10 +45,7 @@ export async function run() {
|
|||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
if (isGhes()) {
|
|
||||||
throw new Error('Caching is not supported on GHES');
|
|
||||||
}
|
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
await restoreCache(cache, cacheDependencyPath);
|
await restoreCache(cache, cacheDependencyPath);
|
||||||
}
|
}
|
||||||
@ -66,13 +63,6 @@ export async function run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isGhes(): boolean {
|
|
||||||
const ghUrl = new URL(
|
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
||||||
);
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveVersionInput(): string {
|
function resolveVersionInput(): string {
|
||||||
let version = core.getInput('node-version');
|
let version = core.getInput('node-version');
|
||||||
const versionFileInput = core.getInput('node-version-file');
|
const versionFileInput = core.getInput('node-version-file');
|
||||||
|
Loading…
Reference in New Issue
Block a user