summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2024-03-22 04:19:17 +0100
committerEarl Warren <contact@earl-warren.org>2024-03-26 19:04:26 +0100
commit8848b0ea2b34cca5f9a2d1f54e77b609579d4d97 (patch)
tree5a6cd3dcb0d3ed54f0167d2026678a48adf61048 /routers
parentremove PATH and GOPATH modification in Makefile (#29978) (diff)
downloadforgejo-8848b0ea2b34cca5f9a2d1f54e77b609579d4d97.tar.xz
forgejo-8848b0ea2b34cca5f9a2d1f54e77b609579d4d97.zip
Fix bugs in rerunning jobs (#29955)
Fix #28761 Fix #27884 Fix #28093 ## Changes ### Rerun all jobs When rerun all jobs, status of the jobs with `needs` will be set to `blocked` instead of `waiting`. Therefore, these jobs will not run until the required jobs are completed. ### Rerun a single job When a single job is rerun, its dependents should also be rerun, just like GitHub does (https://github.com/go-gitea/gitea/issues/28761#issuecomment-2008620820). In this case, only the specified job will be set to `waiting`, its dependents will be set to `blocked` to wait the job. ### Show warning if every job has `needs` If every job in a workflow has `needs`, all jobs will be blocked and no job can be run. So I add a warning message. <img src="https://github.com/go-gitea/gitea/assets/15528715/88f43511-2360-465d-be96-ee92b57ff67b" width="480px" /> (cherry picked from commit 2f060c5834d81f0317c795fc281f9a07e03e5962)
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/actions/actions.go10
-rw-r--r--routers/web/repo/actions/view.go26
2 files changed, 30 insertions, 6 deletions
diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go
index f27329aa0f..6059ad1414 100644
--- a/routers/web/repo/actions/actions.go
+++ b/routers/web/repo/actions/actions.go
@@ -104,8 +104,13 @@ func List(ctx *context.Context) {
workflows = append(workflows, workflow)
continue
}
- // Check whether have matching runner
+ // The workflow must contain at least one job without "needs". Otherwise, a deadlock will occur and no jobs will be able to run.
+ hasJobWithoutNeeds := false
+ // Check whether have matching runner and a job without "needs"
for _, j := range wf.Jobs {
+ if !hasJobWithoutNeeds && len(j.Needs()) == 0 {
+ hasJobWithoutNeeds = true
+ }
runsOnList := j.RunsOn()
for _, ro := range runsOnList {
if strings.Contains(ro, "${{") {
@@ -123,6 +128,9 @@ func List(ctx *context.Context) {
break
}
}
+ if !hasJobWithoutNeeds {
+ workflow.ErrMsg = ctx.Locale.TrString("actions.runs.no_job_without_needs")
+ }
workflows = append(workflows, workflow)
}
}
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index 23ce70a153..fa687bbb93 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -353,12 +353,25 @@ func Rerun(ctx *context_module.Context) {
return
}
- if jobIndexStr != "" {
- jobs = []*actions_model.ActionRunJob{job}
+ if jobIndexStr == "" { // rerun all jobs
+ for _, j := range jobs {
+ // if the job has needs, it should be set to "blocked" status to wait for other jobs
+ shouldBlock := len(j.Needs) > 0
+ if err := rerunJob(ctx, j, shouldBlock); err != nil {
+ ctx.Error(http.StatusInternalServerError, err.Error())
+ return
+ }
+ }
+ ctx.JSON(http.StatusOK, struct{}{})
+ return
}
- for _, j := range jobs {
- if err := rerunJob(ctx, j); err != nil {
+ rerunJobs := actions_service.GetAllRerunJobs(job, jobs)
+
+ for _, j := range rerunJobs {
+ // jobs other than the specified one should be set to "blocked" status
+ shouldBlock := j.JobID != job.JobID
+ if err := rerunJob(ctx, j, shouldBlock); err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
return
}
@@ -367,7 +380,7 @@ func Rerun(ctx *context_module.Context) {
ctx.JSON(http.StatusOK, struct{}{})
}
-func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) error {
+func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shouldBlock bool) error {
status := job.Status
if !status.IsDone() {
return nil
@@ -375,6 +388,9 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) erro
job.TaskID = 0
job.Status = actions_model.StatusWaiting
+ if shouldBlock {
+ job.Status = actions_model.StatusBlocked
+ }
job.Started = 0
job.Stopped = 0