-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add stop-on-signals and auto-cancellation #149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,16 @@ function runBuild() { | |
|
||
const inputs = githubInputs(); | ||
|
||
const config = (({ updateInterval, updateBackOff, hideCloudWatchLogs }) => ({ | ||
const config = (({ | ||
updateInterval, | ||
updateBackOff, | ||
hideCloudWatchLogs, | ||
stopOnSignals, | ||
}) => ({ | ||
updateInterval, | ||
updateBackOff, | ||
hideCloudWatchLogs, | ||
stopOnSignals, | ||
}))(inputs); | ||
|
||
// Get input options for startBuild | ||
|
@@ -39,10 +45,27 @@ async function build(sdk, params, config) { | |
// Start the build | ||
const start = await sdk.codeBuild.startBuild(params); | ||
|
||
// Set up signal handling to stop the build on cancellation | ||
setupSignalHandlers(sdk, start.build.id, config.stopOnSignals); | ||
|
||
// Wait for the build to "complete" | ||
return waitForBuildEndTime(sdk, start.build, config); | ||
} | ||
|
||
function setupSignalHandlers(sdk, id, signals) { | ||
signals.forEach((s) => { | ||
core.info(`Installing signal handler for ${s}`); | ||
process.on(s, async () => { | ||
try { | ||
core.info(`Caught ${s}, attempting to stop build...`); | ||
await sdk.codeBuild.stopBuild({ id }).promise(); | ||
} catch (ex) { | ||
core.error(`Error stopping build: ${ex}`); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async function waitForBuildEndTime( | ||
sdk, | ||
{ id, logs }, | ||
|
@@ -226,6 +249,12 @@ function githubInputs() { | |
const artifactsTypeOverride = | ||
core.getInput("artifacts-type-override", { required: false }) || undefined; | ||
|
||
const stopOnSignals = core | ||
.getInput("stop-on-signals", { required: false }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to set the default value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because of the default in My understanding (correct me if I'm wrong) is: Putting the default in Confusingly, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it. I asked this question because of the issue I reported in the other comment. |
||
.split(",") | ||
.map((i) => i.trim()) | ||
.filter((i) => i !== ""); | ||
|
||
return { | ||
projectName, | ||
owner, | ||
|
@@ -243,6 +272,7 @@ function githubInputs() { | |
hideCloudWatchLogs, | ||
disableGithubEnvVars, | ||
artifactsTypeOverride, | ||
stopOnSignals, | ||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to test this PR but I couldn't cancel the workflow and the build .
my workflow: https://github.com/taoyong-ty/aws-codebuild-run-build/actions/runs/7731467637/workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you say a little more about "couldn't cancel the workflow and the build"? The logs seem to have expired for that example. If you do it again, I can take a look.
This has been working well for us since I opened this PR. Here is a recent example,
GitHub cancels the build (it was a
fail-fast
matrix Job where another Job failed):You can see the Build did indeed go into Stopped at exactly that time:
And the end of the logs on the CodeBuild side, showing the same:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't now why you have
if: always()
there, can you try removing it?always()
is an anti-pattern anyway because it includes thecancelled
status too, which feels important here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right.
What I saw earlier was that the CodeBuild build was still running, even though the GitHub has acknowledged the cancelling request.
But I am now able to see the expected behavior after removin
if: always()
!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the change!
I am ready to approve and merge the change. Could you rebase your commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, done.