@@ -12,6 +12,13 @@ const WORKSPACE_DIRECTORY = core.getInput('workspace-dir');
12
12
const GENERATE_SOURCES = core . getInput ( 'generate-sources' ) ;
13
13
let PACKAGES = "none"
14
14
const ROS_ENV_VARIABLES : any = { } ;
15
+ const COLCON_BUNDLE_RETRIES = Number . parseInt ( core . getInput ( 'colcon-bundle-retries' ) , 10 ) ;
16
+ const MINIMUM_BACKOFF_TIME_SECONDS = 32 ; // delay for the first retry in seconds
17
+ const MAXIMUM_BACKOFF_TIME_SECONDS = 128 ; // maximum delay for a retry in seconds
18
+
19
+ function delay ( ms : number ) {
20
+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
21
+ }
15
22
16
23
async function loadROSEnvVariables ( ) {
17
24
const options = {
@@ -184,7 +191,6 @@ async function prepare_sources() {
184
191
async function build ( ) {
185
192
try {
186
193
await exec . exec ( "rosdep" , [ "install" , "--from-paths" , "." , "--ignore-src" , "-r" , "-y" , "--rosdistro" , ROS_DISTRO ] , getWorkingDirExecOptions ( ) ) ;
187
-
188
194
console . log ( `Building the following packages: ${ PACKAGES } ` ) ;
189
195
await exec . exec ( "colcon" , [ "build" , "--build-base" , "build" , "--install-base" , "install" ] , getWorkingDirExecOptions ( ) ) ;
190
196
} catch ( error ) {
@@ -193,13 +199,25 @@ async function build() {
193
199
}
194
200
195
201
async function bundle ( ) {
196
- try {
197
- const bundleFilename = path . basename ( WORKSPACE_DIRECTORY ) ;
198
- await exec . exec ( "colcon" , [ "bundle" , "--build-base" , "build" , "--install-base" , "install" , "--bundle-base" , "bundle" ] , getWorkingDirExecOptions ( ) ) ;
199
- await exec . exec ( "mv" , [ "bundle/output.tar" , `../${ bundleFilename } .tar` ] , getWorkingDirExecOptions ( ) ) ;
200
- await exec . exec ( "rm" , [ "-rf" , "bundle" ] , getWorkingDirExecOptions ( ) ) ; // github actions have been failing with no disk space
201
- } catch ( error ) {
202
- core . setFailed ( error . message ) ;
202
+ let delay_ms = 1000 * MINIMUM_BACKOFF_TIME_SECONDS ;
203
+ // indexed from 0 because COLCON_BUNDLE_RETRIES is the number of retries AFTER the initial try
204
+ for ( let i = 0 ; i <= COLCON_BUNDLE_RETRIES ; i ++ ) {
205
+ try {
206
+ const bundleFilename = path . basename ( WORKSPACE_DIRECTORY ) ;
207
+ await exec . exec ( "colcon" , [ "bundle" , "--build-base" , "build" , "--install-base" , "install" , "--bundle-base" , "bundle" ] , getWorkingDirExecOptions ( ) ) ;
208
+ await exec . exec ( "mv" , [ "bundle/output.tar" , `../${ bundleFilename } .tar` ] , getWorkingDirExecOptions ( ) ) ;
209
+ await exec . exec ( "rm" , [ "-rf" , "bundle" ] , getWorkingDirExecOptions ( ) ) ; // github actions have been failing with no disk space
210
+ break ; // break if colcon bundle passes
211
+ } catch ( error ) {
212
+ await exec . exec ( "rm" , [ "-rf" , "bundle" ] , getWorkingDirExecOptions ( ) ) ; // remove erred bundle assets
213
+ if ( i == COLCON_BUNDLE_RETRIES ) {
214
+ core . setFailed ( error . message ) ; // set action to Failed if the colcon bundle fails even after COLCON_BUNDLE_RETRIES number of retries
215
+ break ;
216
+ }
217
+ console . log ( `Colcon bundle failed.. retrying in ${ delay_ms } milliseconds` ) ;
218
+ await delay ( delay_ms ) ; // wait for next retry per the current exponential backoff delay
219
+ delay_ms = Math . min ( delay_ms * 2 , MAXIMUM_BACKOFF_TIME_SECONDS ) ; // double the delay for the next retry, truncate if required
220
+ }
203
221
}
204
222
}
205
223
@@ -208,6 +226,12 @@ async function run() {
208
226
console . log ( `GAZEBO_VERSION: ${ GAZEBO_VERSION } ` ) ;
209
227
console . log ( `WORKSPACE_DIRECTORY: ${ WORKSPACE_DIRECTORY } ` ) ;
210
228
console . log ( `GENERATE_SOURCES: ${ GENERATE_SOURCES } ` ) ;
229
+ console . log ( `COLCON_BUNDLE_RETRIES: ${ COLCON_BUNDLE_RETRIES } ` ) ;
230
+
231
+ // check if COLCON_BUNDLE_RETRIES is valid (i.e. 0<) and not too large (i.e. <10)
232
+ if ( COLCON_BUNDLE_RETRIES < 0 || 9 < COLCON_BUNDLE_RETRIES ) {
233
+ core . setFailed ( `Invalid number of colcon bundle retries. Must be between 0-9 inclusive` ) ;
234
+ }
211
235
212
236
await setup ( ) ;
213
237
if ( ROS_DISTRO == "kinetic" && ( GAZEBO_VERSION == "" || GAZEBO_VERSION == "7" ) ) {
0 commit comments