diff --git a/Readme.md b/Readme.md index 7b459d9b..0336f068 100644 --- a/Readme.md +++ b/Readme.md @@ -24,7 +24,7 @@ It is a cause of failed jobs. For this case, the action `wretry.action` can retr ## Features - Retries Github `JavaScript` actions. -- Retries `GitHub Docker` actions utilizing a `Dockerfile` as the image source. +- Retries `GitHub Docker` actions utilizing a `Dockerfile`'s and Docker registry image as the source. - Retries private actions. The option `github_token` is used for private repositories. - The action can be an action repository that is not published on `Marketplace`. - Retries shell commands. Uses default shells to run commands. diff --git a/main/action.yml b/main/action.yml index 8e53d873..0f93c742 100644 --- a/main/action.yml +++ b/main/action.yml @@ -13,6 +13,9 @@ inputs: command: description: 'Command to run. Should be defined action or command, not both.' required: false + pre_retry_command: + description: 'Command to run between retries.' + required: false with: description: 'An options map for Github action' required: false diff --git a/post/action.yml b/post/action.yml index 743447d0..d79ff127 100644 --- a/post/action.yml +++ b/post/action.yml @@ -13,6 +13,9 @@ inputs: command: description: 'Command to run. Should be defined action or command, not both.' required: false + pre_retry_command: + description: 'Command to run between retries.' + required: false with: description: 'An options map for Github action' required: false diff --git a/pre/action.yml b/pre/action.yml index 3a55ed3e..aa243682 100644 --- a/pre/action.yml +++ b/pre/action.yml @@ -13,6 +13,9 @@ inputs: command: description: 'Command to run. Should be defined action or command, not both.' required: false + pre_retry_command: + description: 'Command to run between retries.' + required: false with: description: 'An options map for Github action' required: false diff --git a/src/Docker.js b/src/Docker.js index d453b34d..5dd0ef82 100644 --- a/src/Docker.js +++ b/src/Docker.js @@ -54,11 +54,31 @@ function imageBuild( actionPath, image ) + 'and select valid workflow runner.' ); - if( image === 'Dockerfile' ) + const actionName = _.path.name( actionPath ); + const imageName = `${ actionName }_repo:${ actionName }_tag`.toLowerCase(); + + if( _.uri.isGlobal( image ) ) + { + const parsed = _.uri.parse( image ); + const publicDockerImage = parsed.longPath; + const pullCommand = `docker image pull ${ publicDockerImage }`; + const pull = execSyncNonThrowing( pullCommand ); + if( _.error.is( pull ) ) + throw _.error.brief( pull ); + + const tagCommand = `docker image tag ${ publicDockerImage } ${ imageName }`; + const tagging = execSyncNonThrowing( tagCommand ); + if( _.error.is( tagging ) ) + throw _.error.brief( tagging ); + + core.info( `Docker image : ${ publicDockerImage }.` ); + core.info( pullCommand ); + core.info( pull.toString() ); + core.info( tagCommand ); + } + else if( _.str.ends( image, 'Dockerfile' ) && _.path.isRelative( image ) ) { - const actionName = _.path.name( actionPath ); - const imageName = `${ actionName }_repo:${ actionName }_tag`.toLowerCase(); - const dockerfilePath = _.path.nativize( _.path.join( actionPath, 'Dockerfile' ) ); + const dockerfilePath = _.path.nativize( _.path.join( actionPath, image ) ); const command = `docker build -t ${ imageName } -f ${ dockerfilePath } ${ _.path.nativize( actionPath ) }`; const build = execSyncNonThrowing( command ); if( _.error.is( build ) ) @@ -67,16 +87,16 @@ function imageBuild( actionPath, image ) core.info( `Dockerfile for action : ${ dockerfilePath }.` ); core.info( command ); core.info( build.toString() ); - - return imageName; } - + else _.sure ( false, `The action does not support requested Docker image type "${ image }".` + '\nPlease, open an issue with the request for the feature.' ); + + return imageName; } // diff --git a/test/Docker.test.s b/test/Docker.test.s index eff660d6..31815e70 100644 --- a/test/Docker.test.s +++ b/test/Docker.test.s @@ -58,7 +58,6 @@ function exists( test ) exists.timeOut = 15000; // - function imageBuild( test ) { const ubuntuIs = process.env.ImageOS && _.str.begins( process.env.ImageOS, 'ubuntu' ); @@ -75,6 +74,10 @@ function imageBuild( test ) var got = docker.imageBuild( a.routinePath, 'Dockerfile' ); test.identical( got, 'imagebuild_repo:imagebuild_tag' ); + test.case = 'pull an image'; + var got = docker.imageBuild( a.routinePath, 'docker://ghcr.io/pytooling/releaser' ); + test.identical( got, 'imagebuild_repo:imagebuild_tag' ); + /* - */ if( !Config.debug ) @@ -90,6 +93,8 @@ function imageBuild( test ) test.shouldThrowErrorSync( () => docker.imageBuild( a.routinePath, 'wrong:image' ), onResolve ); } +imageBuild.timeOut = 60000; + // function commandArgsFrom( test )