1
0
Fork 0

Only allow extractXar on mac

pull/207/head
Frederik Wallner 2019-11-08 13:18:08 +01:00
parent 08fed982a7
commit 3e7cf23e47
No known key found for this signature in database
GPG Key ID: AB5A2354F2F8FDC3
2 changed files with 37 additions and 34 deletions

View File

@ -14,6 +14,7 @@ process.env['RUNNER_TOOL_CACHE'] = cachePath
import * as tc from '../src/tool-cache' import * as tc from '../src/tool-cache'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
const IS_MAC = process.platform === 'darwin'
describe('@actions/tool-cache', function() { describe('@actions/tool-cache', function() {
beforeAll(function() { beforeAll(function() {
@ -198,6 +199,39 @@ describe('@actions/tool-cache', function() {
} }
}) })
} else { } 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 () => { it('extract .tar.gz', async () => {
const tempDir = path.join(tempPath, 'test-install-tar.gz') 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') fs.readFileSync(path.join(toolPath, 'foo', 'hello.txt'), 'utf8')
).toBe('foo/hello: world') ).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 () => { it('installs a zip and finds it', async () => {

View File

@ -18,6 +18,7 @@ export class HTTPError extends Error {
} }
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
const IS_MAC = process.platform === 'darwin'
const userAgent = 'actions/tool-cache' 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) // 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, dest?: string,
flags: string = '-x' flags: string = '-x'
): Promise<string> { ): Promise<string> {
if (!file) { ok(IS_MAC, 'extractXar() not supported on current OS')
throw new Error("parameter 'file' is required") ok(file, 'parameter "file" is required')
}
dest = dest || (await _createExtractFolder(dest)) dest = dest || (await _createExtractFolder(dest))
const xarPath: string = await io.which('xar', true) const xarPath: string = await io.which('xar', true)