Fix connection errors if a retry is encountered (#82)

* Use @actions/artifact 0.3.2

* setFailed if certain items don't upload

* Update verion #
This commit is contained in:
Konrad Pabjan 2020-05-18 15:43:29 +02:00 committed by GitHub
parent 9bcc1e21d0
commit 97b7dace6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 131 additions and 80 deletions

175
dist/index.js vendored

@ -2563,7 +2563,9 @@ class BasicCredentialHandler {
this.password = password; this.password = password;
} }
prepareRequest(options) { prepareRequest(options) {
options.headers['Authorization'] = 'Basic ' + Buffer.from(this.username + ':' + this.password).toString('base64'); options.headers['Authorization'] =
'Basic ' +
Buffer.from(this.username + ':' + this.password).toString('base64');
} }
// This handler cannot handle 401 // This handler cannot handle 401
canHandleAuthentication(response) { canHandleAuthentication(response) {
@ -2599,7 +2601,8 @@ 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'] = 'Basic ' + Buffer.from('PAT:' + this.token).toString('base64'); options.headers['Authorization'] =
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
} }
// This handler cannot handle 401 // This handler cannot handle 401
canHandleAuthentication(response) { canHandleAuthentication(response) {
@ -3784,7 +3787,6 @@ class DefaultArtifactClient {
}); });
} }
downloadArtifact(name, path, options) { downloadArtifact(name, path, options) {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const downloadHttpClient = new download_http_client_1.DownloadHttpClient(); const downloadHttpClient = new download_http_client_1.DownloadHttpClient();
const artifacts = yield downloadHttpClient.listArtifacts(); const artifacts = yield downloadHttpClient.listArtifacts();
@ -3804,7 +3806,7 @@ class DefaultArtifactClient {
path = path_1.normalize(path); path = path_1.normalize(path);
path = path_1.resolve(path); path = path_1.resolve(path);
// During upload, empty directories are rejected by the remote server so there should be no artifacts that consist of only empty directories // During upload, empty directories are rejected by the remote server so there should be no artifacts that consist of only empty directories
const downloadSpecification = download_specification_1.getDownloadSpecification(name, items.value, path, ((_a = options) === null || _a === void 0 ? void 0 : _a.createArtifactFolder) || false); const downloadSpecification = download_specification_1.getDownloadSpecification(name, items.value, path, (options === null || options === void 0 ? void 0 : options.createArtifactFolder) || false);
if (downloadSpecification.filesToDownload.length === 0) { if (downloadSpecification.filesToDownload.length === 0) {
core.info(`No downloadable files were found for the artifact: ${artifactToDownload.name}`); core.info(`No downloadable files were found for the artifact: ${artifactToDownload.name}`);
} }
@ -4001,10 +4003,15 @@ function run() {
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`); core.debug(`Root artifact directory is ${searchResult.rootDirectory}`);
const artifactClient = artifact_1.create(); const artifactClient = artifact_1.create();
const options = { const options = {
continueOnError: true continueOnError: false
}; };
yield artifactClient.uploadArtifact(name || constants_1.getDefaultArtifactName(), searchResult.filesToUpload, searchResult.rootDirectory, options); const uploadResponse = yield artifactClient.uploadArtifact(name || constants_1.getDefaultArtifactName(), searchResult.filesToUpload, searchResult.rootDirectory, options);
core.info('Artifact upload has finished successfully!'); if (uploadResponse.failedItems.length > 0) {
core.setFailed(`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`);
}
else {
core.info(`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`);
}
} }
} }
catch (err) { catch (err) {
@ -5340,8 +5347,18 @@ function getProxyUrl(serverUrl) {
return proxyUrl ? proxyUrl.href : ''; return proxyUrl ? proxyUrl.href : '';
} }
exports.getProxyUrl = getProxyUrl; exports.getProxyUrl = getProxyUrl;
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect]; const HttpRedirectCodes = [
const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout]; HttpCodes.MovedPermanently,
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;
@ -5466,18 +5483,22 @@ 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) ? this._maxRetries + 1 : 1; let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -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 && response.message && response.message.statusCode === HttpCodes.Unauthorized) { if (response &&
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)) {
@ -5495,21 +5516,32 @@ 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:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) { if (parsedUrl.protocol == 'https:' &&
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."); parsedUrl.protocol != parsedRedirectUrl.protocol &&
!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);
@ -5560,8 +5592,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) => {
@ -5574,7 +5606,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
@ -5589,10 +5621,10 @@ class HttpClient {
// res should have headers // res should have headers
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();
}); });
@ -5619,31 +5651,34 @@ 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 ? parseInt(info.parsedUrl.port) : defaultPort; info.options.port = info.parsedUrl.port
info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || ''); ? parseInt(info.parsedUrl.port)
: 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];
@ -5681,7 +5716,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:';
@ -5708,7 +5743,9 @@ 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 || {}, { rejectUnauthorized: false }); agent.options = Object.assign(agent.options || {}, {
rejectUnauthorized: false
});
} }
return agent; return agent;
} }
@ -5769,7 +5806,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
@ -6516,8 +6553,8 @@ class UploadHttpClient {
const artifactUrl = utils_1.getArtifactUrl(); const artifactUrl = utils_1.getArtifactUrl();
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately // use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
const client = this.uploadHttpManager.getClient(0); const client = this.uploadHttpManager.getClient(0);
const requestOptions = utils_1.getUploadRequestOptions('application/json', false); const headers = utils_1.getUploadHeaders('application/json', false);
const rawResponse = yield client.post(artifactUrl, data, requestOptions); const rawResponse = yield client.post(artifactUrl, data, headers);
const body = yield rawResponse.readBody(); const body = yield rawResponse.readBody();
if (utils_1.isSuccessStatusCode(rawResponse.message.statusCode) && body) { if (utils_1.isSuccessStatusCode(rawResponse.message.statusCode) && body) {
return JSON.parse(body); return JSON.parse(body);
@ -6629,21 +6666,25 @@ class UploadHttpClient {
// for creating a new GZip file, an in-memory buffer is used for compression // for creating a new GZip file, an in-memory buffer is used for compression
if (totalFileSize < 65536) { if (totalFileSize < 65536) {
const buffer = yield upload_gzip_1.createGZipFileInBuffer(parameters.file); const buffer = yield upload_gzip_1.createGZipFileInBuffer(parameters.file);
let uploadStream; //An open stream is needed in the event of a failure and we need to retry. If a NodeJS.ReadableStream is directly passed in,
// it will not properly get reset to the start of the stream if a chunk upload needs to be retried
let openUploadStream;
if (totalFileSize < buffer.byteLength) { if (totalFileSize < buffer.byteLength) {
// compression did not help with reducing the size, use a readable stream from the original file for upload // compression did not help with reducing the size, use a readable stream from the original file for upload
uploadStream = fs.createReadStream(parameters.file); openUploadStream = () => fs.createReadStream(parameters.file);
isGzip = false; isGzip = false;
uploadFileSize = totalFileSize; uploadFileSize = totalFileSize;
} }
else { else {
// create a readable stream using a PassThrough stream that is both readable and writable // create a readable stream using a PassThrough stream that is both readable and writable
openUploadStream = () => {
const passThrough = new stream.PassThrough(); const passThrough = new stream.PassThrough();
passThrough.end(buffer); passThrough.end(buffer);
uploadStream = passThrough; return passThrough;
};
uploadFileSize = buffer.byteLength; uploadFileSize = buffer.byteLength;
} }
const result = yield this.uploadChunk(httpClientIndex, parameters.resourceUrl, uploadStream, 0, uploadFileSize - 1, uploadFileSize, isGzip, totalFileSize); const result = yield this.uploadChunk(httpClientIndex, parameters.resourceUrl, openUploadStream, 0, uploadFileSize - 1, uploadFileSize, isGzip, totalFileSize);
if (!result) { if (!result) {
// chunk failed to upload // chunk failed to upload
isUploadSuccessful = false; isUploadSuccessful = false;
@ -6685,7 +6726,7 @@ class UploadHttpClient {
failedChunkSizes += chunkSize; failedChunkSizes += chunkSize;
continue; continue;
} }
const result = yield this.uploadChunk(httpClientIndex, parameters.resourceUrl, fs.createReadStream(uploadFilePath, { const result = yield this.uploadChunk(httpClientIndex, parameters.resourceUrl, () => fs.createReadStream(uploadFilePath, {
start, start,
end, end,
autoClose: false autoClose: false
@ -6715,7 +6756,7 @@ class UploadHttpClient {
* indicates a retryable status, we try to upload the chunk as well * indicates a retryable status, we try to upload the chunk as well
* @param {number} httpClientIndex The index of the httpClient being used to make all the necessary calls * @param {number} httpClientIndex The index of the httpClient being used to make all the necessary calls
* @param {string} resourceUrl Url of the resource that the chunk will be uploaded to * @param {string} resourceUrl Url of the resource that the chunk will be uploaded to
* @param {NodeJS.ReadableStream} data Stream of the file that will be uploaded * @param {NodeJS.ReadableStream} openStream Stream of the file that will be uploaded
* @param {number} start Starting byte index of file that the chunk belongs to * @param {number} start Starting byte index of file that the chunk belongs to
* @param {number} end Ending byte index of file that the chunk belongs to * @param {number} end Ending byte index of file that the chunk belongs to
* @param {number} uploadFileSize Total size of the file in bytes that is being uploaded * @param {number} uploadFileSize Total size of the file in bytes that is being uploaded
@ -6723,13 +6764,13 @@ class UploadHttpClient {
* @param {number} totalFileSize Original total size of the file that is being uploaded * @param {number} totalFileSize Original total size of the file that is being uploaded
* @returns if the chunk was successfully uploaded * @returns if the chunk was successfully uploaded
*/ */
uploadChunk(httpClientIndex, resourceUrl, data, start, end, uploadFileSize, isGzip, totalFileSize) { uploadChunk(httpClientIndex, resourceUrl, openStream, start, end, uploadFileSize, isGzip, totalFileSize) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// prepare all the necessary headers before making any http call // prepare all the necessary headers before making any http call
const requestOptions = utils_1.getUploadRequestOptions('application/octet-stream', true, isGzip, totalFileSize, end - start + 1, utils_1.getContentRange(start, end, uploadFileSize)); const headers = utils_1.getUploadHeaders('application/octet-stream', true, isGzip, totalFileSize, end - start + 1, utils_1.getContentRange(start, end, uploadFileSize));
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () { const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
const client = this.uploadHttpManager.getClient(httpClientIndex); const client = this.uploadHttpManager.getClient(httpClientIndex);
return yield client.sendStream('PUT', resourceUrl, data, requestOptions); return yield client.sendStream('PUT', resourceUrl, openStream(), headers);
}); });
let retryCount = 0; let retryCount = 0;
const retryLimit = config_variables_1.getRetryLimit(); const retryLimit = config_variables_1.getRetryLimit();
@ -6807,7 +6848,7 @@ class UploadHttpClient {
*/ */
patchArtifactSize(size, artifactName) { patchArtifactSize(size, artifactName) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const requestOptions = utils_1.getUploadRequestOptions('application/json', false); const headers = utils_1.getUploadHeaders('application/json', false);
const resourceUrl = new url_1.URL(utils_1.getArtifactUrl()); const resourceUrl = new url_1.URL(utils_1.getArtifactUrl());
resourceUrl.searchParams.append('artifactName', artifactName); resourceUrl.searchParams.append('artifactName', artifactName);
const parameters = { Size: size }; const parameters = { Size: size };
@ -6815,7 +6856,7 @@ class UploadHttpClient {
core.debug(`URL is ${resourceUrl.toString()}`); core.debug(`URL is ${resourceUrl.toString()}`);
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately // use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
const client = this.uploadHttpManager.getClient(0); const client = this.uploadHttpManager.getClient(0);
const response = yield client.patch(resourceUrl.toString(), data, requestOptions); const response = yield client.patch(resourceUrl.toString(), data, headers);
const body = yield response.readBody(); const body = yield response.readBody();
if (utils_1.isSuccessStatusCode(response.message.statusCode)) { if (utils_1.isSuccessStatusCode(response.message.statusCode)) {
core.debug(`Artifact ${artifactName} has been successfully uploaded, total size in bytes: ${size}`); core.debug(`Artifact ${artifactName} has been successfully uploaded, total size in bytes: ${size}`);
@ -7248,8 +7289,8 @@ class DownloadHttpClient {
const artifactUrl = utils_1.getArtifactUrl(); const artifactUrl = utils_1.getArtifactUrl();
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately // use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
const client = this.downloadHttpManager.getClient(0); const client = this.downloadHttpManager.getClient(0);
const requestOptions = utils_1.getDownloadRequestOptions('application/json'); const headers = utils_1.getDownloadHeaders('application/json');
const response = yield client.get(artifactUrl, requestOptions); const response = yield client.get(artifactUrl, headers);
const body = yield response.readBody(); const body = yield response.readBody();
if (utils_1.isSuccessStatusCode(response.message.statusCode) && body) { if (utils_1.isSuccessStatusCode(response.message.statusCode) && body) {
return JSON.parse(body); return JSON.parse(body);
@ -7270,8 +7311,8 @@ class DownloadHttpClient {
resourceUrl.searchParams.append('itemPath', artifactName); resourceUrl.searchParams.append('itemPath', artifactName);
// use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately // use the first client from the httpManager, `keep-alive` is not used so the connection will close immediately
const client = this.downloadHttpManager.getClient(0); const client = this.downloadHttpManager.getClient(0);
const requestOptions = utils_1.getDownloadRequestOptions('application/json'); const headers = utils_1.getDownloadHeaders('application/json');
const response = yield client.get(resourceUrl.toString(), requestOptions); const response = yield client.get(resourceUrl.toString(), headers);
const body = yield response.readBody(); const body = yield response.readBody();
if (utils_1.isSuccessStatusCode(response.message.statusCode) && body) { if (utils_1.isSuccessStatusCode(response.message.statusCode) && body) {
return JSON.parse(body); return JSON.parse(body);
@ -7328,15 +7369,16 @@ class DownloadHttpClient {
let retryCount = 0; let retryCount = 0;
const retryLimit = config_variables_1.getRetryLimit(); const retryLimit = config_variables_1.getRetryLimit();
const destinationStream = fs.createWriteStream(downloadPath); const destinationStream = fs.createWriteStream(downloadPath);
const requestOptions = utils_1.getDownloadRequestOptions('application/json', true, true); const headers = utils_1.getDownloadHeaders('application/json', true, true);
// a single GET request is used to download a file // a single GET request is used to download a file
const makeDownloadRequest = () => __awaiter(this, void 0, void 0, function* () { const makeDownloadRequest = () => __awaiter(this, void 0, void 0, function* () {
const client = this.downloadHttpManager.getClient(httpClientIndex); const client = this.downloadHttpManager.getClient(httpClientIndex);
return yield client.get(artifactLocation, requestOptions); return yield client.get(artifactLocation, headers);
}); });
// check the response headers to determine if the file was compressed using gzip // check the response headers to determine if the file was compressed using gzip
const isGzip = (headers) => { const isGzip = (incomingHeaders) => {
return ('content-encoding' in headers && headers['content-encoding'] === 'gzip'); return ('content-encoding' in incomingHeaders &&
incomingHeaders['content-encoding'] === 'gzip');
}; };
// Increments the current retry count and then checks if the retry limit has been reached // Increments the current retry count and then checks if the retry limit has been reached
// If there have been too many retries, fail so the download stops. If there is a retryAfterValue value provided, // If there have been too many retries, fail so the download stops. If there is a retryAfterValue value provided,
@ -7812,9 +7854,9 @@ exports.getContentRange = getContentRange;
* @param {boolean} isKeepAlive is the same connection being used to make multiple calls * @param {boolean} isKeepAlive is the same connection being used to make multiple calls
* @param {boolean} acceptGzip can we accept a gzip encoded response * @param {boolean} acceptGzip can we accept a gzip encoded response
* @param {string} acceptType the type of content that we can accept * @param {string} acceptType the type of content that we can accept
* @returns appropriate request options to make a specific http call during artifact download * @returns appropriate headers to make a specific http call during artifact download
*/ */
function getDownloadRequestOptions(contentType, isKeepAlive, acceptGzip) { function getDownloadHeaders(contentType, isKeepAlive, acceptGzip) {
const requestOptions = {}; const requestOptions = {};
if (contentType) { if (contentType) {
requestOptions['Content-Type'] = contentType; requestOptions['Content-Type'] = contentType;
@ -7835,7 +7877,7 @@ function getDownloadRequestOptions(contentType, isKeepAlive, acceptGzip) {
} }
return requestOptions; return requestOptions;
} }
exports.getDownloadRequestOptions = getDownloadRequestOptions; exports.getDownloadHeaders = getDownloadHeaders;
/** /**
* Sets all the necessary headers when uploading an artifact * Sets all the necessary headers when uploading an artifact
* @param {string} contentType the type of content being uploaded * @param {string} contentType the type of content being uploaded
@ -7844,9 +7886,9 @@ exports.getDownloadRequestOptions = getDownloadRequestOptions;
* @param {number} uncompressedLength the original size of the content if something is being uploaded that has been compressed * @param {number} uncompressedLength the original size of the content if something is being uploaded that has been compressed
* @param {number} contentLength the length of the content that is being uploaded * @param {number} contentLength the length of the content that is being uploaded
* @param {string} contentRange the range of the content that is being uploaded * @param {string} contentRange the range of the content that is being uploaded
* @returns appropriate request options to make a specific http call during artifact upload * @returns appropriate headers to make a specific http call during artifact upload
*/ */
function getUploadRequestOptions(contentType, isKeepAlive, isGzip, uncompressedLength, contentLength, contentRange) { function getUploadHeaders(contentType, isKeepAlive, isGzip, uncompressedLength, contentLength, contentRange) {
const requestOptions = {}; const requestOptions = {};
requestOptions['Accept'] = `application/json;api-version=${getApiVersion()}`; requestOptions['Accept'] = `application/json;api-version=${getApiVersion()}`;
if (contentType) { if (contentType) {
@ -7869,9 +7911,9 @@ function getUploadRequestOptions(contentType, isKeepAlive, isGzip, uncompressedL
} }
return requestOptions; return requestOptions;
} }
exports.getUploadRequestOptions = getUploadRequestOptions; exports.getUploadHeaders = getUploadHeaders;
function createHttpClient() { function createHttpClient() {
return new http_client_1.HttpClient('action/artifact', [ return new http_client_1.HttpClient('actions/artifact', [
new auth_1.BearerCredentialHandler(config_variables_1.getRuntimeToken()) new auth_1.BearerCredentialHandler(config_variables_1.getRuntimeToken())
]); ]);
} }
@ -8291,12 +8333,10 @@ function getProxyUrl(reqUrl) {
} }
let proxyVar; let proxyVar;
if (usingSsl) { if (usingSsl) {
proxyVar = process.env["https_proxy"] || proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
process.env["HTTPS_PROXY"];
} }
else { else {
proxyVar = process.env["http_proxy"] || proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
process.env["HTTP_PROXY"];
} }
if (proxyVar) { if (proxyVar) {
proxyUrl = url.parse(proxyVar); proxyUrl = url.parse(proxyVar);
@ -8308,7 +8348,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;
} }
@ -8329,7 +8369,10 @@ 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.split(',').map(x => x.trim().toUpperCase()).filter(x => x)) { for (let upperNoProxyItem of noProxy
.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;
} }

14
package-lock.json generated

@ -1,13 +1,13 @@
{ {
"name": "upload-artifact", "name": "upload-artifact",
"version": "2.0.0", "version": "2.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@actions/artifact": { "@actions/artifact": {
"version": "0.3.1", "version": "0.3.2",
"resolved": "https://registry.npmjs.org/@actions/artifact/-/artifact-0.3.1.tgz", "resolved": "https://registry.npmjs.org/@actions/artifact/-/artifact-0.3.2.tgz",
"integrity": "sha512-czRvOioOpuvmF/qDevfVVpZeBt7pjYlrnmM1+tRuCpKJxjWFYgi5MIW7TfscyupXPvtJz9jIxMjvxy9Eug1QEA==", "integrity": "sha512-KzUe5DEeVXprAodxfGKtx9f7ukuVKE6V6pge6t5GDGk0cdkfiMEfahoq7HfBsOsmVy4J7rr1YZQPUTvXveYinw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@actions/core": "^1.2.1", "@actions/core": "^1.2.1",
@ -6520,9 +6520,9 @@
} }
}, },
"tmp-promise": { "tmp-promise": {
"version": "2.0.2", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-2.0.2.tgz", "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-2.1.1.tgz",
"integrity": "sha512-zl71nFWjPKW2KXs+73gEk8RmqvtAeXPxhWDkTUoa3MSMkjq3I+9OeknjF178MQoMYsdqL730hfzvNfEkePxq9Q==", "integrity": "sha512-Z048AOz/w9b6lCbJUpevIJpRpUztENl8zdv1bmAKVHimfqRFl92ROkmT9rp7TVBnrEw2gtMTol/2Cp2S2kJa4Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"tmp": "0.1.0" "tmp": "0.1.0"

@ -1,6 +1,6 @@
{ {
"name": "upload-artifact", "name": "upload-artifact",
"version": "2.0.0", "version": "2.0.1",
"description": "Upload a build artifact that can be used by subsequent workflow steps", "description": "Upload a build artifact that can be used by subsequent workflow steps",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
@ -29,7 +29,7 @@
}, },
"homepage": "https://github.com/actions/upload-artifact#readme", "homepage": "https://github.com/actions/upload-artifact#readme",
"devDependencies": { "devDependencies": {
"@actions/artifact": "^0.3.1", "@actions/artifact": "^0.3.2",
"@actions/core": "^1.2.3", "@actions/core": "^1.2.3",
"@actions/glob": "^0.1.0", "@actions/glob": "^0.1.0",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",

@ -21,16 +21,24 @@ async function run(): Promise<void> {
const artifactClient = create() const artifactClient = create()
const options: UploadOptions = { const options: UploadOptions = {
continueOnError: true continueOnError: false
} }
await artifactClient.uploadArtifact( const uploadResponse = await artifactClient.uploadArtifact(
name || getDefaultArtifactName(), name || getDefaultArtifactName(),
searchResult.filesToUpload, searchResult.filesToUpload,
searchResult.rootDirectory, searchResult.rootDirectory,
options options
) )
core.info('Artifact upload has finished successfully!') if (uploadResponse.failedItems.length > 0) {
core.setFailed(
`An error was encountered when uploading ${uploadResponse.artifactName}. There were ${uploadResponse.failedItems.length} items that failed to upload.`
)
} else {
core.info(
`Artifact ${uploadResponse.artifactName} has been successfully uploaded!`
)
}
} }
} catch (err) { } catch (err) {
core.setFailed(err.message) core.setFailed(err.message)