From 57d20b4db494c25af8d2f3d9323650044610e531 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Wed, 29 Apr 2020 17:33:01 +0200 Subject: [PATCH] tool-cache: make extract functions quiet by default and more verbose if `core.isDebug` is set (#206) * tool-cache: make unzip and 7z extract quiet by default This avoids spamming the log when unzipping large archives. * tool-cache: make tar, unzip and 7z verbose when `core.isDebug` Make the extract function print the list of extracted file if the action is run in debug mode. --- packages/tool-cache/__tests__/tool-cache.test.ts | 2 +- packages/tool-cache/src/tool-cache.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index f3718327..7dc17c67 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -334,7 +334,7 @@ describe('@actions/tool-cache', function() { .readFileSync(path.join(tempDir, 'mock7zr-args.txt')) .toString() .trim() - ).toBe(`x -bb1 -bd -sccUTF-8 ${_7zFile}`) + ).toBe(`x -bb0 -bd -sccUTF-8 ${_7zFile}`) expect(fs.existsSync(path.join(extPath, 'file.txt'))).toBeTruthy() expect( fs.existsSync(path.join(extPath, 'file-with-รง-character.txt')) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index f43f8b51..6fa2d510 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -144,9 +144,10 @@ export async function extract7z( process.chdir(dest) if (_7zPath) { try { + const logLevel = core.isDebug() ? '-bb1' : '-bb0' const args: string[] = [ 'x', // eXtract files with full paths - '-bb1', // -bb[0-3] : set output log level + logLevel, // -bb[0-3] : set output log level '-bd', // disable progress indicator '-sccUTF-8', // set charset for for console input/output file @@ -227,6 +228,10 @@ export async function extractTar( // Initialize args const args = [flags] + if (core.isDebug() && !flags.includes('v')) { + args.push('-v') + } + let destArg = dest let fileArg = file if (IS_WINDOWS && isGnuTar) { @@ -295,7 +300,11 @@ async function extractZipWin(file: string, dest: string): Promise { async function extractZipNix(file: string, dest: string): Promise { const unzipPath = await io.which('unzip', true) - await exec(`"${unzipPath}"`, [file], {cwd: dest}) + const args = [file] + if (!core.isDebug()) { + args.unshift('-q') + } + await exec(`"${unzipPath}"`, args, {cwd: dest}) } /**