From da52b358001d3b152ed736de25091af285233dbc 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. --- packages/cache/src/cache.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 86dd60c8..e5b5f6a4 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/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 9aecf41d21d47077df5f93691c9064dec2213d2c 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 --- packages/cache/src/cache.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index e5b5f6a4..473e5eb2 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/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 b9fefecf57ef72e25189c7d6e0882a54f7baa7e6 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 --- packages/cache/src/cache.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 473e5eb2..ac4c1b23 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/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 07b91eafe571b1ecac394047efde45a251338c59 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 --- packages/cache/__tests__/saveCache.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 4627f2c7..bacb2e1c 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__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 64219896396e6ee9d94798001fce6fb18598b730 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 --- packages/cache/__tests__/saveCache.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index bacb2e1c..deb78367 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__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 10a39346639c2532aa41a8316ab7d63fe47e5f2c 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 --- packages/cache/__tests__/saveCache.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index deb78367..72836319 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__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 6f6f4e7588dbb0fad3d51865e5e4c71c971ded42 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. --- packages/cache/src/cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index ac4c1b23..b11d6310 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/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 92b210aced7974a2dc269cc35dae88e6bc5c6c91 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 --- packages/cache/__tests__/saveCache.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 72836319..92628f71 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__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 558edc0a3b9eb9c77b3d9969436ad2cfb52fbc64 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 --- packages/cache/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cache/package.json b/packages/cache/package.json index 0b7bff06..813ac880 100644 --- a/packages/cache/package.json +++ b/packages/cache/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 d618dc457e7e7bc4e6ea2a75c7d6de12dfb77392 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 --- packages/cache/package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cache/package-lock.json b/packages/cache/package-lock.json index 8ff62189..6a7414de 100644 --- a/packages/cache/package-lock.json +++ b/packages/cache/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 4ee0048304669bd5cae5cfa57f08fe9e641b8a02 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 --- packages/cache/RELEASES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cache/RELEASES.md b/packages/cache/RELEASES.md index 8adb7e3c..133be52a 100644 --- a/packages/cache/RELEASES.md +++ b/packages/cache/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