From 3e7cf23e47ff0eee0a8dd95b34444e55251ee4bd Mon Sep 17 00:00:00 2001 From: Frederik Wallner Date: Fri, 8 Nov 2019 13:18:08 +0100 Subject: [PATCH] Only allow extractXar on mac --- .../tool-cache/__tests__/tool-cache.test.ts | 65 ++++++++++--------- packages/tool-cache/src/tool-cache.ts | 6 +- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts index 4ff04425..579aa8c0 100644 --- a/packages/tool-cache/__tests__/tool-cache.test.ts +++ b/packages/tool-cache/__tests__/tool-cache.test.ts @@ -14,6 +14,7 @@ process.env['RUNNER_TOOL_CACHE'] = cachePath import * as tc from '../src/tool-cache' const IS_WINDOWS = process.platform === 'win32' +const IS_MAC = process.platform === 'darwin' describe('@actions/tool-cache', function() { beforeAll(function() { @@ -198,6 +199,39 @@ describe('@actions/tool-cache', function() { } }) } else { + if (IS_MAC) { + it('extract .xar', async () => { + const tempDir = path.join(tempPath, 'test-install.xar') + + await io.mkdirP(tempDir) + + // copy the .xar file to the test dir + const _xarFile: string = path.join(tempDir, 'test.xar') + await io.cp(path.join(__dirname, 'data', 'test.xar'), _xarFile) + + // extract/cache + const extPath: string = await tc.extractXar(_xarFile, undefined, '-x') + await tc.cacheDir(extPath, 'my-xar-contents', '1.1.0') + const toolPath: string = tc.find('my-xar-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() + expect( + fs.readFileSync( + path.join(toolPath, 'folder', 'nested-file.txt'), + 'utf8' + ) + ).toBe('folder/nested-file.txt contents') + }) + } + it('extract .tar.gz', async () => { const tempDir = path.join(tempPath, 'test-install-tar.gz') @@ -253,37 +287,6 @@ describe('@actions/tool-cache', function() { fs.readFileSync(path.join(toolPath, 'foo', 'hello.txt'), 'utf8') ).toBe('foo/hello: world') }) - - it('extract .xar', async () => { - const tempDir = path.join(tempPath, 'test-install.xar') - - await io.mkdirP(tempDir) - - // copy the .xar file to the test dir - const _xarFile: string = path.join(tempDir, 'test.xar') - await io.cp(path.join(__dirname, 'data', 'test.xar'), _xarFile) - - // extract/cache - const extPath: string = await tc.extractXar(_xarFile, undefined, '-x') - await tc.cacheDir(extPath, 'my-xar-contents', '1.1.0') - const toolPath: string = tc.find('my-xar-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() - expect( - fs.readFileSync( - path.join(toolPath, 'folder', 'nested-file.txt'), - 'utf8' - ) - ).toBe('folder/nested-file.txt contents') - }) } 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 6d802767..d59bebbf 100644 --- a/packages/tool-cache/src/tool-cache.ts +++ b/packages/tool-cache/src/tool-cache.ts @@ -18,6 +18,7 @@ export class HTTPError extends Error { } const IS_WINDOWS = process.platform === 'win32' +const IS_MAC = process.platform === 'darwin' const userAgent = 'actions/tool-cache' // On load grab temp directory and cache directory and remove them from env (currently don't want to expose this) @@ -219,9 +220,8 @@ export async function extractXar( dest?: string, flags: string = '-x' ): Promise { - if (!file) { - throw new Error("parameter 'file' is required") - } + ok(IS_MAC, 'extractXar() not supported on current OS') + ok(file, 'parameter "file" is required') dest = dest || (await _createExtractFolder(dest)) const xarPath: string = await io.which('xar', true)