From 8ccf58a6eb6f9bafb340a1d7eb52550fd4dd467b Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Wed, 13 Jul 2022 11:39:29 +0000 Subject: [PATCH] Fix empty cache save on using or github.workspace(#833 in actions/cache) as path --- __tests__/cacheUtils.test.ts | 5 +++++ src/internal/cacheUtils.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/__tests__/cacheUtils.test.ts b/__tests__/cacheUtils.test.ts index f1f9557..c5817f2 100644 --- a/__tests__/cacheUtils.test.ts +++ b/__tests__/cacheUtils.test.ts @@ -32,3 +32,8 @@ test('assertDefined throws if undefined', () => { test('assertDefined returns value', () => { expect(cacheUtils.assertDefined('test', 5)).toBe(5) }) + +test('resolvePaths works on current directory', async () => { + const resolvedPath = await cacheUtils.resolvePaths(['.']) + expect(resolvedPath).toBe(['.']) +}) diff --git a/src/internal/cacheUtils.ts b/src/internal/cacheUtils.ts index 9c1035a..f2eb436 100644 --- a/src/internal/cacheUtils.ts +++ b/src/internal/cacheUtils.ts @@ -52,7 +52,12 @@ export async function resolvePaths(patterns: string[]): Promise { .replace(new RegExp(`\\${path.sep}`, 'g'), '/') core.debug(`Matched: ${relativeFile}`) // Paths are made relative so the tar entries are all relative to the root of the workspace. - paths.push(`${relativeFile}`) + if (relativeFile === "") { + // path.relative returns empty string if workspace and file are equal + paths.push(".") + } else { + paths.push(`${relativeFile}`) + } } return paths