Skip to content

Commit

Permalink
React to feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Aiqiao Yan authored and Aiqiao Yan committed May 19, 2020
1 parent 9a3466a commit fde6221
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
20 changes: 13 additions & 7 deletions packages/cache/src/internal/cacheUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ export async function getCompressionMethod(): Promise<CompressionMethod> {
if (process.platform === 'win32' && !isGnuTarInstalled()) {
// 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)

if (!versionOutput.toLowerCase().includes('zstd command line interface')) {
// zstd is not installed
return CompressionMethod.Gzip
} else if (!version || semver.lt(version, 'v1.3.2')) {
// zstd is installed but using a version earlier than v1.3.2
// v1.3.2 is required to use the `--long` options in zstd
return CompressionMethod.ZstdWithoutLong
} else {
const versionOutput = await getVersion('zstd')
const version = semver.clean(versionOutput)
return !versionOutput.toLowerCase().includes('zstd command line interface')
? CompressionMethod.Gzip
: !version || semver.lt(version, 'v1.3.2')
? CompressionMethod.ZstdOld
: CompressionMethod.Zstd
return CompressionMethod.Zstd
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/cache/src/internal/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export enum CacheFilename {

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

Expand Down
12 changes: 6 additions & 6 deletions packages/cache/src/internal/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ export async function extractTar(
// --d: Decompress.
// --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.
function getProg(): string[] {
function getCompressionProgram(): string[] {
switch (compressionMethod) {
case CompressionMethod.Zstd:
return ['--use-compress-program', 'zstd -d --long=30']
case CompressionMethod.ZstdOld:
case CompressionMethod.ZstdWithoutLong:
return ['--use-compress-program', 'zstd -d']
default:
return ['-z']
}
}
const args = [
...getProg(),
...getCompressionProgram(),
'-xf',
archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P',
Expand Down Expand Up @@ -90,18 +90,18 @@ export async function createTar(
// --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.
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd.
function getProg(): string[] {
function getCompressionProgram(): string[] {
switch (compressionMethod) {
case CompressionMethod.Zstd:
return ['--use-compress-program', 'zstd -T0 --long=30']
case CompressionMethod.ZstdOld:
case CompressionMethod.ZstdWithoutLong:
return ['--use-compress-program', 'zstd -T0']
default:
return ['-z']
}
}
const args = [
...getProg(),
...getCompressionProgram(),
'-cf',
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'),
'-P',
Expand Down

0 comments on commit fde6221

Please sign in to comment.