feat: Support graceful job step cancellation (#69)

* for gh-act-runner
* act-cli support as well
* respecting always() and cancelled() of steps
* setup-job, bug report, gh cli and watch wait call is cancelled early
This commit is contained in:
ChristopherHX
2025-03-29 12:27:36 +01:00
committed by GitHub
parent dde298852a
commit cef5575fa4
8 changed files with 242 additions and 28 deletions

View File

@@ -51,6 +51,7 @@ type RunContext struct {
Masks []string
cleanUpJobContainer common.Executor
caller *caller // job calling this RunContext (reusable workflows)
Cancelled bool
nodeToolFullPath string
}
@@ -435,6 +436,8 @@ func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user
func (rc *RunContext) InitializeNodeTool() common.Executor {
return func(ctx context.Context) error {
ctx, cancel := common.EarlyCancelContext(ctx)
defer cancel()
rc.GetNodeToolFullPath(ctx)
return nil
}
@@ -660,6 +663,8 @@ func (rc *RunContext) interpolateOutputs() common.Executor {
func (rc *RunContext) startContainer() common.Executor {
return func(ctx context.Context) error {
ctx, cancel := common.EarlyCancelContext(ctx)
defer cancel()
if rc.IsHostEnv(ctx) {
return rc.startHostEnvironment()(ctx)
}
@@ -863,10 +868,14 @@ func trimToLen(s string, l int) string {
func (rc *RunContext) getJobContext() *model.JobContext {
jobStatus := "success"
for _, stepStatus := range rc.StepResults {
if stepStatus.Conclusion == model.StepStatusFailure {
jobStatus = "failure"
break
if rc.Cancelled {
jobStatus = "cancelled"
} else {
for _, stepStatus := range rc.StepResults {
if stepStatus.Conclusion == model.StepStatusFailure {
jobStatus = "failure"
break
}
}
}
return &model.JobContext{