fix(actions): allow cancelling runs without running jobs (#35842)

My idea is to allow cancelling an stuck run with all jobs done, in case
such a bug happens again to not require admin commands.

Related #35832

Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
ChristopherHX
2026-08-06 23:52:01 +00:00
committed by GitHub
co-authored by Zettat123 silverwind
parent 6ff3a65708
commit c210ef6dbb
3 changed files with 171 additions and 52 deletions
+7 -5
View File
@@ -19,7 +19,10 @@ func CancelRun(ctx context.Context, run *actions_model.ActionRun, jobs []*action
if err != nil {
return fmt.Errorf("CancelJobs: %w", err)
}
return nil
if len(updatedJobs) > 0 {
return nil // a job update already refreshed the run
}
return actions_model.SettleRunAfterCancel(ctx, run)
}); err != nil {
return nil, err
}
@@ -27,14 +30,13 @@ func CancelRun(ctx context.Context, run *actions_model.ActionRun, jobs []*action
CreateCommitStatusForRunJobs(ctx, run, jobs...)
EmitJobsIfReadyByJobs(updatedJobs)
NotifyWorkflowJobsStatusUpdate(ctx, updatedJobs...)
if len(updatedJobs) == 0 {
return run, nil
}
reloaded, err := actions_model.GetRunByRepoAndID(ctx, run.RepoID, run.ID)
if err != nil {
return nil, fmt.Errorf("GetRunByRepoAndID: %w", err)
}
NotifyWorkflowRunStatusUpdate(ctx, reloaded)
if len(updatedJobs) > 0 || reloaded.Status != run.Status {
NotifyWorkflowRunStatusUpdate(ctx, reloaded)
}
return reloaded, nil
}