File tree Expand file tree Collapse file tree 2 files changed +66
-2
lines changed
Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,36 @@ async function swift_path(swift_version) {
107107 return _swift_paths . get ( swift_version ) ;
108108}
109109async function download_swift ( swift_version ) {
110+ const __download_swift = async ( ) => {
111+ return await exec . exec ( swiftenvPath , [ 'install' , swift_version ] , {
112+ ignoreReturnCode : true ,
113+ } ) ;
114+ } ;
115+ // NOTE: Sometimes `swiftenv install ...` fails owing to curl's error 18 on GitHub Actions.
116+ const __retryableExitStatus = ( status ) => {
117+ return ( status == 18 ) ;
118+ } ;
119+ const commandDesc = `swiftenv install ${ swift_version } ` ;
110120 await run ( 'Download Swift (via swiftenv)...' , async ( ) => {
111- await exec . exec ( swiftenvPath , [ 'install' , swift_version ] ) ;
121+ let retryCount = 0 ;
122+ const maxRetryCount = 5 ;
123+ while ( true ) {
124+ retryCount ++ ;
125+ if ( retryCount > maxRetryCount ) {
126+ throw new Error ( `\`${ commandDesc } \` failed too many times.` ) ;
127+ }
128+ const exitStatus = await __download_swift ( ) ;
129+ if ( exitStatus == 0 ) {
130+ break ;
131+ }
132+ const failureMessage = `\`${ commandDesc } \` failed with exit code ${ exitStatus } .` ;
133+ if ( __retryableExitStatus ( exitStatus ) ) {
134+ core . info ( failureMessage ) ;
135+ }
136+ else {
137+ throw new Error ( failureMessage ) ;
138+ }
139+ }
112140 } ) ;
113141}
114142async function switch_swift ( swift_version ) {
Original file line number Diff line number Diff line change @@ -85,8 +85,44 @@ async function swift_path(swift_version: string): Promise<SwiftPath> {
8585}
8686
8787async function download_swift ( swift_version : string ) : Promise < void > {
88+ const __download_swift = async ( ) : Promise < number > => {
89+ return await exec . exec (
90+ swiftenvPath ,
91+ [ 'install' , swift_version ] ,
92+ {
93+ ignoreReturnCode : true ,
94+ }
95+ ) ;
96+ } ;
97+
98+ // NOTE: Sometimes `swiftenv install ...` fails owing to curl's error 18 on GitHub Actions.
99+
100+ const __retryableExitStatus = ( status : number ) : boolean => {
101+ return ( status == 18 ) ;
102+ } ;
103+
104+ const commandDesc = `swiftenv install ${ swift_version } ` ;
105+
88106 await run ( 'Download Swift (via swiftenv)...' , async ( ) => {
89- await exec . exec ( swiftenvPath , [ 'install' , swift_version ] ) ;
107+ let retryCount = 0 ;
108+ const maxRetryCount = 5 ;
109+ while ( true ) {
110+ retryCount ++ ;
111+ if ( retryCount > maxRetryCount ) {
112+ throw new Error ( `\`${ commandDesc } \` failed too many times.` ) ;
113+ }
114+
115+ const exitStatus = await __download_swift ( ) ;
116+ if ( exitStatus == 0 ) {
117+ break ;
118+ }
119+ const failureMessage = `\`${ commandDesc } \` failed with exit code ${ exitStatus } .` ;
120+ if ( __retryableExitStatus ( exitStatus ) ) {
121+ core . info ( failureMessage ) ;
122+ } else {
123+ throw new Error ( failureMessage ) ;
124+ }
125+ }
90126 } )
91127}
92128
You can’t perform that action at this time.
0 commit comments