Skip to content

Commit

Permalink
pass in the directory for hashFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsudol committed Jan 24, 2023
1 parent 5804607 commit ca5e47a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/glob/__tests__/hash-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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'
)
Expand All @@ -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('')
})

Expand Down
5 changes: 4 additions & 1 deletion packages/glob/src/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
Expand All @@ -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)
}
5 changes: 4 additions & 1 deletion packages/glob/src/internal-hash-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {Globber} from './glob'

export async function hashFiles(
globber: Globber,
currentWorkspace: string,
verbose: Boolean = false
): Promise<string> {
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()) {
Expand Down

0 comments on commit ca5e47a

Please sign in to comment.