1
0
Fork 0

Added verbose mode in hashFiles (#1052)

* Added verbose mode in hashFiles

* Code formatting

* Change verboseMode arg to verbose

Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com>

* Using verbose instead of verboseMode as arg

Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com>
pull/1055/head
ruvceskistefan 2022-04-18 20:29:24 +02:00 committed by GitHub
parent 7654d97eb6
commit 8f2bd5d713
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -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)
}

View File

@ -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')
@ -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 ''
}
}