@@ -23,7 +23,7 @@ import { HttpClient } from '@actions/http-client';
2323import * as core from '@actions/core' ;
2424import * as toolCache from '@actions/tool-cache' ;
2525import * as semver from 'semver' ;
26- import { errorMessage } from '@google-github-actions/actions-utils' ;
26+ import { errorMessage , withRetries } from '@google-github-actions/actions-utils' ;
2727
2828import { buildReleaseURL } from './format-url' ;
2929import { downloadAndExtractTool } from './download-util' ;
@@ -269,23 +269,32 @@ export async function getLatestGcloudSDKVersion(): Promise<string> {
269269 */
270270export async function bestVersion ( spec : string ) : Promise < string > {
271271 let versions : string [ ] ;
272- try {
273- const http = new HttpClient ( userAgentString , undefined , { allowRetries : true , maxRetries : 3 } ) ;
274- const res = await http . get ( versionsURL ) ;
275-
276- const body = await res . readBody ( ) ;
277- const statusCode = res . message . statusCode || 500 ;
278- if ( statusCode >= 400 ) {
279- throw new Error ( `(${ statusCode } ) ${ body } ` ) ;
280- }
281272
282- versions = JSON . parse ( body ) as string [ ] ;
273+ try {
274+ return await withRetries (
275+ async ( ) : Promise < string > => {
276+ const http = new HttpClient ( userAgentString ) ;
277+ const res = await http . get ( versionsURL ) ;
278+
279+ const body = await res . readBody ( ) ;
280+ const statusCode = res . message . statusCode || 500 ;
281+ if ( statusCode >= 400 ) {
282+ throw new Error ( `(${ statusCode } ) ${ body } ` ) ;
283+ }
284+
285+ versions = JSON . parse ( body ) as string [ ] ;
286+ return computeBestVersion ( spec , versions ) ;
287+ } ,
288+ {
289+ retries : 3 ,
290+ backoff : 100 , // 100 milliseconds
291+ backoffLimit : 1_000 , // 1 second
292+ } ,
293+ ) ( ) ;
283294 } catch ( err ) {
284295 const msg = errorMessage ( err ) ;
285296 throw new Error ( `failed to retrieve versions from ${ versionsURL } : ${ msg } ` ) ;
286297 }
287-
288- return computeBestVersion ( spec , versions ) ;
289298}
290299
291300/**
0 commit comments