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 diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 4627f2c7..92628f71 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 path = 'node_modules' + const primaryKey = 'Linux-node-bb828da54c148048dd17899ba9fda624811cfb43' + jest.spyOn(cacheUtils, 'resolvePaths').mockImplementation(async () => { + return [] + }) + await expect(saveCache([path], primaryKey)).rejects.toThrowError( + `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` + ) +}) 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", 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": [ diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index 86dd60c8..b11d6310 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 Error( + `Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.` + ) + } + const archiveFolder = await utils.createTempDirectory() const archivePath = path.join( archiveFolder,