mirror of https://github.com/actions/toolkit
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
parent
7654d97eb6
commit
8f2bd5d713
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 ''
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue