From 120202a68c755457b063f47a4f8c9cf3a3018846 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Wed, 13 Jul 2022 11:39:29 +0000 Subject: [PATCH 1/7] Fix empty cache save on using or github.workspace(#833 in actions/cache) as path --- packages/cache/__tests__/cacheUtils.test.ts | 5 +++++ packages/cache/src/internal/cacheUtils.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index f1f95577..c5817f2d 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__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/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index 9c1035a9..f2eb436a 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 From 593bc7061c5d9718c088c4f2c633f0f96a8d44c3 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Wed, 13 Jul 2022 11:55:36 +0000 Subject: [PATCH 2/7] Fix testcase for resolvePaths works on current directory --- packages/cache/__tests__/cacheUtils.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index c5817f2d..50486511 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -35,5 +35,5 @@ test('assertDefined returns value', () => { test('resolvePaths works on current directory', async () => { const resolvedPath = await cacheUtils.resolvePaths(['.']) - expect(resolvedPath).toBe(['.']) + expect(resolvedPath).toStrictEqual(['.']) }) From da6701aea96a11ec5b7de1018b4ac882091702c5 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Wed, 13 Jul 2022 13:37:49 +0000 Subject: [PATCH 3/7] Fix linting for changes --- packages/cache/src/internal/cacheUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index f2eb436a..c2ace526 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/cacheUtils.ts @@ -52,9 +52,9 @@ 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. - if (relativeFile === "") { + if (relativeFile === '') { // path.relative returns empty string if workspace and file are equal - paths.push(".") + paths.push('.') } else { paths.push(`${relativeFile}`) } From 67cb82d99bbf83749e4a77395567a4ea3fc0ce89 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 14 Jul 2022 07:50:44 +0000 Subject: [PATCH 4/7] Fix failing resolvePaths testcase --- packages/cache/__tests__/cacheUtils.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index 50486511..1cd641f5 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -1,5 +1,6 @@ import {promises as fs} from 'fs' import * as path from 'path' +import { coerce } from 'semver' import * as cacheUtils from '../src/internal/cacheUtils' test('getArchiveFileSizeInBytes returns file size', () => { @@ -34,6 +35,6 @@ test('assertDefined returns value', () => { }) test('resolvePaths works on current directory', async () => { - const resolvedPath = await cacheUtils.resolvePaths(['.']) - expect(resolvedPath).toStrictEqual(['.']) + const paths = await cacheUtils.resolvePaths(['.']) + expect(paths).toContain('.') }) From ec95a9b1146f8d41234b97fc286b96b83f6c6cea Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 14 Jul 2022 07:50:44 +0000 Subject: [PATCH 5/7] Fix failing resolvePaths testcase --- packages/cache/__tests__/cacheUtils.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index 50486511..1cd641f5 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -1,5 +1,6 @@ import {promises as fs} from 'fs' import * as path from 'path' +import { coerce } from 'semver' import * as cacheUtils from '../src/internal/cacheUtils' test('getArchiveFileSizeInBytes returns file size', () => { @@ -34,6 +35,6 @@ test('assertDefined returns value', () => { }) test('resolvePaths works on current directory', async () => { - const resolvedPath = await cacheUtils.resolvePaths(['.']) - expect(resolvedPath).toStrictEqual(['.']) + const paths = await cacheUtils.resolvePaths(['.']) + expect(paths).toContain('.') }) From 83bca5cb13ae891d569a4bc8b9070bb32dc39362 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 14 Jul 2022 08:18:09 +0000 Subject: [PATCH 6/7] Remove unnecessary import --- packages/cache/__tests__/cacheUtils.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index edf36b1d..f4177918 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -1,6 +1,5 @@ import {promises as fs} from 'fs' import * as path from 'path' -import { coerce } from 'semver' import * as cacheUtils from '../src/internal/cacheUtils' test('getArchiveFileSizeInBytes returns file size', () => { From e98bae803b6520b2a331f66011d812c3af8bf6ae Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Wed, 20 Jul 2022 05:25:47 +0000 Subject: [PATCH 7/7] Change testcase to test against github workspace directory instead of current directory --- packages/cache/__tests__/cacheUtils.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/cache/__tests__/cacheUtils.test.ts b/packages/cache/__tests__/cacheUtils.test.ts index f4177918..25124b46 100644 --- a/packages/cache/__tests__/cacheUtils.test.ts +++ b/packages/cache/__tests__/cacheUtils.test.ts @@ -33,7 +33,8 @@ test('assertDefined returns value', () => { expect(cacheUtils.assertDefined('test', 5)).toBe(5) }) -test('resolvePaths works on current directory', async () => { - const paths = await cacheUtils.resolvePaths(['.']) - expect(paths.length).toBe(1) +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) })