Skip to content

Commit d3801d3

Browse files
authored
Pass in the directory for hashFiles (#1318)
1 parent 5804607 commit d3801d3

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

‎packages/glob/__tests__/hash-files.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('globber', () => {
5151
)
5252
})
5353

54+
const emptyDirectory = ''
5455
it('followSymbolicLinks set to true', async () => {
5556
const root = path.join(getTestTemp(), 'set-to-true')
5657
await fs.mkdir(path.join(root, 'realdir'), {recursive: true})
@@ -60,7 +61,9 @@ describe('globber', () => {
6061
path.join(root, 'symDir')
6162
)
6263
const testPath = path.join(root, `symDir`)
63-
const hash = await hashFiles(testPath, {followSymbolicLinks: true})
64+
const hash = await hashFiles(testPath, emptyDirectory, {
65+
followSymbolicLinks: true
66+
})
6467
expect(hash).toEqual(
6568
'd8a411e8f8643821bed189e627ff57151918aa554c00c10b31c693ab2dded273'
6669
)
@@ -80,7 +83,9 @@ describe('globber', () => {
8083
path.join(root, 'symDir')
8184
)
8285
const testPath = path.join(root, 'symdir')
83-
const hash = await hashFiles(testPath, {followSymbolicLinks: false})
86+
const hash = await hashFiles(testPath, emptyDirectory, {
87+
followSymbolicLinks: false
88+
})
8489
expect(hash).toEqual('')
8590
})
8691

‎packages/glob/src/glob.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ export async function create(
2222
* Computes the sha256 hash of a glob
2323
*
2424
* @param patterns Patterns separated by newlines
25+
* @param currentWorkspace Workspace used when matching files
2526
* @param options Glob options
27+
* @param verbose Enables verbose logging
2628
*/
2729
export async function hashFiles(
2830
patterns: string,
31+
currentWorkspace = '',
2932
options?: HashFileOptions,
3033
verbose: Boolean = false
3134
): Promise<string> {
@@ -34,5 +37,5 @@ export async function hashFiles(
3437
followSymbolicLinks = options.followSymbolicLinks
3538
}
3639
const globber = await create(patterns, {followSymbolicLinks})
37-
return _hashFiles(globber, verbose)
40+
return _hashFiles(globber, currentWorkspace, verbose)
3841
}

‎packages/glob/src/internal-hash-files.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ import {Globber} from './glob'
88

99
export async function hashFiles(
1010
globber: Globber,
11+
currentWorkspace: string,
1112
verbose: Boolean = false
1213
): Promise<string> {
1314
const writeDelegate = verbose ? core.info : core.debug
1415
let hasMatch = false
15-
const githubWorkspace = process.env['GITHUB_WORKSPACE'] ?? process.cwd()
16+
const githubWorkspace = currentWorkspace
17+
? currentWorkspace
18+
: process.env['GITHUB_WORKSPACE'] ?? process.cwd()
1619
const result = crypto.createHash('sha256')
1720
let count = 0
1821
for await (const file of globber.globGenerator()) {

0 commit comments

Comments
 (0)