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( export async function hashFiles(
patterns: string, patterns: string,
options?: HashFileOptions options?: HashFileOptions,
verbose: Boolean = false
): Promise<string> { ): Promise<string> {
let followSymbolicLinks = true let followSymbolicLinks = true
if (options && typeof options.followSymbolicLinks === 'boolean') { if (options && typeof options.followSymbolicLinks === 'boolean') {
followSymbolicLinks = options.followSymbolicLinks followSymbolicLinks = options.followSymbolicLinks
} }
const globber = await create(patterns, {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 * as path from 'path'
import {Globber} from './glob' 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 let hasMatch = false
const githubWorkspace = process.env['GITHUB_WORKSPACE'] ?? process.cwd() const githubWorkspace = process.env['GITHUB_WORKSPACE'] ?? process.cwd()
const result = crypto.createHash('sha256') const result = crypto.createHash('sha256')
let count = 0 let count = 0
for await (const file of globber.globGenerator()) { for await (const file of globber.globGenerator()) {
core.debug(file) writeDelegate(file)
if (!file.startsWith(`${githubWorkspace}${path.sep}`)) { 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 continue
} }
if (fs.statSync(file).isDirectory()) { if (fs.statSync(file).isDirectory()) {
core.debug(`Skip directory '${file}'.`) writeDelegate(`Skip directory '${file}'.`)
continue continue
} }
const hash = crypto.createHash('sha256') const hash = crypto.createHash('sha256')
@ -33,10 +37,10 @@ export async function hashFiles(globber: Globber): Promise<string> {
result.end() result.end()
if (hasMatch) { if (hasMatch) {
core.debug(`Found ${count} files to hash.`) writeDelegate(`Found ${count} files to hash.`)
return result.digest('hex') return result.digest('hex')
} else { } else {
core.debug(`No matches found for glob`) writeDelegate(`No matches found for glob`)
return '' return ''
} }
} }