From 67b74a15ded86171e570373ef538c15cf07da4ef Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Thu, 19 Aug 2021 19:54:35 +0800 Subject: [PATCH] fix: throw error in case of no package manager file found --- __tests__/cache.test.ts | 10 ++++------ dist/cleanup/index.js | 3 +-- dist/setup/index.js | 3 +-- src/cache.ts | 3 +-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index 38995b51..54856ee6 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -65,9 +65,8 @@ describe('dependency cache', () => { }); describe('for maven', () => { - it('warns if no pom.xml found', async () => { - await restore('maven'); - expect(spyWarning).toBeCalledWith( + it('throws error if no pom.xml found', async () => { + await expect(restore('maven')).rejects.toThrowError( `No file in ${projectRoot( workspace )} matched to [**/pom.xml], make sure you have checked out the target repository` @@ -83,9 +82,8 @@ describe('dependency cache', () => { }); }); describe('for gradle', () => { - it('warns if no build.gradle found', async () => { - await restore('gradle'); - expect(spyWarning).toBeCalledWith( + it('throws error if no build.gradle found', async () => { + await expect(restore('gradle')).rejects.toThrowError( `No file in ${projectRoot( workspace )} matched to [**/*.gradle*,**/gradle-wrapper.properties], make sure you have checked out the target repository` diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 78ab4348..bbc65296 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -64589,8 +64589,7 @@ function restore(id) { core.debug(`primary key is ${primaryKey}`); core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey); if (primaryKey.endsWith('-')) { - core.warning(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`); - return; + throw new Error(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`); } const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, [ `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}` diff --git a/dist/setup/index.js b/dist/setup/index.js index c551eeca..d8f0e773 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -18976,8 +18976,7 @@ function restore(id) { core.debug(`primary key is ${primaryKey}`); core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey); if (primaryKey.endsWith('-')) { - core.warning(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`); - return; + throw new Error(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`); } const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, [ `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}` diff --git a/src/cache.ts b/src/cache.ts index d1571d94..fb97fb0b 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -65,12 +65,11 @@ export async function restore(id: string) { core.debug(`primary key is ${primaryKey}`); core.saveState(STATE_CACHE_PRIMARY_KEY, primaryKey); if (primaryKey.endsWith('-')) { - core.warning( + throw new Error( `No file in ${process.cwd()} matched to [${ packageManager.pattern }], make sure you have checked out the target repository` ); - return; } const matchedKey = await cache.restoreCache(packageManager.path, primaryKey, [