Skip to content

Commit

Permalink
use cwd instead
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsudol authored Jan 24, 2023
1 parent 7f8e14c commit cbd4f66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
13 changes: 6 additions & 7 deletions packages/glob/__tests__/hash-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {hashFiles} from '../src/glob'
import {promises as fs} from 'fs'

const IS_WINDOWS = process.platform === 'win32'
const currentWorkspace = process.cwd()

/**
* These test focus on the ability of globber to find files
Expand All @@ -19,15 +18,15 @@ describe('globber', () => {
const root = path.join(getTestTemp(), 'basic-hashfiles')
await fs.mkdir(path.join(root), {recursive: true})
await fs.writeFile(path.join(root, 'test.txt'), 'test file content')
const hash = await hashFiles(`${root}/*`, currentWorkspace)
const hash = await hashFiles(`${root}/*`)
expect(hash).toEqual(
'd8a411e8f8643821bed189e627ff57151918aa554c00c10b31c693ab2dded273'
)
})

it('basic hashfiles no match should return empty string', async () => {
const root = path.join(getTestTemp(), 'empty-hashfiles')
const hash = await hashFiles(`${root}/*`, currentWorkspace)
const hash = await hashFiles(`${root}/*`)
expect(hash).toEqual('')
})

Expand All @@ -46,7 +45,7 @@ describe('globber', () => {
path.join(root, 'symDir')
)
const testPath = path.join(root, `symDir`)
const hash = await hashFiles(testPath, currentWorkspace)
const hash = await hashFiles(testPath)
expect(hash).toEqual(
'd8a411e8f8643821bed189e627ff57151918aa554c00c10b31c693ab2dded273'
)
Expand All @@ -61,7 +60,7 @@ describe('globber', () => {
path.join(root, 'symDir')
)
const testPath = path.join(root, `symDir`)
const hash = await hashFiles(testPath, currentWorkspace, {
const hash = await hashFiles(testPath, {
followSymbolicLinks: true
})
expect(hash).toEqual(
Expand All @@ -83,7 +82,7 @@ describe('globber', () => {
path.join(root, 'symDir')
)
const testPath = path.join(root, 'symdir')
const hash = await hashFiles(testPath, currentWorkspace, {
const hash = await hashFiles(testPath, {
followSymbolicLinks: false
})
expect(hash).toEqual('')
Expand All @@ -107,7 +106,7 @@ describe('globber', () => {
'test file content'
)
const testPath = `${path.join(root, 'dir1')}\n${path.join(root, 'dir2')}`
const hash = await hashFiles(testPath, currentWorkspace)
const hash = await hashFiles(testPath)
expect(hash).toEqual(
'4e911ea5824830b6a3ec096c7833d5af8381c189ffaa825c3503a5333a73eadc'
)
Expand Down
4 changes: 1 addition & 3 deletions packages/glob/src/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ 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: string,
options?: HashFileOptions,
verbose: Boolean = false
): Promise<string> {
Expand All @@ -37,5 +35,5 @@ export async function hashFiles(
followSymbolicLinks = options.followSymbolicLinks
}
const globber = await create(patterns, {followSymbolicLinks})
return _hashFiles(globber, currentWorkspace, verbose)
return _hashFiles(globber, verbose)
}
5 changes: 1 addition & 4 deletions packages/glob/src/internal-hash-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ 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 = currentWorkspace
? currentWorkspace
: process.env['GITHUB_WORKSPACE'] ?? process.cwd()
const githubWorkspace = process.cwd()
const result = crypto.createHash('sha256')
let count = 0
for await (const file of globber.globGenerator()) {
Expand Down

0 comments on commit cbd4f66

Please sign in to comment.