mirror of
https://github.com/actions/cache.git
synced 2025-06-29 05:40:51 +02:00
Compare commits
1 Commits
add-retrie
...
timeout-en
Author | SHA1 | Date | |
---|---|---|---|
18e62e1fe0 |
@ -1,4 +1,4 @@
|
|||||||
import { getCacheVersion, retry } from "../src/cacheHttpClient";
|
import { getCacheVersion } from "../src/cacheHttpClient";
|
||||||
import { CompressionMethod, Inputs } from "../src/constants";
|
import { CompressionMethod, Inputs } from "../src/constants";
|
||||||
import * as testUtils from "../src/utils/testUtils";
|
import * as testUtils from "../src/utils/testUtils";
|
||||||
|
|
||||||
@ -37,141 +37,3 @@ test("getCacheVersion with gzip compression does not change vesion", async () =>
|
|||||||
test("getCacheVersion with no input throws", async () => {
|
test("getCacheVersion with no input throws", async () => {
|
||||||
expect(() => getCacheVersion()).toThrow();
|
expect(() => getCacheVersion()).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
interface TestResponse {
|
|
||||||
statusCode: number;
|
|
||||||
result: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleResponse(
|
|
||||||
response: TestResponse | undefined
|
|
||||||
): Promise<TestResponse> {
|
|
||||||
if (!response) {
|
|
||||||
fail("Retry method called too many times");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.statusCode === 999) {
|
|
||||||
throw Error("Test Error");
|
|
||||||
} else {
|
|
||||||
return Promise.resolve(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testRetryExpectingResult(
|
|
||||||
responses: Array<TestResponse>,
|
|
||||||
expectedResult: string | null
|
|
||||||
): Promise<void> {
|
|
||||||
responses = responses.reverse(); // Reverse responses since we pop from end
|
|
||||||
|
|
||||||
const actualResult = await retry(
|
|
||||||
"test",
|
|
||||||
() => handleResponse(responses.pop()),
|
|
||||||
(response: TestResponse) => response.statusCode
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(actualResult.result).toEqual(expectedResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function testRetryExpectingError(
|
|
||||||
responses: Array<TestResponse>
|
|
||||||
): Promise<void> {
|
|
||||||
responses = responses.reverse(); // Reverse responses since we pop from end
|
|
||||||
|
|
||||||
expect(
|
|
||||||
retry(
|
|
||||||
"test",
|
|
||||||
() => handleResponse(responses.pop()),
|
|
||||||
(response: TestResponse) => response.statusCode
|
|
||||||
)
|
|
||||||
).rejects.toBeInstanceOf(Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
test("retry works on successful response", async () => {
|
|
||||||
await testRetryExpectingResult(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
statusCode: 200,
|
|
||||||
result: "Ok"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Ok"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("retry works after retryable status code", async () => {
|
|
||||||
await testRetryExpectingResult(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
statusCode: 503,
|
|
||||||
result: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
statusCode: 200,
|
|
||||||
result: "Ok"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Ok"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("retry fails after exhausting retries", async () => {
|
|
||||||
await testRetryExpectingError([
|
|
||||||
{
|
|
||||||
statusCode: 503,
|
|
||||||
result: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
statusCode: 503,
|
|
||||||
result: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
statusCode: 200,
|
|
||||||
result: "Ok"
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("retry fails after non-retryable status code", async () => {
|
|
||||||
await testRetryExpectingError([
|
|
||||||
{
|
|
||||||
statusCode: 500,
|
|
||||||
result: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
statusCode: 200,
|
|
||||||
result: "Ok"
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("retry works after error", async () => {
|
|
||||||
await testRetryExpectingResult(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
statusCode: 999,
|
|
||||||
result: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
statusCode: 200,
|
|
||||||
result: "Ok"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Ok"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("retry returns after client error", async () => {
|
|
||||||
await testRetryExpectingResult(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
statusCode: 400,
|
|
||||||
result: null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
statusCode: 200,
|
|
||||||
result: "Ok"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
null
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
219
dist/restore/index.js
vendored
219
dist/restore/index.js
vendored
@ -2197,12 +2197,6 @@ function isSuccessStatusCode(statusCode) {
|
|||||||
}
|
}
|
||||||
return statusCode >= 200 && statusCode < 300;
|
return statusCode >= 200 && statusCode < 300;
|
||||||
}
|
}
|
||||||
function isServerErrorStatusCode(statusCode) {
|
|
||||||
if (!statusCode) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return statusCode >= 500;
|
|
||||||
}
|
|
||||||
function isRetryableStatusCode(statusCode) {
|
function isRetryableStatusCode(statusCode) {
|
||||||
if (!statusCode) {
|
if (!statusCode) {
|
||||||
return false;
|
return false;
|
||||||
@ -2242,6 +2236,13 @@ function createHttpClient() {
|
|||||||
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token);
|
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token);
|
||||||
return new http_client_1.HttpClient("actions/cache", [bearerCredentialHandler], getRequestOptions());
|
return new http_client_1.HttpClient("actions/cache", [bearerCredentialHandler], getRequestOptions());
|
||||||
}
|
}
|
||||||
|
function parseEnvNumber(key) {
|
||||||
|
const value = Number(process.env[key]);
|
||||||
|
if (Number.isNaN(value) || value < 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
function getCacheVersion(compressionMethod) {
|
function getCacheVersion(compressionMethod) {
|
||||||
const components = [core.getInput(constants_1.Inputs.Path, { required: true })].concat(compressionMethod == constants_1.CompressionMethod.Zstd ? [compressionMethod] : []);
|
const components = [core.getInput(constants_1.Inputs.Path, { required: true })].concat(compressionMethod == constants_1.CompressionMethod.Zstd ? [compressionMethod] : []);
|
||||||
// Add salt to cache version to support breaking changes in cache entry
|
// Add salt to cache version to support breaking changes in cache entry
|
||||||
@ -2252,60 +2253,19 @@ function getCacheVersion(compressionMethod) {
|
|||||||
.digest("hex");
|
.digest("hex");
|
||||||
}
|
}
|
||||||
exports.getCacheVersion = getCacheVersion;
|
exports.getCacheVersion = getCacheVersion;
|
||||||
function retry(name, method, getStatusCode, maxAttempts = 2) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let response = undefined;
|
|
||||||
let statusCode = undefined;
|
|
||||||
let isRetryable = false;
|
|
||||||
let errorMessage = "";
|
|
||||||
let attempt = 1;
|
|
||||||
while (attempt <= maxAttempts) {
|
|
||||||
try {
|
|
||||||
response = yield method();
|
|
||||||
statusCode = getStatusCode(response);
|
|
||||||
if (!isServerErrorStatusCode(statusCode)) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
isRetryable = isRetryableStatusCode(statusCode);
|
|
||||||
errorMessage = `Cache service responded with ${statusCode}`;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
isRetryable = true;
|
|
||||||
errorMessage = error.message;
|
|
||||||
}
|
|
||||||
core.debug(`${name} - Attempt ${attempt} of ${maxAttempts} failed with error: ${errorMessage}`);
|
|
||||||
if (!isRetryable) {
|
|
||||||
core.debug(`${name} - Error is not retryable`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
attempt++;
|
|
||||||
}
|
|
||||||
throw Error(`${name} failed: ${errorMessage}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.retry = retry;
|
|
||||||
function retryTypedResponse(name, method, maxAttempts = 2) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
return yield retry(name, method, (response) => response.statusCode, maxAttempts);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.retryTypedResponse = retryTypedResponse;
|
|
||||||
function retryHttpClientResponse(name, method, maxAttempts = 2) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
return yield retry(name, method, (response) => response.message.statusCode, maxAttempts);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.retryHttpClientResponse = retryHttpClientResponse;
|
|
||||||
function getCacheEntry(keys, options) {
|
function getCacheEntry(keys, options) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const httpClient = createHttpClient();
|
const httpClient = createHttpClient();
|
||||||
const version = getCacheVersion((_a = options) === null || _a === void 0 ? void 0 : _a.compressionMethod);
|
const version = getCacheVersion((_a = options) === null || _a === void 0 ? void 0 : _a.compressionMethod);
|
||||||
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
||||||
const response = yield retryTypedResponse("getCacheEntry", () => httpClient.getJson(getCacheApiUrl(resource)));
|
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!isSuccessStatusCode(response.statusCode)) {
|
||||||
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
const cacheDownloadUrl = (_b = cacheResult) === null || _b === void 0 ? void 0 : _b.archiveLocation;
|
const cacheDownloadUrl = (_b = cacheResult) === null || _b === void 0 ? void 0 : _b.archiveLocation;
|
||||||
if (!cacheDownloadUrl) {
|
if (!cacheDownloadUrl) {
|
||||||
@ -2325,14 +2285,16 @@ function pipeResponseToStream(response, output) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function downloadCache(archiveLocation, archivePath) {
|
function downloadCache(archiveLocation, archivePath) {
|
||||||
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const stream = fs.createWriteStream(archivePath);
|
const stream = fs.createWriteStream(archivePath);
|
||||||
const httpClient = new http_client_1.HttpClient("actions/cache");
|
const httpClient = new http_client_1.HttpClient("actions/cache");
|
||||||
const downloadResponse = yield retryHttpClientResponse("downloadCache", () => httpClient.get(archiveLocation));
|
const downloadResponse = yield httpClient.get(archiveLocation);
|
||||||
// Abort download if no traffic received over the socket.
|
// Abort download if no traffic received over the socket.
|
||||||
downloadResponse.message.socket.setTimeout(constants_1.SocketTimeout, () => {
|
const socketTimeout = (_a = parseEnvNumber("CACHE_SOCKET_TIMEOUT"), (_a !== null && _a !== void 0 ? _a : constants_1.DefaultSocketTimeout));
|
||||||
|
downloadResponse.message.socket.setTimeout(socketTimeout, () => {
|
||||||
downloadResponse.message.destroy();
|
downloadResponse.message.destroy();
|
||||||
core.debug(`Aborting download, socket timed out after ${constants_1.SocketTimeout} ms`);
|
core.debug(`Aborting download, socket timed out after ${socketTimeout} ms`);
|
||||||
});
|
});
|
||||||
yield pipeResponseToStream(downloadResponse, stream);
|
yield pipeResponseToStream(downloadResponse, stream);
|
||||||
// Validate download size.
|
// Validate download size.
|
||||||
@ -2360,7 +2322,7 @@ function reserveCache(key, options) {
|
|||||||
key,
|
key,
|
||||||
version
|
version
|
||||||
};
|
};
|
||||||
const response = yield retryTypedResponse("reserveCache", () => httpClient.postJson(getCacheApiUrl("caches"), reserveCacheRequest));
|
const response = yield httpClient.postJson(getCacheApiUrl("caches"), reserveCacheRequest);
|
||||||
return _d = (_c = (_b = response) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.cacheId, (_d !== null && _d !== void 0 ? _d : -1);
|
return _d = (_c = (_b = response) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.cacheId, (_d !== null && _d !== void 0 ? _d : -1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2373,7 +2335,7 @@ function getContentRange(start, end) {
|
|||||||
// Content-Range: bytes 0-199/*
|
// Content-Range: bytes 0-199/*
|
||||||
return `bytes ${start}-${end}/*`;
|
return `bytes ${start}-${end}/*`;
|
||||||
}
|
}
|
||||||
function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
|
function uploadChunk(httpClient, resourceUrl, data, start, end) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Uploading chunk of size ${end -
|
core.debug(`Uploading chunk of size ${end -
|
||||||
start +
|
start +
|
||||||
@ -2383,18 +2345,22 @@ function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
|
|||||||
"Content-Range": getContentRange(start, end)
|
"Content-Range": getContentRange(start, end)
|
||||||
};
|
};
|
||||||
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
||||||
return yield httpClient.sendStream("PATCH", resourceUrl, openStream(), additionalHeaders);
|
return yield httpClient.sendStream("PATCH", resourceUrl, data, additionalHeaders);
|
||||||
});
|
});
|
||||||
yield retryHttpClientResponse(`uploadChunk (start: ${start}, end: ${end})`, uploadChunkRequest);
|
const response = yield uploadChunkRequest();
|
||||||
|
if (isSuccessStatusCode(response.message.statusCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isRetryableStatusCode(response.message.statusCode)) {
|
||||||
|
core.debug(`Received ${response.message.statusCode}, retrying chunk at offset ${start}.`);
|
||||||
|
const retryResponse = yield uploadChunkRequest();
|
||||||
|
if (isSuccessStatusCode(retryResponse.message.statusCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Cache service responded with ${response.message.statusCode} during chunk upload.`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function parseEnvNumber(key) {
|
|
||||||
const value = Number(process.env[key]);
|
|
||||||
if (Number.isNaN(value) || value < 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
function uploadFile(httpClient, cacheId, archivePath) {
|
function uploadFile(httpClient, cacheId, archivePath) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -2415,12 +2381,13 @@ function uploadFile(httpClient, cacheId, archivePath) {
|
|||||||
const start = offset;
|
const start = offset;
|
||||||
const end = offset + chunkSize - 1;
|
const end = offset + chunkSize - 1;
|
||||||
offset += MAX_CHUNK_SIZE;
|
offset += MAX_CHUNK_SIZE;
|
||||||
yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, {
|
const chunk = fs.createReadStream(archivePath, {
|
||||||
fd,
|
fd,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
autoClose: false
|
autoClose: false
|
||||||
}), start, end);
|
});
|
||||||
|
yield uploadChunk(httpClient, resourceUrl, chunk, start, end);
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
@ -2433,7 +2400,7 @@ function uploadFile(httpClient, cacheId, archivePath) {
|
|||||||
function commitCache(httpClient, cacheId, filesize) {
|
function commitCache(httpClient, cacheId, filesize) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const commitCacheRequest = { size: filesize };
|
const commitCacheRequest = { size: filesize };
|
||||||
return yield retryTypedResponse("commitCache", () => httpClient.postJson(getCacheApiUrl(`caches/${cacheId.toString()}`), commitCacheRequest));
|
return yield httpClient.postJson(getCacheApiUrl(`caches/${cacheId.toString()}`), commitCacheRequest);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function saveCache(cacheId, archivePath) {
|
function saveCache(cacheId, archivePath) {
|
||||||
@ -2475,9 +2442,7 @@ class BasicCredentialHandler {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
prepareRequest(options) {
|
prepareRequest(options) {
|
||||||
options.headers['Authorization'] =
|
options.headers['Authorization'] = 'Basic ' + Buffer.from(this.username + ':' + this.password).toString('base64');
|
||||||
'Basic ' +
|
|
||||||
Buffer.from(this.username + ':' + this.password).toString('base64');
|
|
||||||
}
|
}
|
||||||
// This handler cannot handle 401
|
// This handler cannot handle 401
|
||||||
canHandleAuthentication(response) {
|
canHandleAuthentication(response) {
|
||||||
@ -2513,8 +2478,7 @@ class PersonalAccessTokenCredentialHandler {
|
|||||||
// currently implements pre-authorization
|
// currently implements pre-authorization
|
||||||
// TODO: support preAuth = false where it hooks on 401
|
// TODO: support preAuth = false where it hooks on 401
|
||||||
prepareRequest(options) {
|
prepareRequest(options) {
|
||||||
options.headers['Authorization'] =
|
options.headers['Authorization'] = 'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
||||||
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
|
||||||
}
|
}
|
||||||
// This handler cannot handle 401
|
// This handler cannot handle 401
|
||||||
canHandleAuthentication(response) {
|
canHandleAuthentication(response) {
|
||||||
@ -3241,7 +3205,6 @@ const exec = __importStar(__webpack_require__(986));
|
|||||||
const glob = __importStar(__webpack_require__(281));
|
const glob = __importStar(__webpack_require__(281));
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const os = __importStar(__webpack_require__(87));
|
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const util = __importStar(__webpack_require__(669));
|
const util = __importStar(__webpack_require__(669));
|
||||||
const uuidV4 = __importStar(__webpack_require__(826));
|
const uuidV4 = __importStar(__webpack_require__(826));
|
||||||
@ -3382,10 +3345,6 @@ function getVersion(app) {
|
|||||||
}
|
}
|
||||||
function getCompressionMethod() {
|
function getCompressionMethod() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Disabling zstd on Windows due to https://github.com/actions/cache/issues/301
|
|
||||||
if (os.platform() === "win32") {
|
|
||||||
return constants_1.CompressionMethod.Gzip;
|
|
||||||
}
|
|
||||||
const versionOutput = yield getVersion("zstd");
|
const versionOutput = yield getVersion("zstd");
|
||||||
return versionOutput.toLowerCase().includes("zstd command line interface")
|
return versionOutput.toLowerCase().includes("zstd command line interface")
|
||||||
? constants_1.CompressionMethod.Zstd
|
? constants_1.CompressionMethod.Zstd
|
||||||
@ -3646,7 +3605,6 @@ var HttpCodes;
|
|||||||
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
||||||
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
||||||
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
||||||
HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests";
|
|
||||||
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
||||||
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
||||||
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
||||||
@ -3671,18 +3629,8 @@ function getProxyUrl(serverUrl) {
|
|||||||
return proxyUrl ? proxyUrl.href : '';
|
return proxyUrl ? proxyUrl.href : '';
|
||||||
}
|
}
|
||||||
exports.getProxyUrl = getProxyUrl;
|
exports.getProxyUrl = getProxyUrl;
|
||||||
const HttpRedirectCodes = [
|
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
|
||||||
HttpCodes.MovedPermanently,
|
const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout];
|
||||||
HttpCodes.ResourceMoved,
|
|
||||||
HttpCodes.SeeOther,
|
|
||||||
HttpCodes.TemporaryRedirect,
|
|
||||||
HttpCodes.PermanentRedirect
|
|
||||||
];
|
|
||||||
const HttpResponseRetryCodes = [
|
|
||||||
HttpCodes.BadGateway,
|
|
||||||
HttpCodes.ServiceUnavailable,
|
|
||||||
HttpCodes.GatewayTimeout
|
|
||||||
];
|
|
||||||
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
||||||
const ExponentialBackoffCeiling = 10;
|
const ExponentialBackoffCeiling = 10;
|
||||||
const ExponentialBackoffTimeSlice = 5;
|
const ExponentialBackoffTimeSlice = 5;
|
||||||
@ -3696,6 +3644,12 @@ class HttpClientResponse {
|
|||||||
this.message.on('data', (chunk) => {
|
this.message.on('data', (chunk) => {
|
||||||
output = Buffer.concat([output, chunk]);
|
output = Buffer.concat([output, chunk]);
|
||||||
});
|
});
|
||||||
|
this.message.on('aborted', () => {
|
||||||
|
reject("Request was aborted or closed prematurely");
|
||||||
|
});
|
||||||
|
this.message.on('timeout', (socket) => {
|
||||||
|
reject("Request timed out");
|
||||||
|
});
|
||||||
this.message.on('end', () => {
|
this.message.on('end', () => {
|
||||||
resolve(output.toString());
|
resolve(output.toString());
|
||||||
});
|
});
|
||||||
@ -3807,22 +3761,19 @@ class HttpClient {
|
|||||||
*/
|
*/
|
||||||
async request(verb, requestUrl, data, headers) {
|
async request(verb, requestUrl, data, headers) {
|
||||||
if (this._disposed) {
|
if (this._disposed) {
|
||||||
throw new Error('Client has already been disposed.');
|
throw new Error("Client has already been disposed.");
|
||||||
}
|
}
|
||||||
let parsedUrl = url.parse(requestUrl);
|
let parsedUrl = url.parse(requestUrl);
|
||||||
let info = this._prepareRequest(verb, parsedUrl, headers);
|
let info = this._prepareRequest(verb, parsedUrl, headers);
|
||||||
// Only perform retries on reads since writes may not be idempotent.
|
// Only perform retries on reads since writes may not be idempotent.
|
||||||
let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
|
let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1;
|
||||||
? this._maxRetries + 1
|
|
||||||
: 1;
|
|
||||||
let numTries = 0;
|
let numTries = 0;
|
||||||
let response;
|
let response;
|
||||||
while (numTries < maxTries) {
|
while (numTries < maxTries) {
|
||||||
response = await this.requestRaw(info, data);
|
response = await this.requestRaw(info, data);
|
||||||
|
|
||||||
// Check if it's an authentication challenge
|
// Check if it's an authentication challenge
|
||||||
if (response &&
|
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
|
||||||
response.message &&
|
|
||||||
response.message.statusCode === HttpCodes.Unauthorized) {
|
|
||||||
let authenticationHandler;
|
let authenticationHandler;
|
||||||
for (let i = 0; i < this.handlers.length; i++) {
|
for (let i = 0; i < this.handlers.length; i++) {
|
||||||
if (this.handlers[i].canHandleAuthentication(response)) {
|
if (this.handlers[i].canHandleAuthentication(response)) {
|
||||||
@ -3840,32 +3791,21 @@ class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let redirectsRemaining = this._maxRedirects;
|
let redirectsRemaining = this._maxRedirects;
|
||||||
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 &&
|
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
|
||||||
this._allowRedirects &&
|
&& this._allowRedirects
|
||||||
redirectsRemaining > 0) {
|
&& redirectsRemaining > 0) {
|
||||||
const redirectUrl = response.message.headers['location'];
|
const redirectUrl = response.message.headers["location"];
|
||||||
if (!redirectUrl) {
|
if (!redirectUrl) {
|
||||||
// if there's no location to redirect to, we won't
|
// if there's no location to redirect to, we won't
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let parsedRedirectUrl = url.parse(redirectUrl);
|
let parsedRedirectUrl = url.parse(redirectUrl);
|
||||||
if (parsedUrl.protocol == 'https:' &&
|
if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) {
|
||||||
parsedUrl.protocol != parsedRedirectUrl.protocol &&
|
throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.");
|
||||||
!this._allowRedirectDowngrade) {
|
|
||||||
throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.');
|
|
||||||
}
|
}
|
||||||
// we need to finish reading the response before reassigning response
|
// we need to finish reading the response before reassigning response
|
||||||
// which will leak the open socket.
|
// which will leak the open socket.
|
||||||
await response.readBody();
|
await response.readBody();
|
||||||
// strip authorization header if redirected to a different hostname
|
|
||||||
if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
|
|
||||||
for (let header in headers) {
|
|
||||||
// header names are case insensitive
|
|
||||||
if (header.toLowerCase() === 'authorization') {
|
|
||||||
delete headers[header];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// let's make the request with the new redirectUrl
|
// let's make the request with the new redirectUrl
|
||||||
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
|
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
|
||||||
response = await this.requestRaw(info, data);
|
response = await this.requestRaw(info, data);
|
||||||
@ -3916,8 +3856,8 @@ class HttpClient {
|
|||||||
*/
|
*/
|
||||||
requestRawWithCallback(info, data, onResult) {
|
requestRawWithCallback(info, data, onResult) {
|
||||||
let socket;
|
let socket;
|
||||||
if (typeof data === 'string') {
|
if (typeof (data) === 'string') {
|
||||||
info.options.headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
|
info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8');
|
||||||
}
|
}
|
||||||
let callbackCalled = false;
|
let callbackCalled = false;
|
||||||
let handleResult = (err, res) => {
|
let handleResult = (err, res) => {
|
||||||
@ -3930,7 +3870,7 @@ class HttpClient {
|
|||||||
let res = new HttpClientResponse(msg);
|
let res = new HttpClientResponse(msg);
|
||||||
handleResult(null, res);
|
handleResult(null, res);
|
||||||
});
|
});
|
||||||
req.on('socket', sock => {
|
req.on('socket', (sock) => {
|
||||||
socket = sock;
|
socket = sock;
|
||||||
});
|
});
|
||||||
// If we ever get disconnected, we want the socket to timeout eventually
|
// If we ever get disconnected, we want the socket to timeout eventually
|
||||||
@ -3943,12 +3883,13 @@ class HttpClient {
|
|||||||
req.on('error', function (err) {
|
req.on('error', function (err) {
|
||||||
// err has statusCode property
|
// err has statusCode property
|
||||||
// res should have headers
|
// res should have headers
|
||||||
|
console.log(`Caught error on request: ${err}`);
|
||||||
handleResult(err, null);
|
handleResult(err, null);
|
||||||
});
|
});
|
||||||
if (data && typeof data === 'string') {
|
if (data && typeof (data) === 'string') {
|
||||||
req.write(data, 'utf8');
|
req.write(data, 'utf8');
|
||||||
}
|
}
|
||||||
if (data && typeof data !== 'string') {
|
if (data && typeof (data) !== 'string') {
|
||||||
data.on('close', function () {
|
data.on('close', function () {
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
@ -3975,34 +3916,31 @@ class HttpClient {
|
|||||||
const defaultPort = usingSsl ? 443 : 80;
|
const defaultPort = usingSsl ? 443 : 80;
|
||||||
info.options = {};
|
info.options = {};
|
||||||
info.options.host = info.parsedUrl.hostname;
|
info.options.host = info.parsedUrl.hostname;
|
||||||
info.options.port = info.parsedUrl.port
|
info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort;
|
||||||
? parseInt(info.parsedUrl.port)
|
info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
||||||
: defaultPort;
|
|
||||||
info.options.path =
|
|
||||||
(info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
|
||||||
info.options.method = method;
|
info.options.method = method;
|
||||||
info.options.headers = this._mergeHeaders(headers);
|
info.options.headers = this._mergeHeaders(headers);
|
||||||
if (this.userAgent != null) {
|
if (this.userAgent != null) {
|
||||||
info.options.headers['user-agent'] = this.userAgent;
|
info.options.headers["user-agent"] = this.userAgent;
|
||||||
}
|
}
|
||||||
info.options.agent = this._getAgent(info.parsedUrl);
|
info.options.agent = this._getAgent(info.parsedUrl);
|
||||||
// gives handlers an opportunity to participate
|
// gives handlers an opportunity to participate
|
||||||
if (this.handlers) {
|
if (this.handlers) {
|
||||||
this.handlers.forEach(handler => {
|
this.handlers.forEach((handler) => {
|
||||||
handler.prepareRequest(info.options);
|
handler.prepareRequest(info.options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
_mergeHeaders(headers) {
|
_mergeHeaders(headers) {
|
||||||
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
|
||||||
if (this.requestOptions && this.requestOptions.headers) {
|
if (this.requestOptions && this.requestOptions.headers) {
|
||||||
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
|
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
|
||||||
}
|
}
|
||||||
return lowercaseKeys(headers || {});
|
return lowercaseKeys(headers || {});
|
||||||
}
|
}
|
||||||
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
|
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
|
||||||
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
|
||||||
let clientHeader;
|
let clientHeader;
|
||||||
if (this.requestOptions && this.requestOptions.headers) {
|
if (this.requestOptions && this.requestOptions.headers) {
|
||||||
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
|
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
|
||||||
@ -4040,7 +3978,7 @@ class HttpClient {
|
|||||||
proxyAuth: proxyUrl.auth,
|
proxyAuth: proxyUrl.auth,
|
||||||
host: proxyUrl.hostname,
|
host: proxyUrl.hostname,
|
||||||
port: proxyUrl.port
|
port: proxyUrl.port
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
let tunnelAgent;
|
let tunnelAgent;
|
||||||
const overHttps = proxyUrl.protocol === 'https:';
|
const overHttps = proxyUrl.protocol === 'https:';
|
||||||
@ -4067,9 +4005,7 @@ class HttpClient {
|
|||||||
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
||||||
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
||||||
// we have to cast it to any and change it directly
|
// we have to cast it to any and change it directly
|
||||||
agent.options = Object.assign(agent.options || {}, {
|
agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false });
|
||||||
rejectUnauthorized: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return agent;
|
return agent;
|
||||||
}
|
}
|
||||||
@ -4130,7 +4066,7 @@ class HttpClient {
|
|||||||
msg = contents;
|
msg = contents;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = 'Failed request: (' + statusCode + ')';
|
msg = "Failed request: (" + statusCode + ")";
|
||||||
}
|
}
|
||||||
let err = new Error(msg);
|
let err = new Error(msg);
|
||||||
// attach statusCode and body obj (if available) to the error object
|
// attach statusCode and body obj (if available) to the error object
|
||||||
@ -4613,7 +4549,7 @@ var CompressionMethod;
|
|||||||
// Socket timeout in milliseconds during download. If no traffic is received
|
// Socket timeout in milliseconds during download. If no traffic is received
|
||||||
// over the socket during this period, the socket is destroyed and the download
|
// over the socket during this period, the socket is destroyed and the download
|
||||||
// is aborted.
|
// is aborted.
|
||||||
exports.SocketTimeout = 5000;
|
exports.DefaultSocketTimeout = 5000;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -5219,10 +5155,12 @@ function getProxyUrl(reqUrl) {
|
|||||||
}
|
}
|
||||||
let proxyVar;
|
let proxyVar;
|
||||||
if (usingSsl) {
|
if (usingSsl) {
|
||||||
proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
|
proxyVar = process.env["https_proxy"] ||
|
||||||
|
process.env["HTTPS_PROXY"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
proxyVar = process.env["http_proxy"] ||
|
||||||
|
process.env["HTTP_PROXY"];
|
||||||
}
|
}
|
||||||
if (proxyVar) {
|
if (proxyVar) {
|
||||||
proxyUrl = url.parse(proxyVar);
|
proxyUrl = url.parse(proxyVar);
|
||||||
@ -5234,7 +5172,7 @@ function checkBypass(reqUrl) {
|
|||||||
if (!reqUrl.hostname) {
|
if (!reqUrl.hostname) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
let noProxy = process.env["no_proxy"] || process.env["NO_PROXY"] || '';
|
||||||
if (!noProxy) {
|
if (!noProxy) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -5255,10 +5193,7 @@ function checkBypass(reqUrl) {
|
|||||||
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
||||||
}
|
}
|
||||||
// Compare request host against noproxy
|
// Compare request host against noproxy
|
||||||
for (let upperNoProxyItem of noProxy
|
for (let upperNoProxyItem of noProxy.split(',').map(x => x.trim().toUpperCase()).filter(x => x)) {
|
||||||
.split(',')
|
|
||||||
.map(x => x.trim().toUpperCase())
|
|
||||||
.filter(x => x)) {
|
|
||||||
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
219
dist/save/index.js
vendored
219
dist/save/index.js
vendored
@ -2197,12 +2197,6 @@ function isSuccessStatusCode(statusCode) {
|
|||||||
}
|
}
|
||||||
return statusCode >= 200 && statusCode < 300;
|
return statusCode >= 200 && statusCode < 300;
|
||||||
}
|
}
|
||||||
function isServerErrorStatusCode(statusCode) {
|
|
||||||
if (!statusCode) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return statusCode >= 500;
|
|
||||||
}
|
|
||||||
function isRetryableStatusCode(statusCode) {
|
function isRetryableStatusCode(statusCode) {
|
||||||
if (!statusCode) {
|
if (!statusCode) {
|
||||||
return false;
|
return false;
|
||||||
@ -2242,6 +2236,13 @@ function createHttpClient() {
|
|||||||
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token);
|
const bearerCredentialHandler = new auth_1.BearerCredentialHandler(token);
|
||||||
return new http_client_1.HttpClient("actions/cache", [bearerCredentialHandler], getRequestOptions());
|
return new http_client_1.HttpClient("actions/cache", [bearerCredentialHandler], getRequestOptions());
|
||||||
}
|
}
|
||||||
|
function parseEnvNumber(key) {
|
||||||
|
const value = Number(process.env[key]);
|
||||||
|
if (Number.isNaN(value) || value < 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
function getCacheVersion(compressionMethod) {
|
function getCacheVersion(compressionMethod) {
|
||||||
const components = [core.getInput(constants_1.Inputs.Path, { required: true })].concat(compressionMethod == constants_1.CompressionMethod.Zstd ? [compressionMethod] : []);
|
const components = [core.getInput(constants_1.Inputs.Path, { required: true })].concat(compressionMethod == constants_1.CompressionMethod.Zstd ? [compressionMethod] : []);
|
||||||
// Add salt to cache version to support breaking changes in cache entry
|
// Add salt to cache version to support breaking changes in cache entry
|
||||||
@ -2252,60 +2253,19 @@ function getCacheVersion(compressionMethod) {
|
|||||||
.digest("hex");
|
.digest("hex");
|
||||||
}
|
}
|
||||||
exports.getCacheVersion = getCacheVersion;
|
exports.getCacheVersion = getCacheVersion;
|
||||||
function retry(name, method, getStatusCode, maxAttempts = 2) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let response = undefined;
|
|
||||||
let statusCode = undefined;
|
|
||||||
let isRetryable = false;
|
|
||||||
let errorMessage = "";
|
|
||||||
let attempt = 1;
|
|
||||||
while (attempt <= maxAttempts) {
|
|
||||||
try {
|
|
||||||
response = yield method();
|
|
||||||
statusCode = getStatusCode(response);
|
|
||||||
if (!isServerErrorStatusCode(statusCode)) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
isRetryable = isRetryableStatusCode(statusCode);
|
|
||||||
errorMessage = `Cache service responded with ${statusCode}`;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
isRetryable = true;
|
|
||||||
errorMessage = error.message;
|
|
||||||
}
|
|
||||||
core.debug(`${name} - Attempt ${attempt} of ${maxAttempts} failed with error: ${errorMessage}`);
|
|
||||||
if (!isRetryable) {
|
|
||||||
core.debug(`${name} - Error is not retryable`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
attempt++;
|
|
||||||
}
|
|
||||||
throw Error(`${name} failed: ${errorMessage}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.retry = retry;
|
|
||||||
function retryTypedResponse(name, method, maxAttempts = 2) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
return yield retry(name, method, (response) => response.statusCode, maxAttempts);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.retryTypedResponse = retryTypedResponse;
|
|
||||||
function retryHttpClientResponse(name, method, maxAttempts = 2) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
return yield retry(name, method, (response) => response.message.statusCode, maxAttempts);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.retryHttpClientResponse = retryHttpClientResponse;
|
|
||||||
function getCacheEntry(keys, options) {
|
function getCacheEntry(keys, options) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const httpClient = createHttpClient();
|
const httpClient = createHttpClient();
|
||||||
const version = getCacheVersion((_a = options) === null || _a === void 0 ? void 0 : _a.compressionMethod);
|
const version = getCacheVersion((_a = options) === null || _a === void 0 ? void 0 : _a.compressionMethod);
|
||||||
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
const resource = `cache?keys=${encodeURIComponent(keys.join(","))}&version=${version}`;
|
||||||
const response = yield retryTypedResponse("getCacheEntry", () => httpClient.getJson(getCacheApiUrl(resource)));
|
const response = yield httpClient.getJson(getCacheApiUrl(resource));
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!isSuccessStatusCode(response.statusCode)) {
|
||||||
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
|
}
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
const cacheDownloadUrl = (_b = cacheResult) === null || _b === void 0 ? void 0 : _b.archiveLocation;
|
const cacheDownloadUrl = (_b = cacheResult) === null || _b === void 0 ? void 0 : _b.archiveLocation;
|
||||||
if (!cacheDownloadUrl) {
|
if (!cacheDownloadUrl) {
|
||||||
@ -2325,14 +2285,16 @@ function pipeResponseToStream(response, output) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function downloadCache(archiveLocation, archivePath) {
|
function downloadCache(archiveLocation, archivePath) {
|
||||||
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const stream = fs.createWriteStream(archivePath);
|
const stream = fs.createWriteStream(archivePath);
|
||||||
const httpClient = new http_client_1.HttpClient("actions/cache");
|
const httpClient = new http_client_1.HttpClient("actions/cache");
|
||||||
const downloadResponse = yield retryHttpClientResponse("downloadCache", () => httpClient.get(archiveLocation));
|
const downloadResponse = yield httpClient.get(archiveLocation);
|
||||||
// Abort download if no traffic received over the socket.
|
// Abort download if no traffic received over the socket.
|
||||||
downloadResponse.message.socket.setTimeout(constants_1.SocketTimeout, () => {
|
const socketTimeout = (_a = parseEnvNumber("CACHE_SOCKET_TIMEOUT"), (_a !== null && _a !== void 0 ? _a : constants_1.DefaultSocketTimeout));
|
||||||
|
downloadResponse.message.socket.setTimeout(socketTimeout, () => {
|
||||||
downloadResponse.message.destroy();
|
downloadResponse.message.destroy();
|
||||||
core.debug(`Aborting download, socket timed out after ${constants_1.SocketTimeout} ms`);
|
core.debug(`Aborting download, socket timed out after ${socketTimeout} ms`);
|
||||||
});
|
});
|
||||||
yield pipeResponseToStream(downloadResponse, stream);
|
yield pipeResponseToStream(downloadResponse, stream);
|
||||||
// Validate download size.
|
// Validate download size.
|
||||||
@ -2360,7 +2322,7 @@ function reserveCache(key, options) {
|
|||||||
key,
|
key,
|
||||||
version
|
version
|
||||||
};
|
};
|
||||||
const response = yield retryTypedResponse("reserveCache", () => httpClient.postJson(getCacheApiUrl("caches"), reserveCacheRequest));
|
const response = yield httpClient.postJson(getCacheApiUrl("caches"), reserveCacheRequest);
|
||||||
return _d = (_c = (_b = response) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.cacheId, (_d !== null && _d !== void 0 ? _d : -1);
|
return _d = (_c = (_b = response) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.cacheId, (_d !== null && _d !== void 0 ? _d : -1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2373,7 +2335,7 @@ function getContentRange(start, end) {
|
|||||||
// Content-Range: bytes 0-199/*
|
// Content-Range: bytes 0-199/*
|
||||||
return `bytes ${start}-${end}/*`;
|
return `bytes ${start}-${end}/*`;
|
||||||
}
|
}
|
||||||
function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
|
function uploadChunk(httpClient, resourceUrl, data, start, end) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Uploading chunk of size ${end -
|
core.debug(`Uploading chunk of size ${end -
|
||||||
start +
|
start +
|
||||||
@ -2383,18 +2345,22 @@ function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
|
|||||||
"Content-Range": getContentRange(start, end)
|
"Content-Range": getContentRange(start, end)
|
||||||
};
|
};
|
||||||
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
||||||
return yield httpClient.sendStream("PATCH", resourceUrl, openStream(), additionalHeaders);
|
return yield httpClient.sendStream("PATCH", resourceUrl, data, additionalHeaders);
|
||||||
});
|
});
|
||||||
yield retryHttpClientResponse(`uploadChunk (start: ${start}, end: ${end})`, uploadChunkRequest);
|
const response = yield uploadChunkRequest();
|
||||||
|
if (isSuccessStatusCode(response.message.statusCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isRetryableStatusCode(response.message.statusCode)) {
|
||||||
|
core.debug(`Received ${response.message.statusCode}, retrying chunk at offset ${start}.`);
|
||||||
|
const retryResponse = yield uploadChunkRequest();
|
||||||
|
if (isSuccessStatusCode(retryResponse.message.statusCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Cache service responded with ${response.message.statusCode} during chunk upload.`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function parseEnvNumber(key) {
|
|
||||||
const value = Number(process.env[key]);
|
|
||||||
if (Number.isNaN(value) || value < 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
function uploadFile(httpClient, cacheId, archivePath) {
|
function uploadFile(httpClient, cacheId, archivePath) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -2415,12 +2381,13 @@ function uploadFile(httpClient, cacheId, archivePath) {
|
|||||||
const start = offset;
|
const start = offset;
|
||||||
const end = offset + chunkSize - 1;
|
const end = offset + chunkSize - 1;
|
||||||
offset += MAX_CHUNK_SIZE;
|
offset += MAX_CHUNK_SIZE;
|
||||||
yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, {
|
const chunk = fs.createReadStream(archivePath, {
|
||||||
fd,
|
fd,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
autoClose: false
|
autoClose: false
|
||||||
}), start, end);
|
});
|
||||||
|
yield uploadChunk(httpClient, resourceUrl, chunk, start, end);
|
||||||
}
|
}
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
@ -2433,7 +2400,7 @@ function uploadFile(httpClient, cacheId, archivePath) {
|
|||||||
function commitCache(httpClient, cacheId, filesize) {
|
function commitCache(httpClient, cacheId, filesize) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const commitCacheRequest = { size: filesize };
|
const commitCacheRequest = { size: filesize };
|
||||||
return yield retryTypedResponse("commitCache", () => httpClient.postJson(getCacheApiUrl(`caches/${cacheId.toString()}`), commitCacheRequest));
|
return yield httpClient.postJson(getCacheApiUrl(`caches/${cacheId.toString()}`), commitCacheRequest);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function saveCache(cacheId, archivePath) {
|
function saveCache(cacheId, archivePath) {
|
||||||
@ -2475,9 +2442,7 @@ class BasicCredentialHandler {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
prepareRequest(options) {
|
prepareRequest(options) {
|
||||||
options.headers['Authorization'] =
|
options.headers['Authorization'] = 'Basic ' + Buffer.from(this.username + ':' + this.password).toString('base64');
|
||||||
'Basic ' +
|
|
||||||
Buffer.from(this.username + ':' + this.password).toString('base64');
|
|
||||||
}
|
}
|
||||||
// This handler cannot handle 401
|
// This handler cannot handle 401
|
||||||
canHandleAuthentication(response) {
|
canHandleAuthentication(response) {
|
||||||
@ -2513,8 +2478,7 @@ class PersonalAccessTokenCredentialHandler {
|
|||||||
// currently implements pre-authorization
|
// currently implements pre-authorization
|
||||||
// TODO: support preAuth = false where it hooks on 401
|
// TODO: support preAuth = false where it hooks on 401
|
||||||
prepareRequest(options) {
|
prepareRequest(options) {
|
||||||
options.headers['Authorization'] =
|
options.headers['Authorization'] = 'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
||||||
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
|
||||||
}
|
}
|
||||||
// This handler cannot handle 401
|
// This handler cannot handle 401
|
||||||
canHandleAuthentication(response) {
|
canHandleAuthentication(response) {
|
||||||
@ -3241,7 +3205,6 @@ const exec = __importStar(__webpack_require__(986));
|
|||||||
const glob = __importStar(__webpack_require__(281));
|
const glob = __importStar(__webpack_require__(281));
|
||||||
const io = __importStar(__webpack_require__(1));
|
const io = __importStar(__webpack_require__(1));
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const os = __importStar(__webpack_require__(87));
|
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const util = __importStar(__webpack_require__(669));
|
const util = __importStar(__webpack_require__(669));
|
||||||
const uuidV4 = __importStar(__webpack_require__(826));
|
const uuidV4 = __importStar(__webpack_require__(826));
|
||||||
@ -3382,10 +3345,6 @@ function getVersion(app) {
|
|||||||
}
|
}
|
||||||
function getCompressionMethod() {
|
function getCompressionMethod() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Disabling zstd on Windows due to https://github.com/actions/cache/issues/301
|
|
||||||
if (os.platform() === "win32") {
|
|
||||||
return constants_1.CompressionMethod.Gzip;
|
|
||||||
}
|
|
||||||
const versionOutput = yield getVersion("zstd");
|
const versionOutput = yield getVersion("zstd");
|
||||||
return versionOutput.toLowerCase().includes("zstd command line interface")
|
return versionOutput.toLowerCase().includes("zstd command line interface")
|
||||||
? constants_1.CompressionMethod.Zstd
|
? constants_1.CompressionMethod.Zstd
|
||||||
@ -3646,7 +3605,6 @@ var HttpCodes;
|
|||||||
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
||||||
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
||||||
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
||||||
HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests";
|
|
||||||
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
||||||
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
||||||
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
||||||
@ -3671,18 +3629,8 @@ function getProxyUrl(serverUrl) {
|
|||||||
return proxyUrl ? proxyUrl.href : '';
|
return proxyUrl ? proxyUrl.href : '';
|
||||||
}
|
}
|
||||||
exports.getProxyUrl = getProxyUrl;
|
exports.getProxyUrl = getProxyUrl;
|
||||||
const HttpRedirectCodes = [
|
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
|
||||||
HttpCodes.MovedPermanently,
|
const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout];
|
||||||
HttpCodes.ResourceMoved,
|
|
||||||
HttpCodes.SeeOther,
|
|
||||||
HttpCodes.TemporaryRedirect,
|
|
||||||
HttpCodes.PermanentRedirect
|
|
||||||
];
|
|
||||||
const HttpResponseRetryCodes = [
|
|
||||||
HttpCodes.BadGateway,
|
|
||||||
HttpCodes.ServiceUnavailable,
|
|
||||||
HttpCodes.GatewayTimeout
|
|
||||||
];
|
|
||||||
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
||||||
const ExponentialBackoffCeiling = 10;
|
const ExponentialBackoffCeiling = 10;
|
||||||
const ExponentialBackoffTimeSlice = 5;
|
const ExponentialBackoffTimeSlice = 5;
|
||||||
@ -3696,6 +3644,12 @@ class HttpClientResponse {
|
|||||||
this.message.on('data', (chunk) => {
|
this.message.on('data', (chunk) => {
|
||||||
output = Buffer.concat([output, chunk]);
|
output = Buffer.concat([output, chunk]);
|
||||||
});
|
});
|
||||||
|
this.message.on('aborted', () => {
|
||||||
|
reject("Request was aborted or closed prematurely");
|
||||||
|
});
|
||||||
|
this.message.on('timeout', (socket) => {
|
||||||
|
reject("Request timed out");
|
||||||
|
});
|
||||||
this.message.on('end', () => {
|
this.message.on('end', () => {
|
||||||
resolve(output.toString());
|
resolve(output.toString());
|
||||||
});
|
});
|
||||||
@ -3807,22 +3761,19 @@ class HttpClient {
|
|||||||
*/
|
*/
|
||||||
async request(verb, requestUrl, data, headers) {
|
async request(verb, requestUrl, data, headers) {
|
||||||
if (this._disposed) {
|
if (this._disposed) {
|
||||||
throw new Error('Client has already been disposed.');
|
throw new Error("Client has already been disposed.");
|
||||||
}
|
}
|
||||||
let parsedUrl = url.parse(requestUrl);
|
let parsedUrl = url.parse(requestUrl);
|
||||||
let info = this._prepareRequest(verb, parsedUrl, headers);
|
let info = this._prepareRequest(verb, parsedUrl, headers);
|
||||||
// Only perform retries on reads since writes may not be idempotent.
|
// Only perform retries on reads since writes may not be idempotent.
|
||||||
let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
|
let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1;
|
||||||
? this._maxRetries + 1
|
|
||||||
: 1;
|
|
||||||
let numTries = 0;
|
let numTries = 0;
|
||||||
let response;
|
let response;
|
||||||
while (numTries < maxTries) {
|
while (numTries < maxTries) {
|
||||||
response = await this.requestRaw(info, data);
|
response = await this.requestRaw(info, data);
|
||||||
|
|
||||||
// Check if it's an authentication challenge
|
// Check if it's an authentication challenge
|
||||||
if (response &&
|
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) {
|
||||||
response.message &&
|
|
||||||
response.message.statusCode === HttpCodes.Unauthorized) {
|
|
||||||
let authenticationHandler;
|
let authenticationHandler;
|
||||||
for (let i = 0; i < this.handlers.length; i++) {
|
for (let i = 0; i < this.handlers.length; i++) {
|
||||||
if (this.handlers[i].canHandleAuthentication(response)) {
|
if (this.handlers[i].canHandleAuthentication(response)) {
|
||||||
@ -3840,32 +3791,21 @@ class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let redirectsRemaining = this._maxRedirects;
|
let redirectsRemaining = this._maxRedirects;
|
||||||
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 &&
|
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
|
||||||
this._allowRedirects &&
|
&& this._allowRedirects
|
||||||
redirectsRemaining > 0) {
|
&& redirectsRemaining > 0) {
|
||||||
const redirectUrl = response.message.headers['location'];
|
const redirectUrl = response.message.headers["location"];
|
||||||
if (!redirectUrl) {
|
if (!redirectUrl) {
|
||||||
// if there's no location to redirect to, we won't
|
// if there's no location to redirect to, we won't
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let parsedRedirectUrl = url.parse(redirectUrl);
|
let parsedRedirectUrl = url.parse(redirectUrl);
|
||||||
if (parsedUrl.protocol == 'https:' &&
|
if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) {
|
||||||
parsedUrl.protocol != parsedRedirectUrl.protocol &&
|
throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.");
|
||||||
!this._allowRedirectDowngrade) {
|
|
||||||
throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.');
|
|
||||||
}
|
}
|
||||||
// we need to finish reading the response before reassigning response
|
// we need to finish reading the response before reassigning response
|
||||||
// which will leak the open socket.
|
// which will leak the open socket.
|
||||||
await response.readBody();
|
await response.readBody();
|
||||||
// strip authorization header if redirected to a different hostname
|
|
||||||
if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
|
|
||||||
for (let header in headers) {
|
|
||||||
// header names are case insensitive
|
|
||||||
if (header.toLowerCase() === 'authorization') {
|
|
||||||
delete headers[header];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// let's make the request with the new redirectUrl
|
// let's make the request with the new redirectUrl
|
||||||
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
|
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
|
||||||
response = await this.requestRaw(info, data);
|
response = await this.requestRaw(info, data);
|
||||||
@ -3916,8 +3856,8 @@ class HttpClient {
|
|||||||
*/
|
*/
|
||||||
requestRawWithCallback(info, data, onResult) {
|
requestRawWithCallback(info, data, onResult) {
|
||||||
let socket;
|
let socket;
|
||||||
if (typeof data === 'string') {
|
if (typeof (data) === 'string') {
|
||||||
info.options.headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
|
info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8');
|
||||||
}
|
}
|
||||||
let callbackCalled = false;
|
let callbackCalled = false;
|
||||||
let handleResult = (err, res) => {
|
let handleResult = (err, res) => {
|
||||||
@ -3930,7 +3870,7 @@ class HttpClient {
|
|||||||
let res = new HttpClientResponse(msg);
|
let res = new HttpClientResponse(msg);
|
||||||
handleResult(null, res);
|
handleResult(null, res);
|
||||||
});
|
});
|
||||||
req.on('socket', sock => {
|
req.on('socket', (sock) => {
|
||||||
socket = sock;
|
socket = sock;
|
||||||
});
|
});
|
||||||
// If we ever get disconnected, we want the socket to timeout eventually
|
// If we ever get disconnected, we want the socket to timeout eventually
|
||||||
@ -3943,12 +3883,13 @@ class HttpClient {
|
|||||||
req.on('error', function (err) {
|
req.on('error', function (err) {
|
||||||
// err has statusCode property
|
// err has statusCode property
|
||||||
// res should have headers
|
// res should have headers
|
||||||
|
console.log(`Caught error on request: ${err}`);
|
||||||
handleResult(err, null);
|
handleResult(err, null);
|
||||||
});
|
});
|
||||||
if (data && typeof data === 'string') {
|
if (data && typeof (data) === 'string') {
|
||||||
req.write(data, 'utf8');
|
req.write(data, 'utf8');
|
||||||
}
|
}
|
||||||
if (data && typeof data !== 'string') {
|
if (data && typeof (data) !== 'string') {
|
||||||
data.on('close', function () {
|
data.on('close', function () {
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
@ -3975,34 +3916,31 @@ class HttpClient {
|
|||||||
const defaultPort = usingSsl ? 443 : 80;
|
const defaultPort = usingSsl ? 443 : 80;
|
||||||
info.options = {};
|
info.options = {};
|
||||||
info.options.host = info.parsedUrl.hostname;
|
info.options.host = info.parsedUrl.hostname;
|
||||||
info.options.port = info.parsedUrl.port
|
info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort;
|
||||||
? parseInt(info.parsedUrl.port)
|
info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
||||||
: defaultPort;
|
|
||||||
info.options.path =
|
|
||||||
(info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
|
||||||
info.options.method = method;
|
info.options.method = method;
|
||||||
info.options.headers = this._mergeHeaders(headers);
|
info.options.headers = this._mergeHeaders(headers);
|
||||||
if (this.userAgent != null) {
|
if (this.userAgent != null) {
|
||||||
info.options.headers['user-agent'] = this.userAgent;
|
info.options.headers["user-agent"] = this.userAgent;
|
||||||
}
|
}
|
||||||
info.options.agent = this._getAgent(info.parsedUrl);
|
info.options.agent = this._getAgent(info.parsedUrl);
|
||||||
// gives handlers an opportunity to participate
|
// gives handlers an opportunity to participate
|
||||||
if (this.handlers) {
|
if (this.handlers) {
|
||||||
this.handlers.forEach(handler => {
|
this.handlers.forEach((handler) => {
|
||||||
handler.prepareRequest(info.options);
|
handler.prepareRequest(info.options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
_mergeHeaders(headers) {
|
_mergeHeaders(headers) {
|
||||||
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
|
||||||
if (this.requestOptions && this.requestOptions.headers) {
|
if (this.requestOptions && this.requestOptions.headers) {
|
||||||
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
|
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
|
||||||
}
|
}
|
||||||
return lowercaseKeys(headers || {});
|
return lowercaseKeys(headers || {});
|
||||||
}
|
}
|
||||||
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
|
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
|
||||||
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {});
|
||||||
let clientHeader;
|
let clientHeader;
|
||||||
if (this.requestOptions && this.requestOptions.headers) {
|
if (this.requestOptions && this.requestOptions.headers) {
|
||||||
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
|
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
|
||||||
@ -4040,7 +3978,7 @@ class HttpClient {
|
|||||||
proxyAuth: proxyUrl.auth,
|
proxyAuth: proxyUrl.auth,
|
||||||
host: proxyUrl.hostname,
|
host: proxyUrl.hostname,
|
||||||
port: proxyUrl.port
|
port: proxyUrl.port
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
let tunnelAgent;
|
let tunnelAgent;
|
||||||
const overHttps = proxyUrl.protocol === 'https:';
|
const overHttps = proxyUrl.protocol === 'https:';
|
||||||
@ -4067,9 +4005,7 @@ class HttpClient {
|
|||||||
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
||||||
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
||||||
// we have to cast it to any and change it directly
|
// we have to cast it to any and change it directly
|
||||||
agent.options = Object.assign(agent.options || {}, {
|
agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false });
|
||||||
rejectUnauthorized: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return agent;
|
return agent;
|
||||||
}
|
}
|
||||||
@ -4130,7 +4066,7 @@ class HttpClient {
|
|||||||
msg = contents;
|
msg = contents;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = 'Failed request: (' + statusCode + ')';
|
msg = "Failed request: (" + statusCode + ")";
|
||||||
}
|
}
|
||||||
let err = new Error(msg);
|
let err = new Error(msg);
|
||||||
// attach statusCode and body obj (if available) to the error object
|
// attach statusCode and body obj (if available) to the error object
|
||||||
@ -4702,7 +4638,7 @@ var CompressionMethod;
|
|||||||
// Socket timeout in milliseconds during download. If no traffic is received
|
// Socket timeout in milliseconds during download. If no traffic is received
|
||||||
// over the socket during this period, the socket is destroyed and the download
|
// over the socket during this period, the socket is destroyed and the download
|
||||||
// is aborted.
|
// is aborted.
|
||||||
exports.SocketTimeout = 5000;
|
exports.DefaultSocketTimeout = 5000;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -5196,10 +5132,12 @@ function getProxyUrl(reqUrl) {
|
|||||||
}
|
}
|
||||||
let proxyVar;
|
let proxyVar;
|
||||||
if (usingSsl) {
|
if (usingSsl) {
|
||||||
proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
|
proxyVar = process.env["https_proxy"] ||
|
||||||
|
process.env["HTTPS_PROXY"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
proxyVar = process.env["http_proxy"] ||
|
||||||
|
process.env["HTTP_PROXY"];
|
||||||
}
|
}
|
||||||
if (proxyVar) {
|
if (proxyVar) {
|
||||||
proxyUrl = url.parse(proxyVar);
|
proxyUrl = url.parse(proxyVar);
|
||||||
@ -5211,7 +5149,7 @@ function checkBypass(reqUrl) {
|
|||||||
if (!reqUrl.hostname) {
|
if (!reqUrl.hostname) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
let noProxy = process.env["no_proxy"] || process.env["NO_PROXY"] || '';
|
||||||
if (!noProxy) {
|
if (!noProxy) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -5232,10 +5170,7 @@ function checkBypass(reqUrl) {
|
|||||||
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
||||||
}
|
}
|
||||||
// Compare request host against noproxy
|
// Compare request host against noproxy
|
||||||
for (let upperNoProxyItem of noProxy
|
for (let upperNoProxyItem of noProxy.split(',').map(x => x.trim().toUpperCase()).filter(x => x)) {
|
||||||
.split(',')
|
|
||||||
.map(x => x.trim().toUpperCase())
|
|
||||||
.filter(x => x)) {
|
|
||||||
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import * as fs from "fs";
|
|||||||
import * as stream from "stream";
|
import * as stream from "stream";
|
||||||
import * as util from "util";
|
import * as util from "util";
|
||||||
|
|
||||||
import { CompressionMethod, Inputs, SocketTimeout } from "./constants";
|
import { CompressionMethod, DefaultSocketTimeout, Inputs } from "./constants";
|
||||||
import {
|
import {
|
||||||
ArtifactCacheEntry,
|
ArtifactCacheEntry,
|
||||||
CacheOptions,
|
CacheOptions,
|
||||||
@ -30,13 +30,6 @@ function isSuccessStatusCode(statusCode?: number): boolean {
|
|||||||
return statusCode >= 200 && statusCode < 300;
|
return statusCode >= 200 && statusCode < 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isServerErrorStatusCode(statusCode?: number): boolean {
|
|
||||||
if (!statusCode) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return statusCode >= 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRetryableStatusCode(statusCode?: number): boolean {
|
function isRetryableStatusCode(statusCode?: number): boolean {
|
||||||
if (!statusCode) {
|
if (!statusCode) {
|
||||||
return false;
|
return false;
|
||||||
@ -92,6 +85,14 @@ function createHttpClient(): HttpClient {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseEnvNumber(key: string): number | undefined {
|
||||||
|
const value = Number(process.env[key]);
|
||||||
|
if (Number.isNaN(value) || value < 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
export function getCacheVersion(compressionMethod?: CompressionMethod): string {
|
export function getCacheVersion(compressionMethod?: CompressionMethod): string {
|
||||||
const components = [core.getInput(Inputs.Path, { required: true })].concat(
|
const components = [core.getInput(Inputs.Path, { required: true })].concat(
|
||||||
compressionMethod == CompressionMethod.Zstd ? [compressionMethod] : []
|
compressionMethod == CompressionMethod.Zstd ? [compressionMethod] : []
|
||||||
@ -106,75 +107,6 @@ export function getCacheVersion(compressionMethod?: CompressionMethod): string {
|
|||||||
.digest("hex");
|
.digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function retry<T>(
|
|
||||||
name: string,
|
|
||||||
method: () => Promise<T>,
|
|
||||||
getStatusCode: (T) => number | undefined,
|
|
||||||
maxAttempts = 2
|
|
||||||
): Promise<T> {
|
|
||||||
let response: T | undefined = undefined;
|
|
||||||
let statusCode: number | undefined = undefined;
|
|
||||||
let isRetryable = false;
|
|
||||||
let errorMessage = "";
|
|
||||||
let attempt = 1;
|
|
||||||
|
|
||||||
while (attempt <= maxAttempts) {
|
|
||||||
try {
|
|
||||||
response = await method();
|
|
||||||
statusCode = getStatusCode(response);
|
|
||||||
|
|
||||||
if (!isServerErrorStatusCode(statusCode)) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
isRetryable = isRetryableStatusCode(statusCode);
|
|
||||||
errorMessage = `Cache service responded with ${statusCode}`;
|
|
||||||
} catch (error) {
|
|
||||||
isRetryable = true;
|
|
||||||
errorMessage = error.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.debug(
|
|
||||||
`${name} - Attempt ${attempt} of ${maxAttempts} failed with error: ${errorMessage}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isRetryable) {
|
|
||||||
core.debug(`${name} - Error is not retryable`);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
attempt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw Error(`${name} failed: ${errorMessage}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function retryTypedResponse<T>(
|
|
||||||
name: string,
|
|
||||||
method: () => Promise<ITypedResponse<T>>,
|
|
||||||
maxAttempts = 2
|
|
||||||
): Promise<ITypedResponse<T>> {
|
|
||||||
return await retry(
|
|
||||||
name,
|
|
||||||
method,
|
|
||||||
(response: ITypedResponse<T>) => response.statusCode,
|
|
||||||
maxAttempts
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function retryHttpClientResponse<T>(
|
|
||||||
name: string,
|
|
||||||
method: () => Promise<IHttpClientResponse>,
|
|
||||||
maxAttempts = 2
|
|
||||||
): Promise<IHttpClientResponse> {
|
|
||||||
return await retry(
|
|
||||||
name,
|
|
||||||
method,
|
|
||||||
(response: IHttpClientResponse) => response.message.statusCode,
|
|
||||||
maxAttempts
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getCacheEntry(
|
export async function getCacheEntry(
|
||||||
keys: string[],
|
keys: string[],
|
||||||
options?: CacheOptions
|
options?: CacheOptions
|
||||||
@ -185,13 +117,15 @@ export async function getCacheEntry(
|
|||||||
keys.join(",")
|
keys.join(",")
|
||||||
)}&version=${version}`;
|
)}&version=${version}`;
|
||||||
|
|
||||||
const response = await retryTypedResponse("getCacheEntry", () =>
|
const response = await httpClient.getJson<ArtifactCacheEntry>(
|
||||||
httpClient.getJson<ArtifactCacheEntry>(getCacheApiUrl(resource))
|
getCacheApiUrl(resource)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode === 204) {
|
if (response.statusCode === 204) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!isSuccessStatusCode(response.statusCode)) {
|
||||||
|
throw new Error(`Cache service responded with ${response.statusCode}`);
|
||||||
|
}
|
||||||
|
|
||||||
const cacheResult = response.result;
|
const cacheResult = response.result;
|
||||||
const cacheDownloadUrl = cacheResult?.archiveLocation;
|
const cacheDownloadUrl = cacheResult?.archiveLocation;
|
||||||
@ -219,16 +153,15 @@ export async function downloadCache(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const stream = fs.createWriteStream(archivePath);
|
const stream = fs.createWriteStream(archivePath);
|
||||||
const httpClient = new HttpClient("actions/cache");
|
const httpClient = new HttpClient("actions/cache");
|
||||||
const downloadResponse = await retryHttpClientResponse(
|
const downloadResponse = await httpClient.get(archiveLocation);
|
||||||
"downloadCache",
|
|
||||||
() => httpClient.get(archiveLocation)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Abort download if no traffic received over the socket.
|
// Abort download if no traffic received over the socket.
|
||||||
downloadResponse.message.socket.setTimeout(SocketTimeout, () => {
|
const socketTimeout =
|
||||||
|
parseEnvNumber("CACHE_SOCKET_TIMEOUT") ?? DefaultSocketTimeout;
|
||||||
|
downloadResponse.message.socket.setTimeout(socketTimeout, () => {
|
||||||
downloadResponse.message.destroy();
|
downloadResponse.message.destroy();
|
||||||
core.debug(
|
core.debug(
|
||||||
`Aborting download, socket timed out after ${SocketTimeout} ms`
|
`Aborting download, socket timed out after ${socketTimeout} ms`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -264,13 +197,10 @@ export async function reserveCache(
|
|||||||
key,
|
key,
|
||||||
version
|
version
|
||||||
};
|
};
|
||||||
const response = await retryTypedResponse("reserveCache", () =>
|
const response = await httpClient.postJson<ReserveCacheResponse>(
|
||||||
httpClient.postJson<ReserveCacheResponse>(
|
getCacheApiUrl("caches"),
|
||||||
getCacheApiUrl("caches"),
|
reserveCacheRequest
|
||||||
reserveCacheRequest
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return response?.result?.cacheId ?? -1;
|
return response?.result?.cacheId ?? -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,7 +216,7 @@ function getContentRange(start: number, end: number): string {
|
|||||||
async function uploadChunk(
|
async function uploadChunk(
|
||||||
httpClient: HttpClient,
|
httpClient: HttpClient,
|
||||||
resourceUrl: string,
|
resourceUrl: string,
|
||||||
openStream: () => NodeJS.ReadableStream,
|
data: NodeJS.ReadableStream,
|
||||||
start: number,
|
start: number,
|
||||||
end: number
|
end: number
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
@ -307,23 +237,29 @@ async function uploadChunk(
|
|||||||
return await httpClient.sendStream(
|
return await httpClient.sendStream(
|
||||||
"PATCH",
|
"PATCH",
|
||||||
resourceUrl,
|
resourceUrl,
|
||||||
openStream(),
|
data,
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
await retryHttpClientResponse(
|
const response = await uploadChunkRequest();
|
||||||
`uploadChunk (start: ${start}, end: ${end})`,
|
if (isSuccessStatusCode(response.message.statusCode)) {
|
||||||
uploadChunkRequest
|
return;
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseEnvNumber(key: string): number | undefined {
|
|
||||||
const value = Number(process.env[key]);
|
|
||||||
if (Number.isNaN(value) || value < 0) {
|
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
|
if (isRetryableStatusCode(response.message.statusCode)) {
|
||||||
|
core.debug(
|
||||||
|
`Received ${response.message.statusCode}, retrying chunk at offset ${start}.`
|
||||||
|
);
|
||||||
|
const retryResponse = await uploadChunkRequest();
|
||||||
|
if (isSuccessStatusCode(retryResponse.message.statusCode)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Cache service responded with ${response.message.statusCode} during chunk upload.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadFile(
|
async function uploadFile(
|
||||||
@ -356,17 +292,17 @@ async function uploadFile(
|
|||||||
const start = offset;
|
const start = offset;
|
||||||
const end = offset + chunkSize - 1;
|
const end = offset + chunkSize - 1;
|
||||||
offset += MAX_CHUNK_SIZE;
|
offset += MAX_CHUNK_SIZE;
|
||||||
|
const chunk = fs.createReadStream(archivePath, {
|
||||||
|
fd,
|
||||||
|
start,
|
||||||
|
end,
|
||||||
|
autoClose: false
|
||||||
|
});
|
||||||
|
|
||||||
await uploadChunk(
|
await uploadChunk(
|
||||||
httpClient,
|
httpClient,
|
||||||
resourceUrl,
|
resourceUrl,
|
||||||
() =>
|
chunk,
|
||||||
fs.createReadStream(archivePath, {
|
|
||||||
fd,
|
|
||||||
start,
|
|
||||||
end,
|
|
||||||
autoClose: false
|
|
||||||
}),
|
|
||||||
start,
|
start,
|
||||||
end
|
end
|
||||||
);
|
);
|
||||||
@ -385,11 +321,9 @@ async function commitCache(
|
|||||||
filesize: number
|
filesize: number
|
||||||
): Promise<ITypedResponse<null>> {
|
): Promise<ITypedResponse<null>> {
|
||||||
const commitCacheRequest: CommitCacheRequest = { size: filesize };
|
const commitCacheRequest: CommitCacheRequest = { size: filesize };
|
||||||
return await retryTypedResponse("commitCache", () =>
|
return await httpClient.postJson<null>(
|
||||||
httpClient.postJson<null>(
|
getCacheApiUrl(`caches/${cacheId.toString()}`),
|
||||||
getCacheApiUrl(`caches/${cacheId.toString()}`),
|
commitCacheRequest
|
||||||
commitCacheRequest
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,4 +32,4 @@ export enum CompressionMethod {
|
|||||||
// Socket timeout in milliseconds during download. If no traffic is received
|
// Socket timeout in milliseconds during download. If no traffic is received
|
||||||
// over the socket during this period, the socket is destroyed and the download
|
// over the socket during this period, the socket is destroyed and the download
|
||||||
// is aborted.
|
// is aborted.
|
||||||
export const SocketTimeout = 5000;
|
export const DefaultSocketTimeout = 5000;
|
||||||
|
@ -3,7 +3,6 @@ import * as exec from "@actions/exec";
|
|||||||
import * as glob from "@actions/glob";
|
import * as glob from "@actions/glob";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as os from "os";
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as util from "util";
|
import * as util from "util";
|
||||||
import * as uuidV4 from "uuid/v4";
|
import * as uuidV4 from "uuid/v4";
|
||||||
@ -149,11 +148,6 @@ async function getVersion(app: string): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
export async function getCompressionMethod(): Promise<CompressionMethod> {
|
||||||
// Disabling zstd on Windows due to https://github.com/actions/cache/issues/301
|
|
||||||
if (os.platform() === "win32") {
|
|
||||||
return CompressionMethod.Gzip;
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionOutput = await getVersion("zstd");
|
const versionOutput = await getVersion("zstd");
|
||||||
return versionOutput.toLowerCase().includes("zstd command line interface")
|
return versionOutput.toLowerCase().includes("zstd command line interface")
|
||||||
? CompressionMethod.Zstd
|
? CompressionMethod.Zstd
|
||||||
|
Reference in New Issue
Block a user