From 545223a83e62ffdaade83757b098ec736d53e73f Mon Sep 17 00:00:00 2001 From: Jongwoo Han Date: Fri, 16 Dec 2022 23:04:57 +0900 Subject: [PATCH 1/2] refactor: Use early return pattern to avoid nested conditions (#428) --- __tests__/util.test.ts | 11 +++++------ dist/cleanup/index.js | 15 +++++++-------- dist/setup/index.js | 15 +++++++-------- src/util.ts | 18 +++++++++--------- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 9815c95..2122563 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -29,14 +29,13 @@ describe('isVersionSatisfies', () => { describe('isCacheFeatureAvailable', () => { it('isCacheFeatureAvailable disabled on GHES', () => { jest.spyOn(cache, 'isFeatureAvailable').mockImplementation(() => false); + const infoMock = jest.spyOn(core, 'warning'); + const message = + '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.'; try { process.env['GITHUB_SERVER_URL'] = 'http://example.com'; - isCacheFeatureAvailable(); - } catch (error) { - expect(error).toHaveProperty( - 'message', - '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.' - ); + expect(isCacheFeatureAvailable()).toBeFalsy(); + expect(infoMock).toHaveBeenCalledWith(message); } finally { delete process.env['GITHUB_SERVER_URL']; } diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 2d9cede..7a4f37b 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -68708,16 +68708,15 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('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.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } + if (cache.isFeatureAvailable()) { + return true; + } + if (isGhes()) { + core.warning('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.'); return false; } - return true; + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName) { diff --git a/dist/setup/index.js b/dist/setup/index.js index e19da8d..3b8eb74 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -105436,16 +105436,15 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('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.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } + if (cache.isFeatureAvailable()) { + return true; + } + if (isGhes()) { + core.warning('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.'); return false; } - return true; + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; function getVersionFromFileContent(content, distributionName) { diff --git a/src/util.ts b/src/util.ts index 9607603..d3a09f6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -85,19 +85,19 @@ export function isGhes(): boolean { } export function isCacheFeatureAvailable(): boolean { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error( - '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.' - ); - } else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } + if (cache.isFeatureAvailable()) { + return true; + } + if (isGhes()) { + core.warning( + '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.' + ); return false; } - return true; + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } export function getVersionFromFileContent( From 06db6c25b819ba00278bbaa10c7701d5182f91b8 Mon Sep 17 00:00:00 2001 From: Milos Pantic <101411245+panticmilos@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:07:31 +0100 Subject: [PATCH 2/2] Update architecture docs (#425) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ae5055..d416f83 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ This action allows you to work with Java and Scala projects. - `java-package`: The packaging variant of the choosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. Default value: `jdk`. - - `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: `x64`. + - `architecture`: The target architecture of the package. Possible values: `x86`, `x64`, `armv7`, `aarch64`, `ppc64le`. Default value: Derived from the runner machine. - `jdkFile`: If a use-case requires a custom distribution setup-java uses the compressed JDK from the location pointed by this input and will take care of the installation and caching on the VM.