mirror of https://github.com/actions/toolkit
fix extractTar on Windows (#264)
parent
81bdf00982
commit
e7cbd693eb
Binary file not shown.
|
@ -268,7 +268,8 @@ describe('@actions/tool-cache', function() {
|
|||
await io.rmRF(tempDir)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
}
|
||||
|
||||
it('extract .tar.gz', async () => {
|
||||
const tempDir = path.join(tempPath, 'test-install-tar.gz')
|
||||
|
||||
|
@ -293,10 +294,7 @@ describe('@actions/tool-cache', function() {
|
|||
fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.readFileSync(
|
||||
path.join(toolPath, 'folder', 'nested-file.txt'),
|
||||
'utf8'
|
||||
)
|
||||
fs.readFileSync(path.join(toolPath, 'folder', 'nested-file.txt'), 'utf8')
|
||||
).toBe('folder/nested-file.txt contents')
|
||||
})
|
||||
|
||||
|
@ -326,10 +324,7 @@ describe('@actions/tool-cache', function() {
|
|||
fs.existsSync(path.join(toolPath, 'folder', 'nested-file.txt'))
|
||||
).toBeTruthy()
|
||||
expect(
|
||||
fs.readFileSync(
|
||||
path.join(toolPath, 'folder', 'nested-file.txt'),
|
||||
'utf8'
|
||||
)
|
||||
fs.readFileSync(path.join(toolPath, 'folder', 'nested-file.txt'), 'utf8')
|
||||
).toBe('folder/nested-file.txt contents')
|
||||
})
|
||||
|
||||
|
@ -350,14 +345,11 @@ describe('@actions/tool-cache', function() {
|
|||
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.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')
|
||||
|
|
|
@ -202,9 +202,41 @@ export async function extractTar(
|
|||
throw new Error("parameter 'file' is required")
|
||||
}
|
||||
|
||||
// Create dest
|
||||
dest = await _createExtractFolder(dest)
|
||||
const tarPath: string = await io.which('tar', true)
|
||||
await exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file])
|
||||
|
||||
// Determine whether 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
|
||||
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) {
|
||||
// Suppress warnings when using GNU tar to extract archives created by BSD tar
|
||||
args.push('--warning=no-unknown-keyword')
|
||||
}
|
||||
|
||||
args.push('-C', destArg, '-f', fileArg)
|
||||
await exec(`tar`, args)
|
||||
|
||||
return dest
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue