@actions/cache
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -81,3 +81,5 @@ "use strict"; | ||
function getCacheVersion(paths, compressionMethod) { | ||
const components = paths.concat(compressionMethod === constants_1.CompressionMethod.Zstd ? [compressionMethod] : []); | ||
const components = paths.concat(!compressionMethod || compressionMethod === constants_1.CompressionMethod.Gzip | ||
? [] | ||
: [compressionMethod]); | ||
// Add salt to cache version to support breaking changes in cache entry | ||
@@ -84,0 +86,0 @@ components.push(versionSalt); |
@@ -10,2 +10,2 @@ /// <reference types="node" /> | ||
export declare function getCacheFileName(compressionMethod: CompressionMethod): string; | ||
export declare function useGnuTar(): Promise<boolean>; | ||
export declare function isGnuTarInstalled(): Promise<boolean>; |
@@ -32,2 +32,3 @@ "use strict"; | ||
const path = __importStar(require("path")); | ||
const semver = __importStar(require("semver")); | ||
const util = __importStar(require("util")); | ||
@@ -127,6 +128,20 @@ const uuid_1 = require("uuid"); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (process.platform === 'win32' && !isGnuTarInstalled()) { | ||
// Disable zstd due to bug https://github.com/actions/cache/issues/301 | ||
return constants_1.CompressionMethod.Gzip; | ||
} | ||
const versionOutput = yield getVersion('zstd'); | ||
return versionOutput.toLowerCase().includes('zstd command line interface') | ||
? constants_1.CompressionMethod.Zstd | ||
: constants_1.CompressionMethod.Gzip; | ||
const version = semver.clean(versionOutput); | ||
if (!versionOutput.toLowerCase().includes('zstd command line interface')) { | ||
// zstd is not installed | ||
return constants_1.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 constants_1.CompressionMethod.ZstdWithoutLong; | ||
} | ||
else { | ||
return constants_1.CompressionMethod.Zstd; | ||
} | ||
}); | ||
@@ -136,8 +151,8 @@ } | ||
function getCacheFileName(compressionMethod) { | ||
return compressionMethod === constants_1.CompressionMethod.Zstd | ||
? constants_1.CacheFilename.Zstd | ||
: constants_1.CacheFilename.Gzip; | ||
return compressionMethod === constants_1.CompressionMethod.Gzip | ||
? constants_1.CacheFilename.Gzip | ||
: constants_1.CacheFilename.Zstd; | ||
} | ||
exports.getCacheFileName = getCacheFileName; | ||
function useGnuTar() { | ||
function isGnuTarInstalled() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -148,3 +163,3 @@ const versionOutput = yield getVersion('tar'); | ||
} | ||
exports.useGnuTar = useGnuTar; | ||
exports.isGnuTarInstalled = isGnuTarInstalled; | ||
//# sourceMappingURL=cacheUtils.js.map |
@@ -7,4 +7,5 @@ export declare enum CacheFilename { | ||
Gzip = "gzip", | ||
ZstdWithoutLong = "zstd-without-long", | ||
Zstd = "zstd" | ||
} | ||
export declare const SocketTimeout = 5000; |
@@ -11,2 +11,5 @@ "use strict"; | ||
CompressionMethod["Gzip"] = "gzip"; | ||
// 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 | ||
CompressionMethod["ZstdWithoutLong"] = "zstd-without-long"; | ||
CompressionMethod["Zstd"] = "zstd"; | ||
@@ -13,0 +16,0 @@ })(CompressionMethod = exports.CompressionMethod || (exports.CompressionMethod = {})); |
@@ -25,12 +25,16 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
function getTarPath(args) { | ||
function getTarPath(args, compressionMethod) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// Explicitly use BSD Tar on Windows | ||
const IS_WINDOWS = process.platform === 'win32'; | ||
if (IS_WINDOWS) { | ||
const systemTar = `${process.env['windir']}\\System32\\tar.exe`; | ||
if (fs_1.existsSync(systemTar)) { | ||
if (compressionMethod !== constants_1.CompressionMethod.Gzip) { | ||
// We only use zstandard compression on windows when gnu tar is installed due to | ||
// a bug with compressing large files with bsdtar + zstd | ||
args.push('--force-local'); | ||
} | ||
else if (fs_1.existsSync(systemTar)) { | ||
return systemTar; | ||
} | ||
else if (yield utils.useGnuTar()) { | ||
else if (yield utils.isGnuTarInstalled()) { | ||
args.push('--force-local'); | ||
@@ -42,6 +46,6 @@ } | ||
} | ||
function execTar(args, cwd) { | ||
function execTar(args, compressionMethod, cwd) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield exec_1.exec(`"${yield getTarPath(args)}"`, args, { cwd }); | ||
yield exec_1.exec(`"${yield getTarPath(args, compressionMethod)}"`, args, { cwd }); | ||
} | ||
@@ -65,6 +69,14 @@ catch (error) { | ||
// Using 30 here because we also support 32-bit self-hosted runners. | ||
function getCompressionProgram() { | ||
switch (compressionMethod) { | ||
case constants_1.CompressionMethod.Zstd: | ||
return ['--use-compress-program', 'zstd -d --long=30']; | ||
case constants_1.CompressionMethod.ZstdWithoutLong: | ||
return ['--use-compress-program', 'zstd -d']; | ||
default: | ||
return ['-z']; | ||
} | ||
} | ||
const args = [ | ||
...(compressionMethod === constants_1.CompressionMethod.Zstd | ||
? ['--use-compress-program', 'zstd -d --long=30'] | ||
: ['-z']), | ||
...getCompressionProgram(), | ||
'-xf', | ||
@@ -76,3 +88,3 @@ archivePath.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), | ||
]; | ||
yield execTar(args); | ||
yield execTar(args, compressionMethod); | ||
}); | ||
@@ -87,10 +99,19 @@ } | ||
fs_1.writeFileSync(path.join(archiveFolder, manifestFilename), sourceDirectories.join('\n')); | ||
const workingDirectory = getWorkingDirectory(); | ||
// -T#: Compress using # working thread. If # is 0, attempt to detect and use the number of physical CPU cores. | ||
// --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 workingDirectory = getWorkingDirectory(); | ||
// Long range mode is added to zstd in v1.3.2 release, so we will not use --long in older version of zstd. | ||
function getCompressionProgram() { | ||
switch (compressionMethod) { | ||
case constants_1.CompressionMethod.Zstd: | ||
return ['--use-compress-program', 'zstd -T0 --long=30']; | ||
case constants_1.CompressionMethod.ZstdWithoutLong: | ||
return ['--use-compress-program', 'zstd -T0']; | ||
default: | ||
return ['-z']; | ||
} | ||
} | ||
const args = [ | ||
...(compressionMethod === constants_1.CompressionMethod.Zstd | ||
? ['--use-compress-program', 'zstd -T0 --long=30'] | ||
: ['-z']), | ||
...getCompressionProgram(), | ||
'-cf', | ||
@@ -104,3 +125,3 @@ cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/'), | ||
]; | ||
yield execTar(args, archiveFolder); | ||
yield execTar(args, compressionMethod, archiveFolder); | ||
}); | ||
@@ -107,0 +128,0 @@ } |
{ | ||
"name": "@actions/cache", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"preview": true, | ||
@@ -44,2 +44,3 @@ "description": "Actions cache lib", | ||
"@actions/io": "^1.0.1", | ||
"semver": "^6.1.0", | ||
"uuid": "^3.3.3" | ||
@@ -49,4 +50,5 @@ }, | ||
"typescript": "^3.8.3", | ||
"@types/semver": "^6.0.0", | ||
"@types/uuid": "^3.4.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59960
819
7
3
+ Addedsemver@^6.1.0
+ Addedsemver@6.3.1(transitive)