From 9a602d2d82b8099cc19ba6de07d9795110e71b21 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Sun, 22 May 2022 10:09:13 +0000 Subject: [PATCH 01/11] Adding check for cache paths' existence. --- src/cache.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cache.ts b/src/cache.ts index 86dd60c..e5b5f6a 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -158,6 +158,12 @@ export async function saveCache( core.debug('Cache Paths:') core.debug(`${JSON.stringify(cachePaths)}`) + + if(cachePaths.length === 0){ + throw new ValidationError( + `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.`) + } + const archiveFolder = await utils.createTempDirectory() const archivePath = path.join( archiveFolder, From fc1ac62569ea1a04602a51902291b023f015a113 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 05:39:42 +0000 Subject: [PATCH 02/11] Updated error type to generic to show warning --- src/cache.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index e5b5f6a..473e5eb 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -160,8 +160,9 @@ export async function saveCache( if(cachePaths.length === 0){ - throw new ValidationError( - `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.`) + throw new Error( + `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.` + ) } const archiveFolder = await utils.createTempDirectory() From 5f97eb6abaaeaf3ddb0ecd602f1d081724f00663 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 05:59:56 +0000 Subject: [PATCH 03/11] Formatting changes --- src/cache.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cache.ts b/src/cache.ts index 473e5eb..ac4c1b2 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -158,11 +158,10 @@ export async function saveCache( core.debug('Cache Paths:') core.debug(`${JSON.stringify(cachePaths)}`) - - if(cachePaths.length === 0){ + if (cachePaths.length === 0) { throw new Error( `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.` - ) + ) } const archiveFolder = await utils.createTempDirectory() From 94fe8e1a0dbf7b636df311f77f54f588a953cb57 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 06:32:13 +0000 Subject: [PATCH 04/11] Added unit test case for #624 --- __tests__/saveCache.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/__tests__/saveCache.test.ts b/__tests__/saveCache.test.ts index 4627f2c..bacb2e1 100644 --- a/__tests__/saveCache.test.ts +++ b/__tests__/saveCache.test.ts @@ -290,3 +290,14 @@ test('save with valid inputs uploads a cache', async () => { expect(saveCacheMock).toHaveBeenCalledWith(cacheId, archiveFile, undefined) expect(getCompressionMock).toHaveBeenCalledTimes(1) }) + +test('save with non existing path should not save cache', async () => { + const paths: string[] = ['aPathThatDoesnotExist'] + const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' + jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async filePaths => { + return [] + }) + await expect(saveCache(paths, primaryKey)).rejects.toThrowError( + `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.` + ) +}) From 1741a9235880226ce667fdb3a5f85e7209a16d2d Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 06:39:22 +0000 Subject: [PATCH 05/11] Standardized test case input --- __tests__/saveCache.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/saveCache.test.ts b/__tests__/saveCache.test.ts index bacb2e1..deb7836 100644 --- a/__tests__/saveCache.test.ts +++ b/__tests__/saveCache.test.ts @@ -292,7 +292,7 @@ test('save with valid inputs uploads a cache', async () => { }) test('save with non existing path should not save cache', async () => { - const paths: string[] = ['aPathThatDoesnotExist'] + const paths: string[] = ['node_modules'] const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async filePaths => { return [] From a018510ff85e5bcd70be62982bad7060017e25da Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 06:49:26 +0000 Subject: [PATCH 06/11] Fixed linting issues --- __tests__/saveCache.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/saveCache.test.ts b/__tests__/saveCache.test.ts index deb7836..7283631 100644 --- a/__tests__/saveCache.test.ts +++ b/__tests__/saveCache.test.ts @@ -292,12 +292,12 @@ test('save with valid inputs uploads a cache', async () => { }) test('save with non existing path should not save cache', async () => { - const paths: string[] = ['node_modules'] + const path = 'node_modules' const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' - jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async filePaths => { + jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => { return [] }) - await expect(saveCache(paths, primaryKey)).rejects.toThrowError( + await expect(saveCache([path], primaryKey)).rejects.toThrowError( `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.` ) }) From cb87af10a959afd8c9fe984b0ebc5f379e135c6b Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 12:03:18 +0000 Subject: [PATCH 07/11] Enhanced warning description to make more sense. --- src/cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache.ts b/src/cache.ts index ac4c1b2..b11d631 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -160,7 +160,7 @@ export async function saveCache( if (cachePaths.length === 0) { throw new Error( - `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.` + `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` ) } From 6b5378202fd1ec68a7083636dba022e7ea4e7ca5 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 23 May 2022 12:05:31 +0000 Subject: [PATCH 08/11] Test case fix for warning message changes --- __tests__/saveCache.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/saveCache.test.ts b/__tests__/saveCache.test.ts index 7283631..92628f7 100644 --- a/__tests__/saveCache.test.ts +++ b/__tests__/saveCache.test.ts @@ -298,6 +298,6 @@ test('save with non existing path should not save cache', async () => { return [] }) await expect(saveCache([path], primaryKey)).rejects.toThrowError( - `Path Validation Error: Path(s) specified in the action do not exist, hence no cache is being saved.` + `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` ) }) From 8f99492a8a96ee0b9adda5b9abf47b2430bbfbb9 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 24 May 2022 05:45:53 +0000 Subject: [PATCH 09/11] Patch version bumped from 2.0.4 to 2.0.5 for cache --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b7bff0..813ac88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@actions/cache", - "version": "2.0.4", + "version": "2.0.5", "preview": true, "description": "Actions cache lib", "keywords": [ From 09a20812f461fcf25faf13edc2cd9abbd717bb2d Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 24 May 2022 05:48:53 +0000 Subject: [PATCH 10/11] Added package-lock.json after version upgrade --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8ff6218..6a7414d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@actions/cache", - "version": "2.0.4", + "version": "2.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@actions/cache", - "version": "2.0.3", + "version": "2.0.5", "license": "MIT", "dependencies": { "@actions/core": "^1.2.6", From 4166efe273cbc1ee4f84d409b20d316da898129e Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Tue, 24 May 2022 06:55:11 +0000 Subject: [PATCH 11/11] Updated RELEASES.md with release information --- RELEASES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 8adb7e3..133be52 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -61,4 +61,7 @@ - Update to v2.0.0 of `@actions/http-client` ### 2.0.4 -- Update to v2.0.1 of `@actions/http-client` [#1087](https://github.com/actions/toolkit/pull/1087) \ No newline at end of file +- Update to v2.0.1 of `@actions/http-client` [#1087](https://github.com/actions/toolkit/pull/1087) + +### 2.0.5 +- Fix to avoid saving empty cache when no files are available for caching. ([issue](https://github.com/actions/cache/issues/624)) \ No newline at end of file