Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass in the current workspace as a parameter to hashFiles #1318

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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