@actions/tool-cache
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -9,5 +9,5 @@ /** | ||
constructor(maxAttempts: number, minSeconds: number, maxSeconds: number); | ||
execute<T>(action: () => Promise<T>): Promise<T>; | ||
execute<T>(action: () => Promise<T>, isRetryable?: (e: Error) => boolean): Promise<T>; | ||
private getSleepAmount; | ||
private sleep; | ||
} |
@@ -35,3 +35,3 @@ "use strict"; | ||
} | ||
execute(action) { | ||
execute(action, isRetryable) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -45,2 +45,5 @@ let attempt = 1; | ||
catch (err) { | ||
if (isRetryable && !isRetryable(err)) { | ||
throw err; | ||
} | ||
core.info(err.message); | ||
@@ -47,0 +50,0 @@ } |
@@ -45,27 +45,2 @@ "use strict"; | ||
const userAgent = 'actions/tool-cache'; | ||
// On load grab temp directory and cache directory and remove them from env (currently don't want to expose this) | ||
let tempDirectory = process.env['RUNNER_TEMP'] || ''; | ||
let cacheRoot = process.env['RUNNER_TOOL_CACHE'] || ''; | ||
// If directories not found, place them in common temp locations | ||
if (!tempDirectory || !cacheRoot) { | ||
let baseLocation; | ||
if (IS_WINDOWS) { | ||
// On windows use the USERPROFILE env variable | ||
baseLocation = process.env['USERPROFILE'] || 'C:\\'; | ||
} | ||
else { | ||
if (process.platform === 'darwin') { | ||
baseLocation = '/Users'; | ||
} | ||
else { | ||
baseLocation = '/home'; | ||
} | ||
} | ||
if (!tempDirectory) { | ||
tempDirectory = path.join(baseLocation, 'actions', 'temp'); | ||
} | ||
if (!cacheRoot) { | ||
cacheRoot = path.join(baseLocation, 'actions', 'cache'); | ||
} | ||
} | ||
/** | ||
@@ -80,3 +55,3 @@ * Download a tool from an url and stream it into a file | ||
return __awaiter(this, void 0, void 0, function* () { | ||
dest = dest || path.join(tempDirectory, v4_1.default()); | ||
dest = dest || path.join(_getTempDirectory(), v4_1.default()); | ||
yield io.mkdirP(path.dirname(dest)); | ||
@@ -86,6 +61,19 @@ core.debug(`Downloading ${url}`); | ||
const maxAttempts = 3; | ||
const minSeconds = getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 10); | ||
const maxSeconds = getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 20); | ||
const minSeconds = _getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 10); | ||
const maxSeconds = _getGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 20); | ||
const retryHelper = new retry_helper_1.RetryHelper(maxAttempts, minSeconds, maxSeconds); | ||
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { return yield downloadToolAttempt(url, dest || ''); })); | ||
return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { | ||
return yield downloadToolAttempt(url, dest || ''); | ||
}), (err) => { | ||
if (err instanceof HTTPError && err.httpStatusCode) { | ||
// Don't retry anything less than 500, except 408 Request Timeout and 429 Too Many Requests | ||
if (err.httpStatusCode < 500 && | ||
err.httpStatusCode !== 408 && | ||
err.httpStatusCode !== 429) { | ||
return false; | ||
} | ||
} | ||
// Otherwise retry | ||
return true; | ||
}); | ||
}); | ||
@@ -111,3 +99,3 @@ } | ||
const pipeline = util.promisify(stream.pipeline); | ||
const responseMessageFactory = getGlobal('TEST_DOWNLOAD_TOOL_RESPONSE_MESSAGE_FACTORY', () => response.message); | ||
const responseMessageFactory = _getGlobal('TEST_DOWNLOAD_TOOL_RESPONSE_MESSAGE_FACTORY', () => response.message); | ||
const readStream = responseMessageFactory(); | ||
@@ -395,3 +383,3 @@ let succeeded = false; | ||
versionSpec = semver.clean(versionSpec) || ''; | ||
const cachePath = path.join(cacheRoot, toolName, versionSpec, arch); | ||
const cachePath = path.join(_getCacheDirectory(), toolName, versionSpec, arch); | ||
core.debug(`checking cache: ${cachePath}`); | ||
@@ -418,3 +406,3 @@ if (fs.existsSync(cachePath) && fs.existsSync(`${cachePath}.complete`)) { | ||
arch = arch || os.arch(); | ||
const toolPath = path.join(cacheRoot, toolName); | ||
const toolPath = path.join(_getCacheDirectory(), toolName); | ||
if (fs.existsSync(toolPath)) { | ||
@@ -438,3 +426,3 @@ const children = fs.readdirSync(toolPath); | ||
// create a temp dir | ||
dest = path.join(tempDirectory, v4_1.default()); | ||
dest = path.join(_getTempDirectory(), v4_1.default()); | ||
} | ||
@@ -447,3 +435,3 @@ yield io.mkdirP(dest); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const folderPath = path.join(cacheRoot, tool, semver.clean(version) || version, arch || ''); | ||
const folderPath = path.join(_getCacheDirectory(), tool, semver.clean(version) || version, arch || ''); | ||
core.debug(`destination ${folderPath}`); | ||
@@ -458,3 +446,3 @@ const markerPath = `${folderPath}.complete`; | ||
function _completeToolPath(tool, version, arch) { | ||
const folderPath = path.join(cacheRoot, tool, semver.clean(version) || version, arch || ''); | ||
const folderPath = path.join(_getCacheDirectory(), tool, semver.clean(version) || version, arch || ''); | ||
const markerPath = `${folderPath}.complete`; | ||
@@ -497,5 +485,21 @@ fs.writeFileSync(markerPath, ''); | ||
/** | ||
* Gets RUNNER_TOOL_CACHE | ||
*/ | ||
function _getCacheDirectory() { | ||
const cacheDirectory = process.env['RUNNER_TOOL_CACHE'] || ''; | ||
assert_1.ok(cacheDirectory, 'Expected RUNNER_TOOL_CACHE to be defined'); | ||
return cacheDirectory; | ||
} | ||
/** | ||
* Gets RUNNER_TEMP | ||
*/ | ||
function _getTempDirectory() { | ||
const tempDirectory = process.env['RUNNER_TEMP'] || ''; | ||
assert_1.ok(tempDirectory, 'Expected RUNNER_TEMP to be defined'); | ||
return tempDirectory; | ||
} | ||
/** | ||
* Gets a global variable | ||
*/ | ||
function getGlobal(key, defaultValue) { | ||
function _getGlobal(key, defaultValue) { | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -502,0 +506,0 @@ const value = global[key]; |
{ | ||
"name": "@actions/tool-cache", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Actions tool-cache lib", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
89184
660
3