diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index f1f95577..25124b46 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -32,3 +32,9 @@ test('assertDefined throws if undefined', () => { test('assertDefined returns value', () => { expect(cacheUtils.assertDefined('test', 5)).toBe(5) }) + +test('resolvePaths works on github workspace directory', async () => { + const workspace = process.env['GITHUB_WORKSPACE'] ?? '.' + const paths = await cacheUtils.resolvePaths([workspace]) + expect(paths.length).toBeGreaterThan(0) +}) diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index 9c1035a9..c2ace526 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/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