Skip to content

Commit fde6221

Browse files
Aiqiao YanAiqiao Yan
authored andcommitted
React to feedback
1 parent 9a3466a commit fde6221

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

packages/cache/src/internal/cacheUtils.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,20 @@ export async function getCompressionMethod(): Promise<CompressionMethod> {
8686
if (process.platform === 'win32' && !isGnuTarInstalled()) {
8787
// Disable zstd due to bug https://github.com/actions/cache/issues/301
8888
return CompressionMethod.Gzip
89+
}
90+
91+
const versionOutput = await getVersion('zstd')
92+
const version = semver.clean(versionOutput)
93+
94+
if (!versionOutput.toLowerCase().includes('zstd command line interface')) {
95+
// zstd is not installed
96+
return CompressionMethod.Gzip
97+
} else if (!version || semver.lt(version, 'v1.3.2')) {
98+
// zstd is installed but using a version earlier than v1.3.2
99+
// v1.3.2 is required to use the `--long` options in zstd
100+
return CompressionMethod.ZstdWithoutLong
89101
} else {
90-
const versionOutput = await getVersion('zstd')
91-
const version = semver.clean(versionOutput)
92-
return !versionOutput.toLowerCase().includes('zstd command line interface')
93-
? CompressionMethod.Gzip
94-
: !version || semver.lt(version, 'v1.3.2')
95-
? CompressionMethod.ZstdOld
96-
: CompressionMethod.Zstd
102+
return CompressionMethod.Zstd
97103
}
98104
}
99105

packages/cache/src/internal/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export enum CacheFilename {
55

66
export enum CompressionMethod {
77
Gzip = 'gzip',
8-
ZstdOld = 'zstd-old',
8+
// Long range mode was added to zstd in v1.3.2.
9+
// This enum is for earlier version of zstd that does not have --long support
10+
ZstdWithoutLong = 'zstd-without-long',
911
Zstd = 'zstd'
1012
}
1113

packages/cache/src/internal/tar.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ export async function extractTar(
5151
// --d: Decompress.
5252
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
5353
// Using 30 here because we also support 32-bit self-hosted runners.
54-
function getProg(): string[] {
54+
function getCompressionProgram(): string[] {
5555
switch (compressionMethod) {
5656
case CompressionMethod.Zstd:
5757
return ['--use-compress-program', 'zstd -d --long=30']
58-
case CompressionMethod.ZstdOld:
58+
case CompressionMethod.ZstdWithoutLong:
5959
return ['--use-compress-program', 'zstd -d']
6060
default:
6161
return ['-z']
6262
}
6363
}
6464
const args = [
65-
...getProg(),
65+
...getCompressionProgram(),
6666
'-xf',
6767
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
6868
'-P',
@@ -90,18 +90,18 @@ export async function createTar(
9090
// --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit.
9191
// Using 30 here because we also support 32-bit self-hosted runners.
9292
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
93-
function getProg(): string[] {
93+
function getCompressionProgram(): string[] {
9494
switch (compressionMethod) {
9595
case CompressionMethod.Zstd:
9696
return ['--use-compress-program', 'zstd -T0 --long=30']
97-
case CompressionMethod.ZstdOld:
97+
case CompressionMethod.ZstdWithoutLong:
9898
return ['--use-compress-program', 'zstd -T0']
9999
default:
100100
return ['-z']
101101
}
102102
}
103103
const args = [
104-
...getProg(),
104+
...getCompressionProgram(),
105105
'-cf',
106106
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
107107
'-P',

0 commit comments

Comments
 (0)