@@ -3208,9 +3208,12 @@ const os = __importStar(__webpack_require__(87));
32083208const path = __importStar ( __webpack_require__ ( 622 ) ) ;
32093209const httpm = __importStar ( __webpack_require__ ( 539 ) ) ;
32103210const semver = __importStar ( __webpack_require__ ( 280 ) ) ;
3211+ const stream = __importStar ( __webpack_require__ ( 794 ) ) ;
3212+ const util = __importStar ( __webpack_require__ ( 669 ) ) ;
32113213const v4_1 = __importDefault ( __webpack_require__ ( 826 ) ) ;
32123214const exec_1 = __webpack_require__ ( 986 ) ;
32133215const assert_1 = __webpack_require__ ( 357 ) ;
3216+ const retry_helper_1 = __webpack_require__ ( 979 ) ;
32143217class HTTPError extends Error {
32153218 constructor ( httpStatusCode ) {
32163219 super ( `Unexpected HTTP response: ${ httpStatusCode } ` ) ;
@@ -3255,52 +3258,58 @@ if (!tempDirectory || !cacheRoot) {
32553258 */
32563259function downloadTool ( url , dest ) {
32573260 return __awaiter ( this , void 0 , void 0 , function * ( ) {
3258- // Wrap in a promise so that we can resolve from within stream callbacks
3259- return new Promise ( ( resolve , reject ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
3260- try {
3261- const http = new httpm . HttpClient ( userAgent , [ ] , {
3262- allowRetries : true ,
3263- maxRetries : 3
3264- } ) ;
3265- dest = dest || path . join ( tempDirectory , v4_1 . default ( ) ) ;
3266- yield io . mkdirP ( path . dirname ( dest ) ) ;
3267- core . debug ( `Downloading ${ url } ` ) ;
3268- core . debug ( `Downloading ${ dest } ` ) ;
3269- if ( fs . existsSync ( dest ) ) {
3270- throw new Error ( `Destination file path ${ dest } already exists` ) ;
3261+ dest = dest || path . join ( tempDirectory , v4_1 . default ( ) ) ;
3262+ yield io . mkdirP ( path . dirname ( dest ) ) ;
3263+ core . debug ( `Downloading ${ url } ` ) ;
3264+ core . debug ( `Destination ${ dest } ` ) ;
3265+ const maxAttempts = 3 ;
3266+ const minSeconds = getGlobal ( 'TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS' , 10 ) ;
3267+ const maxSeconds = getGlobal ( 'TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS' , 20 ) ;
3268+ const retryHelper = new retry_helper_1 . RetryHelper ( maxAttempts , minSeconds , maxSeconds ) ;
3269+ return yield retryHelper . execute ( ( ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return yield downloadToolAttempt ( url , dest || '' ) ; } ) ) ;
3270+ } ) ;
3271+ }
3272+ exports . downloadTool = downloadTool ;
3273+ function downloadToolAttempt ( url , dest ) {
3274+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
3275+ if ( fs . existsSync ( dest ) ) {
3276+ throw new Error ( `Destination file path ${ dest } already exists` ) ;
3277+ }
3278+ // Get the response headers
3279+ const http = new httpm . HttpClient ( userAgent , [ ] , {
3280+ allowRetries : false
3281+ } ) ;
3282+ const response = yield http . get ( url ) ;
3283+ if ( response . message . statusCode !== 200 ) {
3284+ const err = new HTTPError ( response . message . statusCode ) ;
3285+ core . debug ( `Failed to download from "${ url } ". Code(${ response . message . statusCode } ) Message(${ response . message . statusMessage } )` ) ;
3286+ throw err ;
3287+ }
3288+ // Download the response body
3289+ const pipeline = util . promisify ( stream . pipeline ) ;
3290+ const responseMessageFactory = getGlobal ( 'TEST_DOWNLOAD_TOOL_RESPONSE_MESSAGE_FACTORY' , ( ) => response . message ) ;
3291+ const readStream = responseMessageFactory ( ) ;
3292+ let succeeded = false ;
3293+ try {
3294+ yield pipeline ( readStream , fs . createWriteStream ( dest ) ) ;
3295+ core . debug ( 'download complete' ) ;
3296+ succeeded = true ;
3297+ return dest ;
3298+ }
3299+ finally {
3300+ // Error, delete dest before retry
3301+ if ( ! succeeded ) {
3302+ core . debug ( 'download failed' ) ;
3303+ try {
3304+ yield io . rmRF ( dest ) ;
32713305 }
3272- const response = yield http . get ( url ) ;
3273- if ( response . message . statusCode !== 200 ) {
3274- const err = new HTTPError ( response . message . statusCode ) ;
3275- core . debug ( `Failed to download from "${ url } ". Code(${ response . message . statusCode } ) Message(${ response . message . statusMessage } )` ) ;
3276- throw err ;
3306+ catch ( err ) {
3307+ core . debug ( `Failed to delete '${ dest } '. ${ err . message } ` ) ;
32773308 }
3278- const file = fs . createWriteStream ( dest ) ;
3279- file . on ( 'open' , ( ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
3280- try {
3281- const stream = response . message . pipe ( file ) ;
3282- stream . on ( 'close' , ( ) => {
3283- core . debug ( 'download complete' ) ;
3284- resolve ( dest ) ;
3285- } ) ;
3286- }
3287- catch ( err ) {
3288- core . debug ( `Failed to download from "${ url } ". Code(${ response . message . statusCode } ) Message(${ response . message . statusMessage } )` ) ;
3289- reject ( err ) ;
3290- }
3291- } ) ) ;
3292- file . on ( 'error' , err => {
3293- file . end ( ) ;
3294- reject ( err ) ;
3295- } ) ;
32963309 }
3297- catch ( err ) {
3298- reject ( err ) ;
3299- }
3300- } ) ) ;
3310+ }
33013311 } ) ;
33023312}
3303- exports . downloadTool = downloadTool ;
33043313/**
33053314 * Extract a .7z file
33063315 *
@@ -3390,14 +3399,17 @@ function extractTar(file, dest, flags = 'xz') {
33903399 // Create dest
33913400 dest = yield _createExtractFolder ( dest ) ;
33923401 // Determine whether GNU tar
3402+ core . debug ( 'Checking tar --version' ) ;
33933403 let versionOutput = '' ;
33943404 yield exec_1 . exec ( 'tar --version' , [ ] , {
33953405 ignoreReturnCode : true ,
3406+ silent : true ,
33963407 listeners : {
33973408 stdout : ( data ) => ( versionOutput += data . toString ( ) ) ,
33983409 stderr : ( data ) => ( versionOutput += data . toString ( ) )
33993410 }
34003411 } ) ;
3412+ core . debug ( versionOutput . trim ( ) ) ;
34013413 const isGnuTar = versionOutput . toUpperCase ( ) . includes ( 'GNU TAR' ) ;
34023414 // Initialize args
34033415 const args = [ flags ] ;
@@ -3654,6 +3666,15 @@ function _evaluateVersions(versions, versionSpec) {
36543666 }
36553667 return version ;
36563668}
3669+ /**
3670+ * Gets a global variable
3671+ */
3672+ function getGlobal ( key , defaultValue ) {
3673+ /* eslint-disable @typescript-eslint/no-explicit-any */
3674+ const value = global [ key ] ;
3675+ /* eslint-enable @typescript-eslint/no-explicit-any */
3676+ return value !== undefined ? value : defaultValue ;
3677+ }
36573678//# sourceMappingURL=tool-cache.js.map
36583679
36593680/***/ } ) ,
@@ -3698,6 +3719,15 @@ var HttpCodes;
36983719 HttpCodes [ HttpCodes [ "ServiceUnavailable" ] = 503 ] = "ServiceUnavailable" ;
36993720 HttpCodes [ HttpCodes [ "GatewayTimeout" ] = 504 ] = "GatewayTimeout" ;
37003721} ) ( HttpCodes = exports . HttpCodes || ( exports . HttpCodes = { } ) ) ;
3722+ var Headers ;
3723+ ( function ( Headers ) {
3724+ Headers [ "Accept" ] = "accept" ;
3725+ Headers [ "ContentType" ] = "content-type" ;
3726+ } ) ( Headers = exports . Headers || ( exports . Headers = { } ) ) ;
3727+ var MediaTypes ;
3728+ ( function ( MediaTypes ) {
3729+ MediaTypes [ "ApplicationJson" ] = "application/json" ;
3730+ } ) ( MediaTypes = exports . MediaTypes || ( exports . MediaTypes = { } ) ) ;
37013731/**
37023732 * Returns the proxy URL, depending upon the supplied url and proxy environment variables.
37033733 * @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
@@ -3796,6 +3826,36 @@ class HttpClient {
37963826 sendStream ( verb , requestUrl , stream , additionalHeaders ) {
37973827 return this . request ( verb , requestUrl , stream , additionalHeaders ) ;
37983828 }
3829+ /**
3830+ * Gets a typed object from an endpoint
3831+ * Be aware that not found returns a null. Other errors (4xx, 5xx) reject the promise
3832+ */
3833+ async getJson ( requestUrl , additionalHeaders = { } ) {
3834+ additionalHeaders [ Headers . Accept ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . Accept , MediaTypes . ApplicationJson ) ;
3835+ let res = await this . get ( requestUrl , additionalHeaders ) ;
3836+ return this . _processResponse ( res , this . requestOptions ) ;
3837+ }
3838+ async postJson ( requestUrl , obj , additionalHeaders = { } ) {
3839+ let data = JSON . stringify ( obj , null , 2 ) ;
3840+ additionalHeaders [ Headers . Accept ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . Accept , MediaTypes . ApplicationJson ) ;
3841+ additionalHeaders [ Headers . ContentType ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . ContentType , MediaTypes . ApplicationJson ) ;
3842+ let res = await this . post ( requestUrl , data , additionalHeaders ) ;
3843+ return this . _processResponse ( res , this . requestOptions ) ;
3844+ }
3845+ async putJson ( requestUrl , obj , additionalHeaders = { } ) {
3846+ let data = JSON . stringify ( obj , null , 2 ) ;
3847+ additionalHeaders [ Headers . Accept ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . Accept , MediaTypes . ApplicationJson ) ;
3848+ additionalHeaders [ Headers . ContentType ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . ContentType , MediaTypes . ApplicationJson ) ;
3849+ let res = await this . put ( requestUrl , data , additionalHeaders ) ;
3850+ return this . _processResponse ( res , this . requestOptions ) ;
3851+ }
3852+ async patchJson ( requestUrl , obj , additionalHeaders = { } ) {
3853+ let data = JSON . stringify ( obj , null , 2 ) ;
3854+ additionalHeaders [ Headers . Accept ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . Accept , MediaTypes . ApplicationJson ) ;
3855+ additionalHeaders [ Headers . ContentType ] = this . _getExistingOrDefaultHeader ( additionalHeaders , Headers . ContentType , MediaTypes . ApplicationJson ) ;
3856+ let res = await this . patch ( requestUrl , data , additionalHeaders ) ;
3857+ return this . _processResponse ( res , this . requestOptions ) ;
3858+ }
37993859 /**
38003860 * Makes a raw http request.
38013861 * All other methods such as get, post, patch, and request ultimately call this.
@@ -3979,6 +4039,14 @@ class HttpClient {
39794039 }
39804040 return lowercaseKeys ( headers || { } ) ;
39814041 }
4042+ _getExistingOrDefaultHeader ( additionalHeaders , header , _default ) {
4043+ const lowercaseKeys = obj => Object . keys ( obj ) . reduce ( ( c , k ) => ( c [ k . toLowerCase ( ) ] = obj [ k ] , c ) , { } ) ;
4044+ let clientHeader ;
4045+ if ( this . requestOptions && this . requestOptions . headers ) {
4046+ clientHeader = lowercaseKeys ( this . requestOptions . headers ) [ header ] ;
4047+ }
4048+ return additionalHeaders [ header ] || clientHeader || _default ;
4049+ }
39824050 _getAgent ( parsedUrl ) {
39834051 let agent ;
39844052 let proxyUrl = pm . getProxyUrl ( parsedUrl ) ;
@@ -4046,6 +4114,73 @@ class HttpClient {
40464114 const ms = ExponentialBackoffTimeSlice * Math . pow ( 2 , retryNumber ) ;
40474115 return new Promise ( resolve => setTimeout ( ( ) => resolve ( ) , ms ) ) ;
40484116 }
4117+ static dateTimeDeserializer ( key , value ) {
4118+ if ( typeof value === 'string' ) {
4119+ let a = new Date ( value ) ;
4120+ if ( ! isNaN ( a . valueOf ( ) ) ) {
4121+ return a ;
4122+ }
4123+ }
4124+ return value ;
4125+ }
4126+ async _processResponse ( res , options ) {
4127+ return new Promise ( async ( resolve , reject ) => {
4128+ const statusCode = res . message . statusCode ;
4129+ const response = {
4130+ statusCode : statusCode ,
4131+ result : null ,
4132+ headers : { }
4133+ } ;
4134+ // not found leads to null obj returned
4135+ if ( statusCode == HttpCodes . NotFound ) {
4136+ resolve ( response ) ;
4137+ }
4138+ let obj ;
4139+ let contents ;
4140+ // get the result from the body
4141+ try {
4142+ contents = await res . readBody ( ) ;
4143+ if ( contents && contents . length > 0 ) {
4144+ if ( options && options . deserializeDates ) {
4145+ obj = JSON . parse ( contents , HttpClient . dateTimeDeserializer ) ;
4146+ }
4147+ else {
4148+ obj = JSON . parse ( contents ) ;
4149+ }
4150+ response . result = obj ;
4151+ }
4152+ response . headers = res . message . headers ;
4153+ }
4154+ catch ( err ) {
4155+ // Invalid resource (contents not json); leaving result obj null
4156+ }
4157+ // note that 3xx redirects are handled by the http layer.
4158+ if ( statusCode > 299 ) {
4159+ let msg ;
4160+ // if exception/error in body, attempt to get better error
4161+ if ( obj && obj . message ) {
4162+ msg = obj . message ;
4163+ }
4164+ else if ( contents && contents . length > 0 ) {
4165+ // it may be the case that the exception is in the body message as string
4166+ msg = contents ;
4167+ }
4168+ else {
4169+ msg = "Failed request: (" + statusCode + ")" ;
4170+ }
4171+ let err = new Error ( msg ) ;
4172+ // attach statusCode and body obj (if available) to the error object
4173+ err [ 'statusCode' ] = statusCode ;
4174+ if ( response . result ) {
4175+ err [ 'result' ] = response . result ;
4176+ }
4177+ reject ( err ) ;
4178+ }
4179+ else {
4180+ resolve ( response ) ;
4181+ }
4182+ } ) ;
4183+ }
40494184}
40504185exports . HttpClient = HttpClient ;
40514186
@@ -4329,6 +4464,13 @@ module.exports = require("fs");
43294464
43304465/***/ } ) ,
43314466
4467+ /***/ 794 :
4468+ /***/ ( function ( module ) {
4469+
4470+ module . exports = require ( "stream" ) ;
4471+
4472+ /***/ } ) ,
4473+
43324474/***/ 826 :
43334475/***/ ( function ( module , __unusedexports , __webpack_require__ ) {
43344476
@@ -4601,6 +4743,80 @@ function checkBypass(reqUrl) {
46014743exports . checkBypass = checkBypass ;
46024744
46034745
4746+ /***/ } ) ,
4747+
4748+ /***/ 979 :
4749+ /***/ ( function ( __unusedmodule , exports , __webpack_require__ ) {
4750+
4751+ "use strict" ;
4752+
4753+ var __awaiter = ( this && this . __awaiter ) || function ( thisArg , _arguments , P , generator ) {
4754+ function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
4755+ return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
4756+ function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
4757+ function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
4758+ function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
4759+ step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
4760+ } ) ;
4761+ } ;
4762+ var __importStar = ( this && this . __importStar ) || function ( mod ) {
4763+ if ( mod && mod . __esModule ) return mod ;
4764+ var result = { } ;
4765+ if ( mod != null ) for ( var k in mod ) if ( Object . hasOwnProperty . call ( mod , k ) ) result [ k ] = mod [ k ] ;
4766+ result [ "default" ] = mod ;
4767+ return result ;
4768+ } ;
4769+ Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
4770+ const core = __importStar ( __webpack_require__ ( 470 ) ) ;
4771+ /**
4772+ * Internal class for retries
4773+ */
4774+ class RetryHelper {
4775+ constructor ( maxAttempts , minSeconds , maxSeconds ) {
4776+ if ( maxAttempts < 1 ) {
4777+ throw new Error ( 'max attempts should be greater than or equal to 1' ) ;
4778+ }
4779+ this . maxAttempts = maxAttempts ;
4780+ this . minSeconds = Math . floor ( minSeconds ) ;
4781+ this . maxSeconds = Math . floor ( maxSeconds ) ;
4782+ if ( this . minSeconds > this . maxSeconds ) {
4783+ throw new Error ( 'min seconds should be less than or equal to max seconds' ) ;
4784+ }
4785+ }
4786+ execute ( action ) {
4787+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
4788+ let attempt = 1 ;
4789+ while ( attempt < this . maxAttempts ) {
4790+ // Try
4791+ try {
4792+ return yield action ( ) ;
4793+ }
4794+ catch ( err ) {
4795+ core . info ( err . message ) ;
4796+ }
4797+ // Sleep
4798+ const seconds = this . getSleepAmount ( ) ;
4799+ core . info ( `Waiting ${ seconds } seconds before trying again` ) ;
4800+ yield this . sleep ( seconds ) ;
4801+ attempt ++ ;
4802+ }
4803+ // Last attempt
4804+ return yield action ( ) ;
4805+ } ) ;
4806+ }
4807+ getSleepAmount ( ) {
4808+ return ( Math . floor ( Math . random ( ) * ( this . maxSeconds - this . minSeconds + 1 ) ) +
4809+ this . minSeconds ) ;
4810+ }
4811+ sleep ( seconds ) {
4812+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
4813+ return new Promise ( resolve => setTimeout ( resolve , seconds * 1000 ) ) ;
4814+ } ) ;
4815+ }
4816+ }
4817+ exports . RetryHelper = RetryHelper ;
4818+ //# sourceMappingURL=retry-helper.js.map
4819+
46044820/***/ } ) ,
46054821
46064822/***/ 986 :
0 commit comments