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

Added verbose mode in hashFiles #1052

Merged
merged 4 commits into from
Apr 18, 2022
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
5 changes: 3 additions & 2 deletions packages/glob/src/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export async function create(
*/
export async function hashFiles(
patterns: string,
options?: HashFileOptions
options?: HashFileOptions,
verbose: Boolean = false
): Promise<string> {
let followSymbolicLinks = true
if (options && typeof options.followSymbolicLinks === 'boolean') {
followSymbolicLinks = options.followSymbolicLinks
}
const globber = await create(patterns, {followSymbolicLinks})
return _hashFiles(globber)
return _hashFiles(globber, verbose)
}
16 changes: 10 additions & 6 deletions packages/glob/src/internal-hash-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import * as util from 'util'
import * as path from 'path'
import {Globber} from './glob'

export async function hashFiles(globber: Globber): Promise<string> {
export async function hashFiles(
globber: Globber,
verbose: Boolean = false
): Promise<string> {
const writeDelegate = verbose ? core.info : core.debug
let hasMatch = false
const githubWorkspace = process.env['GITHUB_WORKSPACE'] ?? process.cwd()
const result = crypto.createHash('sha256')
let count = 0
for await (const file of globber.globGenerator()) {
core.debug(file)
writeDelegate(file)
if (!file.startsWith(`${githubWorkspace}${path.sep}`)) {
core.debug(`Ignore '${file}' since it is not under GITHUB_WORKSPACE.`)
writeDelegate(`Ignore '${file}' since it is not under GITHUB_WORKSPACE.`)
continue
}
if (fs.statSync(file).isDirectory()) {
core.debug(`Skip directory '${file}'.`)
writeDelegate(`Skip directory '${file}'.`)
continue
}
const hash = crypto.createHash('sha256')
Expand All @@ -33,10 +37,10 @@ export async function hashFiles(globber: Globber): Promise<string> {
result.end()

if (hasMatch) {
core.debug(`Found ${count} files to hash.`)
writeDelegate(`Found ${count} files to hash.`)
return result.digest('hex')
} else {
core.debug(`No matches found for glob`)
writeDelegate(`No matches found for glob`)
return ''
}
}