Show warning instead of failure when cache is not reachable

This commit is contained in:
Ricardo Cino 2022-06-13 11:22:21 +00:00
parent eeb10cff27
commit dfc4b745b4
4 changed files with 13 additions and 6 deletions

View File

@ -46,7 +46,8 @@ describe('cache-utils', () => {
isFeatureAvailable.mockImplementation(() => false);
process.env['GITHUB_SERVER_URL'] = 'https://www.test.com';
expect(() => isCacheFeatureAvailable()).toThrowError(
isCacheFeatureAvailable();
expect(warningSpy).toHaveBeenCalledWith(
'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.'
);
});

View File

@ -644,8 +644,8 @@ describe('setup-node', () => {
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}`
expect(warningSpy).toHaveBeenCalledWith(
'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.'
);
});

View File

@ -107,7 +107,7 @@ export function isGhes(): boolean {
export function isCacheFeatureAvailable(): boolean {
if (!cache.isFeatureAvailable()) {
if (isGhes()) {
throw new Error(
core.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.'
);
} else {

View File

@ -16,7 +16,6 @@ export async function run() {
let version = resolveVersionInput();
let arch = core.getInput('architecture');
const cache = core.getInput('cache');
// if architecture supplied but node-version is not
// if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant.
@ -39,6 +38,13 @@ export async function run() {
await installer.getNode(version, stable, checkLatest, auth, arch);
}
} catch (err) {
core.setFailed(err.message);
}
try {
const cache = core.getInput('cache');
const registryUrl: string = core.getInput('registry-url');
const alwaysAuth: string = core.getInput('always-auth');
if (registryUrl) {
@ -59,7 +65,7 @@ export async function run() {
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
);
} catch (err) {
core.setFailed(err.message);
core.warning(err.message);
}
}