mirror of https://github.com/actions/toolkit
Address review comments
parent
7181b913f5
commit
55484166d8
|
@ -12,6 +12,7 @@ jest.mock('@actions/io')
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
const IS_MAC = process.platform === 'darwin'
|
const IS_MAC = process.platform === 'darwin'
|
||||||
|
const windowsGnuTar = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||||
|
|
||||||
const defaultTarPath = process.platform === 'darwin' ? 'gtar' : 'tar'
|
const defaultTarPath = process.platform === 'darwin' ? 'gtar' : 'tar'
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ test('zstd extract tar', async () => {
|
||||||
: 'cache.tar'
|
: 'cache.tar'
|
||||||
const workspace = process.env['GITHUB_WORKSPACE']
|
const workspace = process.env['GITHUB_WORKSPACE']
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
|
|
||||||
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
@ -82,7 +83,7 @@ test('gzip extract tar', async () => {
|
||||||
|
|
||||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
@ -144,7 +145,7 @@ test('zstd create tar', async () => {
|
||||||
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd)
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Zstd)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
@ -184,7 +185,7 @@ test('gzip create tar', async () => {
|
||||||
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip)
|
await tar.createTar(archiveFolder, sourceDirectories, CompressionMethod.Gzip)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
|
@ -221,7 +222,7 @@ test('zstd list tar', async () => {
|
||||||
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
@ -249,7 +250,7 @@ test('zstdWithoutLong list tar', async () => {
|
||||||
await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong)
|
await tar.listTar(archivePath, CompressionMethod.ZstdWithoutLong)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
@ -276,7 +277,7 @@ test('gzip list tar', async () => {
|
||||||
await tar.listTar(archivePath, CompressionMethod.Gzip)
|
await tar.listTar(archivePath, CompressionMethod.Gzip)
|
||||||
|
|
||||||
const tarPath = IS_WINDOWS
|
const tarPath = IS_WINDOWS
|
||||||
? `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
? windowsGnuTar
|
||||||
: defaultTarPath
|
: defaultTarPath
|
||||||
expect(execMock).toHaveBeenCalledTimes(1)
|
expect(execMock).toHaveBeenCalledTimes(1)
|
||||||
expect(execMock).toHaveBeenCalledWith(
|
expect(execMock).toHaveBeenCalledWith(
|
||||||
|
|
|
@ -11,14 +11,15 @@ async function getTarPath(
|
||||||
args: string[],
|
args: string[],
|
||||||
compressionMethod: CompressionMethod
|
compressionMethod: CompressionMethod
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
var tarPath = await io.which('tar', true)
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32': {
|
case 'win32': {
|
||||||
const systemTar = `${process.env['windir']}\\System32\\tar.exe`
|
|
||||||
const gnuTar = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
const gnuTar = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||||
|
const systemTar = `${process.env['windir']}\\System32\\tar.exe`
|
||||||
if (existsSync(gnuTar)) {
|
if (existsSync(gnuTar)) {
|
||||||
// Use GNUtar as default on windows
|
// Use GNUtar as default on windows
|
||||||
args.push('--force-local')
|
args.push('--force-local')
|
||||||
return gnuTar
|
tarPath = gnuTar
|
||||||
} else if (
|
} else if (
|
||||||
compressionMethod !== CompressionMethod.Gzip ||
|
compressionMethod !== CompressionMethod.Gzip ||
|
||||||
(await utils.isGnuTarInstalled())
|
(await utils.isGnuTarInstalled())
|
||||||
|
@ -27,7 +28,7 @@ async function getTarPath(
|
||||||
// a bug with compressing large files with bsdtar + zstd
|
// a bug with compressing large files with bsdtar + zstd
|
||||||
args.push('--force-local')
|
args.push('--force-local')
|
||||||
} else if (existsSync(systemTar)) {
|
} else if (existsSync(systemTar)) {
|
||||||
return systemTar
|
tarPath = systemTar
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -36,14 +37,14 @@ async function getTarPath(
|
||||||
if (gnuTar) {
|
if (gnuTar) {
|
||||||
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
|
// fix permission denied errors when extracting BSD tar archive with GNU tar - https://github.com/actions/cache/issues/527
|
||||||
args.push('--delay-directory-restore')
|
args.push('--delay-directory-restore')
|
||||||
return gnuTar
|
tarPath = gnuTar
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return await io.which('tar', true)
|
return tarPath
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execTar(
|
async function execTar(
|
||||||
|
|
Loading…
Reference in New Issue