@@ -412,6 +412,12 @@ func Rerun(ctx *context_module.Context) {
412412 return
413413 }
414414
415+ // rerun is not allowed if the run is not done
416+ if ! run .Status .IsDone () {
417+ ctx .JSONError (ctx .Locale .Tr ("actions.runs.not_done" ))
418+ return
419+ }
420+
415421 // can not rerun job when workflow is disabled
416422 cfgUnit := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions )
417423 cfg := cfgUnit .ActionsConfig ()
@@ -420,55 +426,51 @@ func Rerun(ctx *context_module.Context) {
420426 return
421427 }
422428
423- // check run (workflow-level) concurrency
429+ // reset run's start and stop time
430+ run .PreviousDuration = run .Duration ()
431+ run .Started = 0
432+ run .Stopped = 0
433+ run .Status = actions_model .StatusWaiting
424434
425- job , jobs := getRunJobs (ctx , runIndex , jobIndex )
426- if ctx .Written () {
435+ vars , err := actions_model .GetVariablesOfRun (ctx , run )
436+ if err != nil {
437+ ctx .ServerError ("GetVariablesOfRun" , fmt .Errorf ("get run %d variables: %w" , run .ID , err ))
427438 return
428439 }
429440
430- // reset run's start and stop time when it is done
431- if run .Status .IsDone () {
432- run .PreviousDuration = run .Duration ()
433- run .Started = 0
434- run .Stopped = 0
435- run .Status = actions_model .StatusWaiting
436-
437- vars , err := actions_model .GetVariablesOfRun (ctx , run )
438- if err != nil {
439- ctx .ServerError ("GetVariablesOfRun" , fmt .Errorf ("get run %d variables: %w" , run .ID , err ))
441+ if run .RawConcurrency != "" {
442+ var rawConcurrency model.RawConcurrency
443+ if err := yaml .Unmarshal ([]byte (run .RawConcurrency ), & rawConcurrency ); err != nil {
444+ ctx .ServerError ("UnmarshalRawConcurrency" , fmt .Errorf ("unmarshal raw concurrency: %w" , err ))
440445 return
441446 }
442447
443- if run .RawConcurrency != "" {
444- var rawConcurrency model.RawConcurrency
445- if err := yaml .Unmarshal ([]byte (run .RawConcurrency ), & rawConcurrency ); err != nil {
446- ctx .ServerError ("UnmarshalRawConcurrency" , fmt .Errorf ("unmarshal raw concurrency: %w" , err ))
447- return
448- }
449-
450- err = actions_service .EvaluateRunConcurrencyFillModel (ctx , run , & rawConcurrency , vars )
451- if err != nil {
452- ctx .ServerError ("EvaluateRunConcurrencyFillModel" , err )
453- return
454- }
455-
456- run .Status , err = actions_service .PrepareToStartRunWithConcurrency (ctx , run )
457- if err != nil {
458- ctx .ServerError ("PrepareToStartRunWithConcurrency" , err )
459- return
460- }
461- }
462- if err := actions_model .UpdateRun (ctx , run , "started" , "stopped" , "previous_duration" , "status" , "concurrency_group" , "concurrency_cancel" ); err != nil {
463- ctx .ServerError ("UpdateRun" , err )
448+ err = actions_service .EvaluateRunConcurrencyFillModel (ctx , run , & rawConcurrency , vars )
449+ if err != nil {
450+ ctx .ServerError ("EvaluateRunConcurrencyFillModel" , err )
464451 return
465452 }
466453
467- if err := run .LoadAttributes (ctx ); err != nil {
468- ctx .ServerError ("run.LoadAttributes" , err )
454+ run .Status , err = actions_service .PrepareToStartRunWithConcurrency (ctx , run )
455+ if err != nil {
456+ ctx .ServerError ("PrepareToStartRunWithConcurrency" , err )
469457 return
470458 }
471- notify_service .WorkflowRunStatusUpdate (ctx , run .Repo , run .TriggerUser , run )
459+ }
460+ if err := actions_model .UpdateRun (ctx , run , "started" , "stopped" , "previous_duration" , "status" , "concurrency_group" , "concurrency_cancel" ); err != nil {
461+ ctx .ServerError ("UpdateRun" , err )
462+ return
463+ }
464+
465+ if err := run .LoadAttributes (ctx ); err != nil {
466+ ctx .ServerError ("run.LoadAttributes" , err )
467+ return
468+ }
469+ notify_service .WorkflowRunStatusUpdate (ctx , run .Repo , run .TriggerUser , run )
470+
471+ job , jobs := getRunJobs (ctx , runIndex , jobIndex )
472+ if ctx .Written () {
473+ return
472474 }
473475
474476 isRunBlocked := run .Status == actions_model .StatusBlocked
@@ -501,7 +503,7 @@ func Rerun(ctx *context_module.Context) {
501503
502504func rerunJob (ctx * context_module.Context , job * actions_model.ActionRunJob , shouldBlock bool ) error {
503505 status := job .Status
504- if ! status .IsDone () || ! job . Run . Status . IsDone () {
506+ if ! status .IsDone () {
505507 return nil
506508 }
507509
0 commit comments