mirror of
https://github.com/actions/setup-node.git
synced 2025-04-22 09:21:00 +00:00
work on resolving comments
This commit is contained in:
parent
1c630f9ff8
commit
62e9de96c2
8 changed files with 64 additions and 49 deletions
|
@ -50,7 +50,6 @@ describe('cache-restore', () => {
|
|||
let debugSpy: jest.SpyInstance;
|
||||
let setOutputSpy: jest.SpyInstance;
|
||||
let getCommandOutputSpy: jest.SpyInstance;
|
||||
let isCacheActionAvailable: jest.SpyInstance;
|
||||
let restoreCacheSpy: jest.SpyInstance;
|
||||
let hashFilesSpy: jest.SpyInstance;
|
||||
|
||||
|
@ -103,9 +102,6 @@ describe('cache-restore', () => {
|
|||
|
||||
// cache-utils
|
||||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
||||
|
||||
isCacheActionAvailable = jest.spyOn(utils, 'isCacheFeatureAvailable');
|
||||
isCacheActionAvailable.mockImplementation(() => true);
|
||||
});
|
||||
|
||||
describe('Validate provided package manager', () => {
|
||||
|
|
|
@ -28,7 +28,6 @@ describe('run', () => {
|
|||
let getStateSpy: jest.SpyInstance;
|
||||
let saveCacheSpy: jest.SpyInstance;
|
||||
let getCommandOutputSpy: jest.SpyInstance;
|
||||
let isCacheActionAvailable: jest.SpyInstance;
|
||||
let hashFilesSpy: jest.SpyInstance;
|
||||
let existsSpy: jest.SpyInstance;
|
||||
|
||||
|
@ -71,9 +70,6 @@ describe('run', () => {
|
|||
|
||||
// utils
|
||||
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
|
||||
|
||||
isCacheActionAvailable = jest.spyOn(utils, 'isCacheFeatureAvailable');
|
||||
isCacheActionAvailable.mockImplementation(() => true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -40,31 +40,28 @@ describe('cache-utils', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('isCacheFeatureAvailable is false', () => {
|
||||
it('isCacheFeatureAvailable for GHES is false', () => {
|
||||
isFeatureAvailable.mockImplementation(() => false);
|
||||
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
|
||||
|
||||
expect(isCacheFeatureAvailable()).toBe(false);
|
||||
expect(info).toHaveBeenCalledWith(
|
||||
'[warning]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.'
|
||||
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 is false', () => {
|
||||
it('isCacheFeatureAvailable for GHES has an interhal error', () => {
|
||||
isFeatureAvailable.mockImplementation(() => false);
|
||||
process.env['GITHUB_SERVER_URL'] = '';
|
||||
|
||||
expect(isCacheFeatureAvailable()).toBe(false);
|
||||
expect(info).toHaveBeenCalledWith(
|
||||
'[warning]An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'
|
||||
expect(() => isCacheFeatureAvailable()).toThrowError(
|
||||
'An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'
|
||||
);
|
||||
});
|
||||
|
||||
it('isCacheFeatureAvailable is true', () => {
|
||||
it('isCacheFeatureAvailable for GHES is available', () => {
|
||||
isFeatureAvailable.mockImplementation(() => true);
|
||||
|
||||
expect(isCacheFeatureAvailable()).toBe(true);
|
||||
expect(info).not.toHaveBeenCalled();
|
||||
expect(isCacheFeatureAvailable()).toStrictEqual(true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as core from '@actions/core';
|
|||
import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as im from '../src/installer';
|
||||
import * as cache from '@actions/cache';
|
||||
import fs from 'fs';
|
||||
import cp from 'child_process';
|
||||
import osm = require('os');
|
||||
|
@ -36,6 +37,7 @@ describe('setup-node', () => {
|
|||
let execSpy: jest.SpyInstance;
|
||||
let authSpy: jest.SpyInstance;
|
||||
let parseNodeVersionSpy: jest.SpyInstance;
|
||||
let isCacheActionAvailable: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
// @actions/core
|
||||
|
@ -67,6 +69,9 @@ describe('setup-node', () => {
|
|||
existsSpy = jest.spyOn(fs, 'existsSync');
|
||||
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
||||
|
||||
// @actions/tool-cache
|
||||
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
|
||||
|
||||
// disable authentication portion for installer tests
|
||||
authSpy = jest.spyOn(auth, 'configAuthentication');
|
||||
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(cnSpy).toHaveBeenCalledWith(
|
||||
`::error::An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.${osm.EOL}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('LTS version', () => {
|
||||
beforeEach(() => {
|
||||
os.platform = 'linux';
|
||||
|
|
9
dist/cache-save/index.js
vendored
9
dist/cache-save/index.js
vendored
|
@ -3873,10 +3873,6 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
|
|||
core.debug(`${packageManager} path is ${stdOut}`);
|
||||
return stdOut;
|
||||
});
|
||||
function logWarning(message) {
|
||||
const warningPrefix = '[warning]';
|
||||
core.info(`${warningPrefix}${message}`);
|
||||
}
|
||||
function isGhes() {
|
||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
|
@ -3885,12 +3881,11 @@ exports.isGhes = isGhes;
|
|||
function isCacheFeatureAvailable() {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
logWarning('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.');
|
||||
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 {
|
||||
logWarning('An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.');
|
||||
throw new Error('An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
14
dist/setup/index.js
vendored
14
dist/setup/index.js
vendored
|
@ -6617,10 +6617,7 @@ function run() {
|
|||
if (registryUrl) {
|
||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||
}
|
||||
if (cache) {
|
||||
if (!cache_utils_1.isCacheFeatureAvailable()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
if (cache && cache_utils_1.isCacheFeatureAvailable()) {
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
yield cache_restore_1.restoreCache(cache, cacheDependencyPath);
|
||||
}
|
||||
|
@ -46129,10 +46126,6 @@ exports.getCacheDirectoryPath = (packageManagerInfo, packageManager) => __awaite
|
|||
core.debug(`${packageManager} path is ${stdOut}`);
|
||||
return stdOut;
|
||||
});
|
||||
function logWarning(message) {
|
||||
const warningPrefix = '[warning]';
|
||||
core.info(`${warningPrefix}${message}`);
|
||||
}
|
||||
function isGhes() {
|
||||
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||
|
@ -46141,12 +46134,11 @@ exports.isGhes = isGhes;
|
|||
function isCacheFeatureAvailable() {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
logWarning('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.');
|
||||
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 {
|
||||
logWarning('An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.');
|
||||
throw new Error('An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -97,11 +97,6 @@ export const getCacheDirectoryPath = async (
|
|||
return stdOut;
|
||||
};
|
||||
|
||||
function logWarning(message: string): void {
|
||||
const warningPrefix = '[warning]';
|
||||
core.info(`${warningPrefix}${message}`);
|
||||
}
|
||||
|
||||
export function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
|
@ -112,15 +107,14 @@ export function isGhes(): boolean {
|
|||
export function isCacheFeatureAvailable(): boolean {
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
if (isGhes()) {
|
||||
logWarning(
|
||||
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 {
|
||||
logWarning(
|
||||
throw new Error(
|
||||
'An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -45,10 +45,7 @@ export async function run() {
|
|||
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
if (!isCacheFeatureAvailable()) {
|
||||
throw new Error('Caching is not supported on GHES');
|
||||
}
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(cache, cacheDependencyPath);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue