From 02e20d7b11d40eb65c61d6d4c70603cd757b6c2c Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 13 Aug 2019 19:22:33 +0700 Subject: [PATCH 1/5] added test for extracting .tar.gz --- .../tool-cache/__tests__/data/test.tar.gz | Bin 0 -> 281 bytes .../tool-cache/__tests__/tool-cache.test.ts | 28 ++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 packages/tool-cache/__tests__/data/test.tar.gz diff --git a/packages/tool-cache/__tests__/data/test.tar.gz b/packages/tool-cache/__tests__/data/test.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..9ba362f6234fad6550b31467c4da52b32f3f149b GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index c1fb9e8f2b..f118640c78 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -197,6 +197,34 @@ describe('@actions/tool-cache', function() { await io.rmRF(tempDir) } }) + } else { + it('extract .tar.gz to specified directory', async () => { + const tempDir = path.join(__dirname, 'test-install-tar.gz') + try { + await io.mkdirP(tempDir) + + // 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) + + // 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') + + 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() + } finally { + await io.rmRF(tempDir) + } + }) } it('installs a zip and finds it', async () => { From 1b4f23f639073f563a00f8b2cde66e1299e43765 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 13 Aug 2019 19:23:51 +0700 Subject: [PATCH 2/5] added ability to extract .tar.xz --- .../tool-cache/__tests__/data/test.tar.xz | Bin 0 -> 312 bytes .../tool-cache/__tests__/tool-cache.test.ts | 28 ++++++++++++++++++ packages/tool-cache/src/tool-cache.ts | 2 +- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 packages/tool-cache/__tests__/data/test.tar.xz diff --git a/packages/tool-cache/__tests__/data/test.tar.xz b/packages/tool-cache/__tests__/data/test.tar.xz new file mode 100644 index 0000000000000000000000000000000000000000..0b964c5553d8ebccc84f530cccf15f765d617379 GIT binary patch literal 312 zcmV-80muIRH+ooF000E$*0e?f03iVu0001VFXf})C;tHWT>uvgyc~T2mB1ZJMw}eQ z0!s&q0bgonO&27s?Hk1_*DR3GzbZ293_*d!FN2X;)&qV9v^4HmoZ*QgY;<%LL&yWB^Vf*iFsMDAL0h9uOPyhg9ONYL(#Ao{g K000001X)@&9F3;{ literal 0 HcmV?d00001 diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index f118640c78..c2ba241594 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -225,6 +225,34 @@ describe('@actions/tool-cache', function() { await io.rmRF(tempDir) } }) + + it('extract .tar.xz to specified directory', async () => { + const tempDir = path.join(__dirname, 'test-install-tar.xz') + try { + await io.mkdirP(tempDir) + + // 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) + + // extract/cache + const extPath: string = await tc.extractTar(_txzFile) + 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, '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() + } finally { + await io.rmRF(tempDir) + } + }) } it('installs a zip and finds it', async () => { diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index a25cdceec1..139a671ac5 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -196,7 +196,7 @@ export async function extractTar(file: string, dest?: string): Promise { dest = dest || (await _createExtractFolder(dest)) const tarPath: string = await io.which('tar', true) - await exec(`"${tarPath}"`, ['xzC', dest, '-f', file]) + await exec(`"${tarPath}"`, ['xC', dest, '-f', file]) return dest } From 71e5e89f7961b25d878892dbd6002a57c248cc15 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 13 Aug 2019 22:51:58 +0700 Subject: [PATCH 3/5] add flags to extract tar --- packages/tool-cache/__tests__/tool-cache.test.ts | 2 +- packages/tool-cache/src/tool-cache.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index c2ba241594..8a6ba80ed6 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -236,7 +236,7 @@ describe('@actions/tool-cache', function() { await io.cp(path.join(__dirname, 'data', 'test.tar.xz'), _txzFile) // extract/cache - const extPath: string = await tc.extractTar(_txzFile) + 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') diff --git a/packages/tool-cache/src/tool-cache.ts b/packages/tool-cache/src/tool-cache.ts index 139a671ac5..e38abee5e9 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -187,16 +187,21 @@ export async function extract7z( * * @param file path to the tar * @param dest destination directory. Optional. + * @param flags flags for the tar. Optional. * @returns path to the destination directory */ -export async function extractTar(file: string, dest?: string): Promise { +export async function extractTar( + file: string, + dest?: string, + flags: string = 'xz' +): Promise { if (!file) { throw new Error("parameter 'file' is required") } dest = dest || (await _createExtractFolder(dest)) const tarPath: string = await io.which('tar', true) - await exec(`"${tarPath}"`, ['xC', dest, '-f', file]) + await exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file]) return dest } From e6239ff7ec4b1b3f586108336b8bcd628ed36876 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 13 Aug 2019 22:58:09 +0700 Subject: [PATCH 4/5] make use of tempPath --- .../tool-cache/__tests__/tool-cache.test.ts | 82 +++++++++---------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index 8a6ba80ed6..821d2b895c 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -199,59 +199,53 @@ describe('@actions/tool-cache', function() { }) } else { it('extract .tar.gz to specified directory', async () => { - const tempDir = path.join(__dirname, 'test-install-tar.gz') - try { - await io.mkdirP(tempDir) + 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() - } finally { - await io.rmRF(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') + + 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() }) it('extract .tar.xz to specified directory', async () => { - const tempDir = path.join(__dirname, 'test-install-tar.xz') - try { - await io.mkdirP(tempDir) + 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, '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() - } finally { - await io.rmRF(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') + + 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() }) } From a53bdddd53c38a1208f4444574b511eedfd984b6 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Tue, 13 Aug 2019 23:42:31 +0700 Subject: [PATCH 5/5] check file contents and make different content for tar file --- .../tool-cache/__tests__/data/test.tar.xz | Bin 312 -> 10240 bytes .../tool-cache/__tests__/tool-cache.test.ts | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/tool-cache/__tests__/data/test.tar.xz b/packages/tool-cache/__tests__/data/test.tar.xz index 0b964c5553d8ebccc84f530cccf15f765d617379..5993e1fd9d694a620c13f2c95272eadf4369f9ca 100644 GIT binary patch literal 10240 zcmeIz+X{j}5C-7A?kV;OboMX`y^T^)AS`&G9>3kp5W(tZBI@6pMOPj9W`E6cB|a#Q zl3B&clx*g6T1rD1$JTSR+I?SsKFbdw z2=9T^;5Ym4%93LLtur3||HRfA`+wXwP00F7FH$n~zwmyZ`{_H7mWb>l|M&iT!=yBc zyv^dFf1dx8{#*CA`W)J3x6r}ij|*gZUA1D#AMsMepXQ(Z^#8ZaMg0Cda`FF<{L62? zI)sgU6;yx#1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz00bZa0cn9N;>lkc literal 312 zcmV-80muIRH+ooF000E$*0e?f03iVu0001VFXf})C;tHWT>uvgyc~T2mB1ZJMw}eQ z0!s&q0bgonO&27s?Hk1_*DR3GzbZ293_*d!FN2X;)&qV9v^4HmoZ*QgY;<%LL&yWB^Vf*iFsMDAL0h9uOPyhg9ONYL(#Ao{g K000001X)@&9F3;{ diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index 821d2b895c..32f8979197 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -198,7 +198,7 @@ describe('@actions/tool-cache', function() { } }) } else { - it('extract .tar.gz to specified directory', async () => { + it('extract .tar.gz', async () => { const tempDir = path.join(tempPath, 'test-install-tar.gz') await io.mkdirP(tempDir) @@ -221,9 +221,15 @@ describe('@actions/tool-cache', function() { 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') }) - it('extract .tar.xz to specified directory', async () => { + it('extract .tar.xz', async () => { const tempDir = path.join(tempPath, 'test-install-tar.xz') await io.mkdirP(tempDir) @@ -239,13 +245,13 @@ describe('@actions/tool-cache', function() { 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, 'bar.txt'))).toBeTruthy() expect( - fs.existsSync(path.join(toolPath, 'file-with-ç-character.txt')) + fs.existsSync(path.join(toolPath, 'foo', 'hello.txt')) ).toBeTruthy() expect( - fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt')) - ).toBeTruthy() + fs.readFileSync(path.join(toolPath, 'foo', 'hello.txt'), 'utf8') + ).toBe('foo/hello: world') }) }