@@ -23,10 +23,16 @@ function runBuild() {
2323
2424 const inputs = githubInputs ( ) ;
2525
26- const config = ( ( { updateInterval , updateBackOff , hideCloudWatchLogs } ) => ( {
26+ const config = ( ( {
2727 updateInterval,
2828 updateBackOff,
2929 hideCloudWatchLogs,
30+ stopOnSignals,
31+ } ) => ( {
32+ updateInterval,
33+ updateBackOff,
34+ hideCloudWatchLogs,
35+ stopOnSignals,
3036 } ) ) ( inputs ) ;
3137
3238 // Get input options for startBuild
@@ -39,10 +45,27 @@ async function build(sdk, params, config) {
3945 // Start the build
4046 const start = await sdk . codeBuild . startBuild ( params ) ;
4147
48+ // Set up signal handling to stop the build on cancellation
49+ setupSignalHandlers ( sdk , start . build . id , config . stopOnSignals ) ;
50+
4251 // Wait for the build to "complete"
4352 return waitForBuildEndTime ( sdk , start . build , config ) ;
4453}
4554
55+ function setupSignalHandlers ( sdk , id , signals ) {
56+ signals . forEach ( ( s ) => {
57+ core . info ( `Installing signal handler for ${ s } ` ) ;
58+ process . on ( s , async ( ) => {
59+ try {
60+ core . info ( `Caught ${ s } , attempting to stop build...` ) ;
61+ await sdk . codeBuild . stopBuild ( { id } ) . promise ( ) ;
62+ } catch ( ex ) {
63+ core . error ( `Error stopping build: ${ ex } ` ) ;
64+ }
65+ } ) ;
66+ } ) ;
67+ }
68+
4669async function waitForBuildEndTime (
4770 sdk ,
4871 { id, logs } ,
@@ -226,6 +249,12 @@ function githubInputs() {
226249 const artifactsTypeOverride =
227250 core . getInput ( "artifacts-type-override" , { required : false } ) || undefined ;
228251
252+ const stopOnSignals = core
253+ . getInput ( "stop-on-signals" , { required : false } )
254+ . split ( "," )
255+ . map ( ( i ) => i . trim ( ) )
256+ . filter ( ( i ) => i !== "" ) ;
257+
229258 return {
230259 projectName,
231260 owner,
@@ -243,6 +272,7 @@ function githubInputs() {
243272 hideCloudWatchLogs,
244273 disableGithubEnvVars,
245274 artifactsTypeOverride,
275+ stopOnSignals,
246276 } ;
247277}
248278
0 commit comments