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}"`,
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
'--posix',
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||||
'--exclude',
|
'--exclude',
|
||||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd,
|
||||||
'-P',
|
'-P',
|
||||||
|
@ -157,9 +159,7 @@ test('zstd create tar', async () => {
|
||||||
'--files-from',
|
'--files-from',
|
||||||
'manifest.txt',
|
'manifest.txt',
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30',
|
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||||
'-cf',
|
|
||||||
IS_WINDOWS ? CacheFilename.Zstd.replace(/\\/g, '/') : CacheFilename.Zstd
|
|
||||||
]
|
]
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
||||||
|
@ -187,6 +187,8 @@ test('gzip create tar', async () => {
|
||||||
`"${tarPath}"`,
|
`"${tarPath}"`,
|
||||||
[
|
[
|
||||||
'--posix',
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
||||||
'--exclude',
|
'--exclude',
|
||||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip,
|
||||||
'-P',
|
'-P',
|
||||||
|
@ -194,9 +196,7 @@ test('gzip create tar', async () => {
|
||||||
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
IS_WINDOWS ? workspace?.replace(/\\/g, '/') : workspace,
|
||||||
'--files-from',
|
'--files-from',
|
||||||
'manifest.txt',
|
'manifest.txt',
|
||||||
'-z',
|
'-z'
|
||||||
'-cf',
|
|
||||||
IS_WINDOWS ? CacheFilename.Gzip.replace(/\\/g, '/') : CacheFilename.Gzip
|
|
||||||
]
|
]
|
||||||
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
.concat(IS_WINDOWS ? ['--force-local'] : [])
|
||||||
.concat(IS_MAC ? ['--delay-directory-restore'] : []),
|
.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
|
// Use zstandard if possible to maximize cache performance
|
||||||
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
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 versionOutput = await getVersion('zstd')
|
||||||
const version = semver.clean(versionOutput)
|
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.
|
// --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.
|
// Using 30 here because we also support 32-bit self-hosted runners.
|
||||||
const tarPath = await getTarPath([])
|
const tarPath = await getTarPath([])
|
||||||
const BSD_TAR_ZSTD = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
const BSD_TAR_WINDOWS = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case CompressionMethod.Zstd:
|
case CompressionMethod.Zstd:
|
||||||
if (BSD_TAR_ZSTD) {
|
if (BSD_TAR_WINDOWS) {
|
||||||
return ['-a'] // auto-detect compression
|
return ['-a'] // auto-detect compression
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
|
@ -73,7 +73,7 @@ async function getCompressionProgram(
|
||||||
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
IS_WINDOWS ? 'zstd -d --long=30' : 'unzstd --long=30'
|
||||||
]
|
]
|
||||||
case CompressionMethod.ZstdWithoutLong:
|
case CompressionMethod.ZstdWithoutLong:
|
||||||
if (BSD_TAR_ZSTD) {
|
if (BSD_TAR_WINDOWS) {
|
||||||
return ['a'] // auto-detect compression
|
return ['a'] // auto-detect compression
|
||||||
}
|
}
|
||||||
return ['--use-compress-program', IS_WINDOWS ? 'zstd -d' : 'unzstd']
|
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
|
// Write source directories to manifest.txt to avoid command length limits
|
||||||
const manifestFilename = 'manifest.txt'
|
const manifestFilename = 'manifest.txt'
|
||||||
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
const cacheFileName = utils.getCacheFileName(compressionMethod)
|
||||||
|
const tarFile = 'cache.tar'
|
||||||
|
const tarPath = await getTarPath([])
|
||||||
|
const BSD_TAR_WINDOWS = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
||||||
writeFileSync(
|
writeFileSync(
|
||||||
path.join(archiveFolder, manifestFilename),
|
path.join(archiveFolder, manifestFilename),
|
||||||
sourceDirectories.join('\n')
|
sourceDirectories.join('\n')
|
||||||
|
@ -133,42 +136,44 @@ export async function createTar(
|
||||||
// Using 30 here because we also support 32-bit self-hosted runners.
|
// 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.
|
// 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[]> {
|
async function getCompressionProgram(): Promise<string[]> {
|
||||||
const tarPath = await getTarPath([])
|
|
||||||
const BSD_TAR_ZSTD = IS_WINDOWS && tarPath === SystemTarPathOnWindows
|
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case CompressionMethod.Zstd:
|
case CompressionMethod.Zstd:
|
||||||
if (BSD_TAR_ZSTD) {
|
if (BSD_TAR_WINDOWS) {
|
||||||
return ['-O', '|', 'zstd -T0 --long=30 -o']
|
return ['&&', 'zstd -T0 --long=30 -o']
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
'--use-compress-program',
|
'--use-compress-program',
|
||||||
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30',
|
IS_WINDOWS ? 'zstd -T0 --long=30' : 'zstdmt --long=30'
|
||||||
'-cf'
|
|
||||||
]
|
]
|
||||||
case CompressionMethod.ZstdWithoutLong:
|
case CompressionMethod.ZstdWithoutLong:
|
||||||
if (BSD_TAR_ZSTD) {
|
if (BSD_TAR_WINDOWS) {
|
||||||
return ['-O', '|', 'zstd -T0 -o']
|
return ['&&', 'zstd -T0 -o']
|
||||||
}
|
}
|
||||||
return [
|
return ['--use-compress-program', IS_WINDOWS ? 'zstd -T0' : 'zstdmt']
|
||||||
'--use-compress-program',
|
|
||||||
IS_WINDOWS ? 'zstd -T0' : 'zstdmt',
|
|
||||||
'-cf'
|
|
||||||
]
|
|
||||||
default:
|
default:
|
||||||
return ['-z', '-cf']
|
return ['-z']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const args = [
|
const args = [
|
||||||
'--posix',
|
'--posix',
|
||||||
|
'-cf',
|
||||||
|
BSD_TAR_WINDOWS
|
||||||
|
? tarFile
|
||||||
|
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'--exclude',
|
'--exclude',
|
||||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
BSD_TAR_WINDOWS
|
||||||
|
? tarFile
|
||||||
|
: cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'-P',
|
'-P',
|
||||||
'-C',
|
'-C',
|
||||||
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
workingDirectory.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
|
||||||
'--files-from',
|
'--files-from',
|
||||||
manifestFilename,
|
manifestFilename,
|
||||||
...(await getCompressionProgram()),
|
...(await getCompressionProgram())
|
||||||
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
|
].concat(
|
||||||
]
|
BSD_TAR_WINDOWS
|
||||||
|
? [cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/')]
|
||||||
|
: []
|
||||||
|
)
|
||||||
await execTar(args, archiveFolder)
|
await execTar(args, archiveFolder)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue