mirror of https://github.com/actions/toolkit
Address some comments and correct compression commands
parent
f9dfb05bd2
commit
54eb9b8055
|
@ -149,6 +149,8 @@ test('zstd create tar', async () => {
|
|||
`"${tarPath}"`,
|
||||
[
|
||||
'--posix',
|
||||
'-cf',
|
||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||
'--exclude',
|
||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||
'-P',
|
||||
|
@ -157,9 +159,7 @@ test('zstd create tar', async () => {
|
|||
'--files-from',
|
||||
'manifest.txt',
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30',
|
||||
'-cf',
|
||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd
|
||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||
]
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
||||
|
@ -187,6 +187,8 @@ test('gzip create tar', async () => {
|
|||
`"${tarPath}"`,
|
||||
[
|
||||
'--posix',
|
||||
'-cf',
|
||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
||||
'--exclude',
|
||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
||||
'-P',
|
||||
|
@ -194,9 +196,7 @@ test('gzip create tar', async () => {
|
|||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||
'--files-from',
|
||||
'manifest.txt',
|
||||
'-z',
|
||||
'-cf',
|
||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip
|
||||
'-z'
|
||||
]
|
||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
||||
|
|
|
@ -94,11 +94,6 @@ async function getVersion(app: string): Promise<string> {
|
|||
|
||||
// Use zstandard if possible to maximize cache performance
|
||||
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
||||
// if (process.platform === 'win32' && !(await getGnuTarPathOnWindows())) {
|
||||
// // Disable zstd due to bug https://github.com/actions/cache/issues/301
|
||||
// return CompressionMethod.Gzip
|
||||
// }
|
||||
|
||||
const versionOutput = await getVersion('zstd')
|
||||
const version = semver.clean(versionOutput)
|
||||
|
||||
|
|
|
@ -62,10 +62,10 @@ async function getCompressionProgram(
|
|||
// --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 tarPath = await getTarPath([])
|
||||
const BSD_TAR_ZSTD = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
||||
const BSD_TAR_WINDOWS = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
||||
switch (compressionMethod) {
|
||||
case CompressionMethod.Zstd:
|
||||
if (BSD_TAR_ZSTD) {
|
||||
if (BSD_TAR_WINDOWS) {
|
||||
return ['-a'] // auto-detect compression
|
||||
}
|
||||
return [
|
||||
|
@ -73,7 +73,7 @@ async function getCompressionProgram(
|
|||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||
]
|
||||
case CompressionMethod.ZstdWithoutLong:
|
||||
if (BSD_TAR_ZSTD) {
|
||||
if (BSD_TAR_WINDOWS) {
|
||||
return ['a'] // auto-detect compression
|
||||
}
|
||||
return ['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']
|
||||
|
@ -121,6 +121,9 @@ export async function createTar(
|
|||
// Write source directories to manifest.txt to avoid command length limits
|
||||
const manifestFilename = 'manifest.txt'
|
||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||
const tarFile = 'cache.tar'
|
||||
const tarPath = await getTarPath([])
|
||||
const BSD_TAR_WINDOWS = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
||||
writeFileSync(
|
||||
path.join(archiveFolder, manifestFilename),
|
||||
sourceDirectories.join('\n')
|
||||
|
@ -133,42 +136,44 @@ export async function createTar(
|
|||
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
|
||||
async function getCompressionProgram(): Promise<string[]> {
|
||||
const tarPath = await getTarPath([])
|
||||
const BSD_TAR_ZSTD = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
||||
switch (compressionMethod) {
|
||||
case CompressionMethod.Zstd:
|
||||
if (BSD_TAR_ZSTD) {
|
||||
return ['-O', '|', 'zstd -T0 --long=30 -o']
|
||||
if (BSD_TAR_WINDOWS) {
|
||||
return ['&&', 'zstd -T0 --long=30 -o']
|
||||
}
|
||||
return [
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30',
|
||||
'-cf'
|
||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||
]
|
||||
case CompressionMethod.ZstdWithoutLong:
|
||||
if (BSD_TAR_ZSTD) {
|
||||
return ['-O', '|', 'zstd -T0 -o']
|
||||
if (BSD_TAR_WINDOWS) {
|
||||
return ['&&', 'zstd -T0 -o']
|
||||
}
|
||||
return [
|
||||
'--use-compress-program',
|
||||
IS_WINDOWS ? 'zstd -T0' : 'zstdmt',
|
||||
'-cf'
|
||||
]
|
||||
return ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
|
||||
default:
|
||||
return ['-z', '-cf']
|
||||
return ['-z']
|
||||
}
|
||||
}
|
||||
const args = [
|
||||
'--posix',
|
||||
'-cf',
|
||||
BSD_TAR_WINDOWS
|
||||
? tarFile
|
||||
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'--exclude',
|
||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
BSD_TAR_WINDOWS
|
||||
? tarFile
|
||||
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'-P',
|
||||
'-C',
|
||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||
'--files-from',
|
||||
manifestFilename,
|
||||
...(await getCompressionProgram()),
|
||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
||||
]
|
||||
...(await getCompressionProgram())
|
||||
].concat(
|
||||
BSD_TAR_WINDOWS
|
||||
? [cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/')]
|
||||
: []
|
||||
)
|
||||
await execTar(args, archiveFolder)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue