mirror of https://github.com/actions/toolkit
Address review comments
parent
0fd856d0a0
commit
34f0143be2
|
@ -5,7 +5,9 @@ import {
|
|||
CacheFilename,
|
||||
CompressionMethod,
|
||||
GnuTarPathOnWindows,
|
||||
SystemTarPathOnWindows
|
||||
ManifestFilename,
|
||||
SystemTarPathOnWindows,
|
||||
TarFilename
|
||||
} from '../src/internal/constants'
|
||||
import * as tar from '../src/internal/tar'
|
||||
import * as utils from '../src/internal/cacheUtils'
|
||||
|
@ -57,8 +59,8 @@ test('zstd extract tar', async () => {
|
|||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
[
|
||||
`"${tarPath}"`,
|
||||
'-xf',
|
||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||
'-P',
|
||||
|
@ -70,7 +72,8 @@ test('zstd extract tar', async () => {
|
|||
.concat([
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||
]),
|
||||
])
|
||||
.join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
})
|
||||
|
@ -86,25 +89,24 @@ test('zstd extract tar with windows BSDtar', async () => {
|
|||
const archivePath = `${process.env['windir']}\\fakepath\\cache.tar`
|
||||
const workspace = process.env['GITHUB_WORKSPACE']
|
||||
const tarPath = SystemTarPathOnWindows
|
||||
const tarFilename = 'cache.tar'
|
||||
|
||||
await tar.extractTar(archivePath, CompressionMethod.Zstd)
|
||||
|
||||
expect(mkdirMock).toHaveBeenCalledWith(workspace)
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
'zstd -d --long=30 -o',
|
||||
[
|
||||
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'zstd -d --long=30 -o',
|
||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'&&',
|
||||
`${tarPath}`,
|
||||
'-xf',
|
||||
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'-P',
|
||||
'-C',
|
||||
workspace?.replace(/\\/g, '/')
|
||||
],
|
||||
].join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
}
|
||||
|
@ -124,8 +126,8 @@ test('gzip extract tar', async () => {
|
|||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
[
|
||||
`"${tarPath}"`,
|
||||
'-xf',
|
||||
IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath,
|
||||
'-P',
|
||||
|
@ -134,7 +136,8 @@ test('gzip extract tar', async () => {
|
|||
]
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||
.concat(['-z']),
|
||||
.concat(['-z'])
|
||||
.join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
})
|
||||
|
@ -153,8 +156,8 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
|||
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"tar"`,
|
||||
[
|
||||
`"tar"`,
|
||||
'-xf',
|
||||
archivePath.replace(/\\/g, '/'),
|
||||
'-P',
|
||||
|
@ -162,7 +165,7 @@ test('gzip extract GNU tar on windows with GNUtar in path', async () => {
|
|||
workspace?.replace(/\\/g, '/'),
|
||||
'--force-local',
|
||||
'-z'
|
||||
],
|
||||
].join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
}
|
||||
|
@ -183,8 +186,8 @@ test('zstd create tar', async () => {
|
|||
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
[
|
||||
`"${tarPath}"`,
|
||||
'--posix',
|
||||
'-cf',
|
||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||
|
@ -194,14 +197,15 @@ test('zstd create tar', async () => {
|
|||
'-C',
|
||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||
'--files-from',
|
||||
'manifest.txt'
|
||||
ManifestFilename
|
||||
]
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||
.concat([
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||
]),
|
||||
])
|
||||
.join(' '),
|
||||
{
|
||||
cwd: archiveFolder
|
||||
}
|
||||
|
@ -218,7 +222,6 @@ test('zstd create tar with windows BSDtar', async () => {
|
|||
const archiveFolder = getTempDir()
|
||||
const workspace = process.env['GITHUB_WORKSPACE']
|
||||
const sourceDirectories = ['~/.npm/cache', `${workspace}/dist`]
|
||||
const tarFilename = 'cache.tar'
|
||||
|
||||
await fs.promises.mkdir(archiveFolder, {recursive: true})
|
||||
|
||||
|
@ -232,23 +235,23 @@ test('zstd create tar with windows BSDtar', async () => {
|
|||
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
[
|
||||
`"${tarPath}"`,
|
||||
'--posix',
|
||||
'-cf',
|
||||
tarFilename.replace(/\\/g, '/'),
|
||||
TarFilename.replace(/\\/g, '/'),
|
||||
'--exclude',
|
||||
tarFilename.replace(/\\/g, '/'),
|
||||
TarFilename.replace(/\\/g, '/'),
|
||||
'-P',
|
||||
'-C',
|
||||
workspace?.replace(/\\/g, '/'),
|
||||
'--files-from',
|
||||
'manifest.txt',
|
||||
ManifestFilename,
|
||||
'&&',
|
||||
'zstd -T0 --long=30 -o',
|
||||
CacheFilename.Zstd.replace(/\\/g, '/'),
|
||||
tarFilename.replace(/\\/g, '/')
|
||||
],
|
||||
TarFilename.replace(/\\/g, '/')
|
||||
].join(' '),
|
||||
{
|
||||
cwd: archiveFolder
|
||||
}
|
||||
|
@ -282,11 +285,12 @@ test('gzip create tar', async () => {
|
|||
'-C',
|
||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||
'--files-from',
|
||||
'manifest.txt'
|
||||
ManifestFilename
|
||||
]
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||
.concat(['-z']),
|
||||
.concat(['-z'])
|
||||
.join(' '),
|
||||
{
|
||||
cwd: archiveFolder
|
||||
}
|
||||
|
@ -305,14 +309,14 @@ test('zstd list tar', async () => {
|
|||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||
[`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||
.concat([
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||
]),
|
||||
])
|
||||
.join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
})
|
||||
|
@ -327,20 +331,19 @@ test('zstd list tar with windows BSDtar', async () => {
|
|||
|
||||
await tar.listTar(archivePath, CompressionMethod.Zstd)
|
||||
|
||||
const tarFilename = 'cache.tar'
|
||||
const tarPath = SystemTarPathOnWindows
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
'zstd -d --long=30 -o',
|
||||
[
|
||||
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'zstd -d --long=30 -o',
|
||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'&&',
|
||||
`${tarPath}`,
|
||||
'-tf',
|
||||
tarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
TarFilename.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'-P'
|
||||
],
|
||||
].join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
}
|
||||
|
@ -358,11 +361,11 @@ test('zstdWithoutLong list tar', async () => {
|
|||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||
[`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||
.concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']),
|
||||
.concat(['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd'])
|
||||
.join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
})
|
||||
|
@ -378,11 +381,11 @@ test('gzip list tar', async () => {
|
|||
const tarPath = IS_WINDOWS ? GnuTarPathOnWindows : defaultTarPath
|
||||
expect(execMock).toHaveBeenCalledTimes(1)
|
||||
expect(execMock).toHaveBeenCalledWith(
|
||||
`"${tarPath}"`,
|
||||
['-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||
[`"${tarPath}"`, '-tf', IS_WINDOWS ? archivePath.replace(/\\/g, '/') : archivePath, '-P']
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : [])
|
||||
.concat(['-z']),
|
||||
.concat(['-z'])
|
||||
.join(' '),
|
||||
{cwd: undefined}
|
||||
)
|
||||
})
|
||||
|
|
|
@ -30,4 +30,9 @@ export const SocketTimeout = 5000
|
|||
// The default path of GNUtar on hosted Windows runners
|
||||
export const GnuTarPathOnWindows = `${process.env['PROGRAMFILES']}\\Git\\usr\\bin\\tar.exe`
|
||||
|
||||
// The default path of BSDtar on hosted Windows runners
|
||||
export const SystemTarPathOnWindows = `${process.env['SYSTEMDRIVE']}\\Windows\\System32\\tar.exe`
|
||||
|
||||
export const TarFilename = 'cache.tar'
|
||||
|
||||
export const ManifestFilename = 'manifest.txt'
|
|
@ -7,7 +7,9 @@ import {ArchiveTool} from './contracts'
|
|||
import {
|
||||
CompressionMethod,
|
||||
SystemTarPathOnWindows,
|
||||
ArchiveToolType
|
||||
ArchiveToolType,
|
||||
TarFilename,
|
||||
ManifestFilename
|
||||
} from './constants'
|
||||
|
||||
const IS_WINDOWS = process.platform === 'win32'
|
||||
|
@ -55,7 +57,6 @@ async function getTarArgs(
|
|||
archivePath = ''
|
||||
): Promise<string[]> {
|
||||
const args = [tarPath.path]
|
||||
const manifestFilename = 'manifest.txt'
|
||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||
const tarFile = 'cache.tar'
|
||||
const workingDirectory = getWorkingDirectory()
|
||||
|
@ -81,7 +82,7 @@ async function getTarArgs(
|
|||
'-C',
|
||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'--files-from',
|
||||
manifestFilename
|
||||
ManifestFilename
|
||||
)
|
||||
break
|
||||
case 'extract':
|
||||
|
@ -162,7 +163,6 @@ async function getDecompressionProgram(
|
|||
// unzstd is equivalent to 'zstd -d'
|
||||
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
|
||||
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||
const tarFile = 'cache.tar'
|
||||
const BSD_TAR_ZSTD =
|
||||
tarPath.type === ArchiveToolType.BSD &&
|
||||
compressionMethod !== CompressionMethod.Gzip &&
|
||||
|
@ -172,7 +172,7 @@ async function getDecompressionProgram(
|
|||
return BSD_TAR_ZSTD
|
||||
? [
|
||||
'zstd -d --long=30 -o',
|
||||
tarFile,
|
||||
TarFilename,
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'&&'
|
||||
]
|
||||
|
@ -184,7 +184,7 @@ async function getDecompressionProgram(
|
|||
return BSD_TAR_ZSTD
|
||||
? [
|
||||
'zstd -d -o',
|
||||
tarFile,
|
||||
TarFilename,
|
||||
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'&&'
|
||||
]
|
||||
|
@ -204,7 +204,6 @@ async function getCompressionProgram(
|
|||
compressionMethod: CompressionMethod
|
||||
): Promise<string[]> {
|
||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||
const tarFile = 'cache.tar'
|
||||
const BSD_TAR_ZSTD =
|
||||
tarPath.type === ArchiveToolType.BSD &&
|
||||
compressionMethod !== CompressionMethod.Gzip &&
|
||||
|
@ -216,7 +215,7 @@ async function getCompressionProgram(
|
|||
'&&',
|
||||
'zstd -T0 --long=30 -o',
|
||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
tarFile
|
||||
TarFilename
|
||||
]
|
||||
: [
|
||||
'--use-compress-program',
|
||||
|
@ -228,7 +227,7 @@ async function getCompressionProgram(
|
|||
'&&',
|
||||
'zstd -T0 -o',
|
||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
tarFile
|
||||
TarFilename
|
||||
]
|
||||
: ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue