From d3801d332cc66efead8e9fe94b5a0627b2d9ebf3 Mon Sep 17 00:00:00 2001 From: John Sudol <24583161+johnsudol@users.noreply.github.com> Date: Tue, 24 Jan 2023 14:12:47 -0500 Subject: [PATCH] Pass in the directory for hashFiles (#1318) --- packages/glob/__tests__/hash-files.test.ts | 9 +++++++-- packages/glob/src/glob.ts | 5 ++++- packages/glob/src/internal-hash-files.ts | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/glob/__tests__/hash-files.test.ts b/packages/glob/__tests__/hash-files.test.ts index cb912ca0..51ed3ee6 100644 --- a/packages/glob/__tests__/hash-files.test.ts +++ b/packages/glob/__tests__/hash-files.test.ts @@ -51,6 +51,7 @@ describe('globber', () => { ) }) + const emptyDirectory = '' it('followSymbolicLinks set to true', async () => { const root = path.join(getTestTemp(), 'set-to-true') await fs.mkdir(path.join(root, 'realdir'), {recursive: true}) @@ -60,7 +61,9 @@ describe('globber', () => { path.join(root, 'symDir') ) const testPath = path.join(root, `symDir`) - const hash = await hashFiles(testPath, {followSymbolicLinks: true}) + const hash = await hashFiles(testPath, emptyDirectory, { + followSymbolicLinks: true + }) expect(hash).toEqual( 'd8a411e8f8643821bed189e627ff57151918aa554c00c10b31c693ab2dded273' ) @@ -80,7 +83,9 @@ describe('globber', () => { path.join(root, 'symDir') ) const testPath = path.join(root, 'symdir') - const hash = await hashFiles(testPath, {followSymbolicLinks: false}) + const hash = await hashFiles(testPath, emptyDirectory, { + followSymbolicLinks: false + }) expect(hash).toEqual('') }) diff --git a/packages/glob/src/glob.ts b/packages/glob/src/glob.ts index acbb6d2c..3c68de8d 100644 --- a/packages/glob/src/glob.ts +++ b/packages/glob/src/glob.ts @@ -22,10 +22,13 @@ export async function create( * Computes the sha256 hash of a glob * * @param patterns Patterns separated by newlines + * @param currentWorkspace Workspace used when matching files * @param options Glob options + * @param verbose Enables verbose logging */ export async function hashFiles( patterns: string, + currentWorkspace = '', options?: HashFileOptions, verbose: Boolean = false ): Promise { @@ -34,5 +37,5 @@ export async function hashFiles( followSymbolicLinks = options.followSymbolicLinks } const globber = await create(patterns, {followSymbolicLinks}) - return _hashFiles(globber, verbose) + return _hashFiles(globber, currentWorkspace, verbose) } diff --git a/packages/glob/src/internal-hash-files.ts b/packages/glob/src/internal-hash-files.ts index ef18d9f5..d968db5e 100644 --- a/packages/glob/src/internal-hash-files.ts +++ b/packages/glob/src/internal-hash-files.ts @@ -8,11 +8,14 @@ import {Globber} from './glob' export async function hashFiles( globber: Globber, + currentWorkspace: string, verbose: Boolean = false ): Promise { const writeDelegate = verbose ? core.info : core.debug let hasMatch = false - const githubWorkspace = process.env['GITHUB_WORKSPACE'] ?? process.cwd() + const githubWorkspace = currentWorkspace + ? currentWorkspace + : process.env['GITHUB_WORKSPACE'] ?? process.cwd() const result = crypto.createHash('sha256') let count = 0 for await (const file of globber.globGenerator()) {