aboutsummaryrefslogtreecommitdiffstats
path: root/services/actions
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2023-07-25 11:15:55 +0800
committerGitHub <noreply@github.com>2023-07-25 11:15:55 +0800
commit44781f9f5c4ede618660d8cfe42437f0e8dc22a0 (patch)
treeefcdc2e7876ede8c7e721432760e6ef9cefe4806 /services/actions
parent5db640abcd8608b065a1b390404bba2233220c95 (diff)
downloadgitea-44781f9f5c4ede618660d8cfe42437f0e8dc22a0.tar.gz
gitea-44781f9f5c4ede618660d8cfe42437f0e8dc22a0.zip
Implement auto-cancellation of concurrent jobs if the event is push (#25716)
- cancel running jobs if the event is push - Add a new function `CancelRunningJobs` to cancel all running jobs of a run - Update `FindRunOptions` struct to include `Ref` field and update its condition in `toConds` function - Implement auto cancellation of running jobs in the same workflow in `notify` function related task: https://github.com/go-gitea/gitea/pull/22751/ --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> Signed-off-by: appleboy <appleboy.tw@gmail.com> Co-authored-by: Jason Song <i@wolfogre.com> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'services/actions')
-rw-r--r--services/actions/notifier_helper.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go
index 90ad3001ba..764d24a7db 100644
--- a/services/actions/notifier_helper.go
+++ b/services/actions/notifier_helper.go
@@ -230,16 +230,31 @@ func notify(ctx context.Context, input *notifyInput) error {
log.Error("jobparser.Parse: %v", err)
continue
}
+
+ // cancel running jobs if the event is push
+ if run.Event == webhook_module.HookEventPush {
+ // cancel running jobs of the same workflow
+ if err := actions_model.CancelRunningJobs(
+ ctx,
+ run.RepoID,
+ run.Ref,
+ run.WorkflowID,
+ ); err != nil {
+ log.Error("CancelRunningJobs: %v", err)
+ }
+ }
+
if err := actions_model.InsertRun(ctx, run, jobs); err != nil {
log.Error("InsertRun: %v", err)
continue
}
- if jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID}); err != nil {
+
+ alljobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID})
+ if err != nil {
log.Error("FindRunJobs: %v", err)
- } else {
- CreateCommitStatus(ctx, jobs...)
+ continue
}
-
+ CreateCommitStatus(ctx, alljobs...)
}
return nil
}