Skip to content

Commit

Permalink
Merge pull request #1097 from actions/users/kotewar/avoid-empty-cache…
Browse files Browse the repository at this point in the history
…-save

Avoid saving empty cache when there are no files to cache.
  • Loading branch information
kotewar committed May 24, 2022
2 parents 1e0f628 + 4ee0048 commit 8263c4d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/cache/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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))
11 changes: 11 additions & 0 deletions packages/cache/__tests__/saveCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
)
})
4 changes: 2 additions & 2 deletions packages/cache/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/cache",
"version": "2.0.4",
"version": "2.0.5",
"preview": true,
"description": "Actions cache lib",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions packages/cache/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8263c4d

Please sign in to comment.