From c5c30f57578925f82b2b7dbc0b79dcd951a74d58 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Wed, 30 Mar 2022 01:04:37 +0530 Subject: [PATCH] review comments --- __tests__/utils.test.ts | 15 ++++++++------- dist/setup/index.js | 4 +++- src/utils.ts | 5 ++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index 9c764ffe..009031a2 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -1,4 +1,5 @@ import * as cache from '@actions/cache'; +import * as core from '@actions/core'; import { validateVersion, validatePythonVersionFormatForPyPy, @@ -6,6 +7,7 @@ import { } from '../src/utils'; jest.mock('@actions/cache'); +jest.mock('@actions/core'); describe('validatePythonVersionFormatForPyPy', () => { it.each([ @@ -46,7 +48,7 @@ describe('isCacheFeatureAvailable', () => { } catch (error) { expect(error).toHaveProperty( 'message', - 'Caching 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.' + 'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.' ); } finally { delete process.env['GITHUB_SERVER_URL']; @@ -55,14 +57,13 @@ describe('isCacheFeatureAvailable', () => { it('isCacheFeatureAvailable disabled on dotcom', () => { jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false); + const infoMock = jest.spyOn(core, 'warning'); + const message = + 'An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'; try { process.env['GITHUB_SERVER_URL'] = 'http://github.com'; - isCacheFeatureAvailable(); - } catch (error) { - expect(error).toHaveProperty( - 'message', - 'An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.' - ); + expect(isCacheFeatureAvailable()).toBe(false); + expect(infoMock).toHaveBeenCalledWith(message); } finally { delete process.env['GITHUB_SERVER_URL']; } diff --git a/dist/setup/index.js b/dist/setup/index.js index e449da6f..aff3d216 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -5599,6 +5599,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_LINUX = exports.IS_WINDOWS = void 0; const cache = __importStar(__webpack_require__(692)); +const core = __importStar(__webpack_require__(470)); const fs_1 = __importDefault(__webpack_require__(747)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(876)); @@ -5678,8 +5679,9 @@ function isCacheFeatureAvailable() { throw new Error('Caching 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 { - throw new Error('An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'); + core.warning('An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.'); } + return false; } return true; } diff --git a/src/utils.ts b/src/utils.ts index 8f9b75f9..b372ac58 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,5 @@ import * as cache from '@actions/cache'; +import * as core from '@actions/core'; import fs from 'fs'; import * as path from 'path'; import * as semver from 'semver'; @@ -108,10 +109,12 @@ export function isCacheFeatureAvailable(): boolean { 'Caching 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 { - throw new Error( + core.warning( 'An internal error has occurred in cache backend. Please check https://www.githubstatus.com/ for any ongoing issue in actions.' ); } + + return false; } return true;