From 8424027dbb73dc1e5300e713c67ee7a3e3a8caff Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 14:44:08 -0500 Subject: [PATCH 01/11] fix extractTar on Windows --- packages/tool-cache/src/tool-cache.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index 972eea0b0c..f2a67596f8 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -203,8 +203,25 @@ export async function extractTar( } dest = await _createExtractFolder(dest) - const tarPath: string = await io.which('tar', true) - await exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file]) + let destArg = dest + const args = [flags] + if (IS_WINDOWS) { + let versionOutput = '' + exec('tar --version', [], { + ignoreReturnCode: true, + listeners: { + stdout: (data: Buffer) => (versionOutput += data.toString()), + stderr: (data: Buffer) => (versionOutput += data.toString()) + } + }) + + if (versionOutput.toUpperCase().includes('GNU TAR')) { + args.push('--force-local') + destArg = dest.replace(/\\/g, '/') + } + } + args.push('-C', destArg, '-f', file) + await exec(`tar`, args) return dest } From 6c95edaae7cc0f636aaf580f795b7f8eeb21d71c Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 14:46:26 -0500 Subject: [PATCH 02/11] . --- .../tool-cache/__tests__/tool-cache.test.ts | 144 +++++++++--------- 1 file changed, 68 insertions(+), 76 deletions(-) diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index be176f1bee..543280a545 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -268,96 +268,88 @@ describe('@actions/tool-cache', function() { await io.rmRF(tempDir) } }) - } else { - it('extract .tar.gz', async () => { - const tempDir = path.join(tempPath, 'test-install-tar.gz') + } - await io.mkdirP(tempDir) + it('extract .tar.gz', async () => { + const tempDir = path.join(tempPath, 'test-install-tar.gz') - // copy the .tar.gz file to the test dir - const _tgzFile: string = path.join(tempDir, 'test.tar.gz') - await io.cp(path.join(__dirname, 'data', 'test.tar.gz'), _tgzFile) + await io.mkdirP(tempDir) - // extract/cache - const extPath: string = await tc.extractTar(_tgzFile) - await tc.cacheDir(extPath, 'my-tgz-contents', '1.1.0') - const toolPath: string = tc.find('my-tgz-contents', '1.1.0') + // copy the .tar.gz file to the test dir + const _tgzFile: string = path.join(tempDir, 'test.tar.gz') + await io.cp(path.join(__dirname, 'data', 'test.tar.gz'), _tgzFile) - expect(fs.existsSync(toolPath)).toBeTruthy() - expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy() - expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy() - expect( - fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt')) - ).toBeTruthy() - expect( - fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt')) - ).toBeTruthy() - expect( - fs.readFileSync( - path.join(toolPath, 'folder', 'nested-file.txt'), - 'utf8' - ) - ).toBe('folder/nested-file.txt contents') - }) + // extract/cache + const extPath: string = await tc.extractTar(_tgzFile) + await tc.cacheDir(extPath, 'my-tgz-contents', '1.1.0') + const toolPath: string = tc.find('my-tgz-contents', '1.1.0') - it('extract .tar.gz to a directory that does not exist', async () => { - const tempDir = path.join(tempPath, 'test-install-tar.gz') - const destDir = path.join(tempDir, 'not-exist') + expect(fs.existsSync(toolPath)).toBeTruthy() + expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy() + expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy() + expect( + fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt')) + ).toBeTruthy() + expect( + fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt')) + ).toBeTruthy() + expect( + fs.readFileSync(path.join(toolPath, 'folder', 'nested-file.txt'), 'utf8') + ).toBe('folder/nested-file.txt contents') + }) - await io.mkdirP(tempDir) + it('extract .tar.gz to a directory that does not exist', async () => { + const tempDir = path.join(tempPath, 'test-install-tar.gz') + const destDir = path.join(tempDir, 'not-exist') - // copy the .tar.gz file to the test dir - const _tgzFile: string = path.join(tempDir, 'test.tar.gz') - await io.cp(path.join(__dirname, 'data', 'test.tar.gz'), _tgzFile) + await io.mkdirP(tempDir) - // extract/cache - const extPath: string = await tc.extractTar(_tgzFile, destDir) - await tc.cacheDir(extPath, 'my-tgz-contents', '1.1.0') - const toolPath: string = tc.find('my-tgz-contents', '1.1.0') + // copy the .tar.gz file to the test dir + const _tgzFile: string = path.join(tempDir, 'test.tar.gz') + await io.cp(path.join(__dirname, 'data', 'test.tar.gz'), _tgzFile) - expect(extPath).toContain('not-exist') - expect(fs.existsSync(toolPath)).toBeTruthy() - expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy() - expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy() - expect( - fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt')) - ).toBeTruthy() - expect( - fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt')) - ).toBeTruthy() - expect( - fs.readFileSync( - path.join(toolPath, 'folder', 'nested-file.txt'), - 'utf8' - ) - ).toBe('folder/nested-file.txt contents') - }) + // extract/cache + const extPath: string = await tc.extractTar(_tgzFile, destDir) + await tc.cacheDir(extPath, 'my-tgz-contents', '1.1.0') + const toolPath: string = tc.find('my-tgz-contents', '1.1.0') - it('extract .tar.xz', async () => { - const tempDir = path.join(tempPath, 'test-install-tar.xz') + expect(extPath).toContain('not-exist') + expect(fs.existsSync(toolPath)).toBeTruthy() + expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy() + expect(fs.existsSync(path.join(toolPath, 'file.txt'))).toBeTruthy() + expect( + fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt')) + ).toBeTruthy() + expect( + fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt')) + ).toBeTruthy() + expect( + fs.readFileSync(path.join(toolPath, 'folder', 'nested-file.txt'), 'utf8') + ).toBe('folder/nested-file.txt contents') + }) - await io.mkdirP(tempDir) + it('extract .tar.xz', async () => { + const tempDir = path.join(tempPath, 'test-install-tar.xz') - // copy the .tar.gz file to the test dir - const _txzFile: string = path.join(tempDir, 'test.tar.xz') - await io.cp(path.join(__dirname, 'data', 'test.tar.xz'), _txzFile) + await io.mkdirP(tempDir) - // extract/cache - const extPath: string = await tc.extractTar(_txzFile, undefined, 'x') - await tc.cacheDir(extPath, 'my-txz-contents', '1.1.0') - const toolPath: string = tc.find('my-txz-contents', '1.1.0') + // copy the .tar.gz file to the test dir + const _txzFile: string = path.join(tempDir, 'test.tar.xz') + await io.cp(path.join(__dirname, 'data', 'test.tar.xz'), _txzFile) - expect(fs.existsSync(toolPath)).toBeTruthy() - expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy() - expect(fs.existsSync(path.join(toolPath, 'bar.txt'))).toBeTruthy() - expect( - fs.existsSync(path.join(toolPath, 'foo', 'hello.txt')) - ).toBeTruthy() - expect( - fs.readFileSync(path.join(toolPath, 'foo', 'hello.txt'), 'utf8') - ).toBe('foo/hello: world') - }) - } + // extract/cache + const extPath: string = await tc.extractTar(_txzFile, undefined, 'x') + await tc.cacheDir(extPath, 'my-txz-contents', '1.1.0') + const toolPath: string = tc.find('my-txz-contents', '1.1.0') + + expect(fs.existsSync(toolPath)).toBeTruthy() + expect(fs.existsSync(`${toolPath}.complete`)).toBeTruthy() + expect(fs.existsSync(path.join(toolPath, 'bar.txt'))).toBeTruthy() + expect(fs.existsSync(path.join(toolPath, 'foo', 'hello.txt'))).toBeTruthy() + expect( + fs.readFileSync(path.join(toolPath, 'foo', 'hello.txt'), 'utf8') + ).toBe('foo/hello: world') + }) it('installs a zip and finds it', async () => { const tempDir = path.join(__dirname, 'test-install-zip') From e37250946ad81eb114b1298b865abed0374f76e9 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 14:58:01 -0500 Subject: [PATCH 03/11] . --- packages/tool-cache/src/tool-cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index f2a67596f8..ea34e3fd24 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -207,7 +207,7 @@ export async function extractTar( const args = [flags] if (IS_WINDOWS) { let versionOutput = '' - exec('tar --version', [], { + await exec('tar --version', [], { ignoreReturnCode: true, listeners: { stdout: (data: Buffer) => (versionOutput += data.toString()), From 0071524b71c1328b5489ba1284af91ccd1f98f83 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 15:02:16 -0500 Subject: [PATCH 04/11] . --- .github/workflows/unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index feaa75fb6f..ce3795f014 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,6 +20,7 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: + - run: echo ::add-path::C:\Windows\System32 # temp edit - name: Checkout uses: actions/checkout@v1 From 443db3861775d949a977028d518b95f841b2e73a Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 16:12:28 -0500 Subject: [PATCH 05/11] . --- packages/tool-cache/__tests__/data/test.tar.gz | Bin 281 -> 729 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/packages/tool-cache/__tests__/data/test.tar.gz b/packages/tool-cache/__tests__/data/test.tar.gz index 9ba362f6234fad6550b31467c4da52b32f3f149b..ea74cafe2211a115dd274b6f7a325a773fb458f5 100644 GIT binary patch literal 729 zcmV;~0w(<*iwFRHMEP9+1MQgKZksR^#(SNouzEQO>i@t+F1EE(Cv8&IZkl$9h?Aft zP=VWIeW5+b9%ipGlcuGKlCVmFX6pC5aj=mwKKcBe!$mwlH}Sv}Czoe$Pd}gec5aXM z45d^{Nvbx`YSB`Df4zVUMwn26=8`id31w2V;E2rky^u}Zlr}EhQcRI1yY6$h4Tn3% z?_Y&Hw*Lu&lBrFnrqA5|yIrR`^tGfy=uk&JH=67mjaNoP<%c0xOh;VzxFA>W&p&?p z?hnjupXne7IHx_%AG*^l@4G-pBBVVQKJ;djH2cwKy_epYS3-NLuW8i3`%kRupKGa) z2yJgkHLqO%mnJDpYz?_7(`-bJ-DVKaTlRV0=q|l>%`h*fu_f2>yt+syhFDWt-`(tw z?#P>ClH0K>GUj|x+{5i$Fn`+(v1^oXIxL5s2tIufCf2EgI{c~CAU$wfb zC9hon%lOwekeSk&fw#}Ru(|%@_4gmQcac0im*EE0s4c7Fpgyg9Ix?pqsQ4InB000000000000000000000000000000aESZ` L%t0o~08jt`&o_5+ literal 281 zcmV+!0p|W6iwFP!000001MSw)ZG$ir1yGOT1t5O5AD)L2M?s1}!j9UFI!K1;8nxS` z^rHzsF>Ta)gv19(Sh_s>)*DfrN*r^(lVkdRzYt_t+jNn#LJ={skX(LgLL5VECn-fZ zK8>M|Rt=D<)7z2r~g(aeE8Eo=f7;=i}SDN`8PW6|AyFM{?~9xUv}dV{Sd=%F9=qZ z=6^hF{Zz6Be)PZ8@ox9O^ZdJf{%gk?{cjCl`42uszpYA~2Fv}=&HXR`Cu#R5i~WBM fKc|n=000000000000000;8DE;vO4YL04M+eM2v~K From 4b8b9fda8275c990d17f42c5c9fcdac15964e112 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 16:17:27 -0500 Subject: [PATCH 06/11] . --- .github/workflows/unit-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ce3795f014..feaa75fb6f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,7 +20,6 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: - - run: echo ::add-path::C:\Windows\System32 # temp edit - name: Checkout uses: actions/checkout@v1 From 46de6c6cbdeb4bb16abc5338d0681c7754c99839 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 16:34:58 -0500 Subject: [PATCH 07/11] Revert "." This reverts commit 4b8b9fda8275c990d17f42c5c9fcdac15964e112. --- .github/workflows/unit-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index feaa75fb6f..ce3795f014 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,6 +20,7 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: + - run: echo ::add-path::C:\Windows\System32 # temp edit - name: Checkout uses: actions/checkout@v1 From 9eee88d359eda1d3608b0ac9b6d0f5b3be596a17 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 17:52:53 -0500 Subject: [PATCH 08/11] . --- packages/tool-cache/src/tool-cache.ts | 38 +++++++++++++++++---------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index ea34e3fd24..9dd47e6261 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -202,24 +202,34 @@ export async function extractTar( throw new Error("parameter 'file' is required") } + // Create dest dest = await _createExtractFolder(dest) - let destArg = dest - const args = [flags] - if (IS_WINDOWS) { - let versionOutput = '' - await exec('tar --version', [], { - ignoreReturnCode: true, - listeners: { - stdout: (data: Buffer) => (versionOutput += data.toString()), - stderr: (data: Buffer) => (versionOutput += data.toString()) - } - }) - if (versionOutput.toUpperCase().includes('GNU TAR')) { - args.push('--force-local') - destArg = dest.replace(/\\/g, '/') + // Determine whther GNU tar + let versionOutput = '' + await exec('tar --version', [], { + ignoreReturnCode: true, + listeners: { + stdout: (data: Buffer) => (versionOutput += data.toString()), + stderr: (data: Buffer) => (versionOutput += data.toString()) } + }) + const isGnuTar = versionOutput.toUpperCase().includes('GNU TAR') + + // Initialize args + const args = [flags] + + let destArg = dest + if (IS_WINDOWS && isGnuTar) { + args.push('--force-local') + destArg = dest.replace(/\\/g, '/') } + + if (isGnuTar) { + // Suppress warnings when using GNU tar to extract archives created by BSD tar + args.push('--warning=no-unknown-keyword') + } + args.push('-C', destArg, '-f', file) await exec(`tar`, args) From 6af6cc0d96ce611e7c5852b61e4a771cfd533ae6 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 17:59:20 -0500 Subject: [PATCH 09/11] Revert "Revert "."" This reverts commit 46de6c6cbdeb4bb16abc5338d0681c7754c99839. --- .github/workflows/unit-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ce3795f014..feaa75fb6f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -20,7 +20,6 @@ jobs: runs-on: ${{ matrix.runs-on }} steps: - - run: echo ::add-path::C:\Windows\System32 # temp edit - name: Checkout uses: actions/checkout@v1 From 67b788f0f6430f08c00be96605c6a3eee009a177 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Tue, 17 Dec 2019 20:20:38 -0500 Subject: [PATCH 10/11] Update packages/tool-cache/src/tool-cache.ts Co-Authored-By: Josh Gross --- packages/tool-cache/src/tool-cache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index 9dd47e6261..5af2cd962f 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -205,7 +205,7 @@ export async function extractTar( // Create dest dest = await _createExtractFolder(dest) - // Determine whther GNU tar + // Determine whether GNU tar let versionOutput = '' await exec('tar --version', [], { ignoreReturnCode: true, From 45be6ade7ad86655c1071b8d8da76ccfd98e9e7b Mon Sep 17 00:00:00 2001 From: eric sciple Date: Thu, 19 Dec 2019 10:35:45 -0500 Subject: [PATCH 11/11] . --- packages/tool-cache/src/tool-cache.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index 5af2cd962f..87265ff9ea 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -220,9 +220,14 @@ export async function extractTar( const args = [flags] let destArg = dest + let fileArg = file if (IS_WINDOWS && isGnuTar) { args.push('--force-local') destArg = dest.replace(/\\/g, '/') + + // Technically only the dest needs to have `/` but for aesthetic consistency + // convert slashes in the file arg too. + fileArg = file.replace(/\\/g, '/') } if (isGnuTar) { @@ -230,7 +235,7 @@ export async function extractTar( args.push('--warning=no-unknown-keyword') } - args.push('-C', destArg, '-f', file) + args.push('-C', destArg, '-f', fileArg) await exec(`tar`, args) return dest