@@ -36,8 +36,6 @@ import (
3636 notify_service "code.gitea.io/gitea/services/notify"
3737
3838 "github.com/nektos/act/pkg/model"
39- "go.yaml.in/yaml/v4"
40- "xorm.io/builder"
4139)
4240
4341func getRunIndex (ctx * context_module.Context ) int64 {
@@ -431,130 +429,33 @@ func Rerun(ctx *context_module.Context) {
431429 return
432430 }
433431
434- // reset run's start and stop time
435- run .PreviousDuration = run .Duration ()
436- run .Started = 0
437- run .Stopped = 0
438- run .Status = actions_model .StatusWaiting
439-
440- vars , err := actions_model .GetVariablesOfRun (ctx , run )
432+ jobs , err := actions_model .GetRunJobsByRunID (ctx , run .ID )
441433 if err != nil {
442- ctx .ServerError ("GetVariablesOfRun" , fmt .Errorf ("get run %d variables: %w" , run .ID , err ))
443- return
444- }
445-
446- if run .RawConcurrency != "" {
447- var rawConcurrency model.RawConcurrency
448- if err := yaml .Unmarshal ([]byte (run .RawConcurrency ), & rawConcurrency ); err != nil {
449- ctx .ServerError ("UnmarshalRawConcurrency" , fmt .Errorf ("unmarshal raw concurrency: %w" , err ))
450- return
451- }
452-
453- err = actions_service .EvaluateRunConcurrencyFillModel (ctx , run , & rawConcurrency , vars , nil )
454- if err != nil {
455- ctx .ServerError ("EvaluateRunConcurrencyFillModel" , err )
456- return
457- }
458-
459- run .Status , err = actions_service .PrepareToStartRunWithConcurrency (ctx , run )
460- if err != nil {
461- ctx .ServerError ("PrepareToStartRunWithConcurrency" , err )
462- return
463- }
464- }
465- if err := actions_model .UpdateRun (ctx , run , "started" , "stopped" , "previous_duration" , "status" , "concurrency_group" , "concurrency_cancel" ); err != nil {
466- ctx .ServerError ("UpdateRun" , err )
467- return
468- }
469-
470- if err := run .LoadAttributes (ctx ); err != nil {
471- ctx .ServerError ("run.LoadAttributes" , err )
434+ ctx .ServerError ("GetRunJobsByRunID" , err )
472435 return
473436 }
474- notify_service .WorkflowRunStatusUpdate (ctx , run .Repo , run .TriggerUser , run )
475-
476- job , jobs := getRunJobs (ctx , runIndex , jobIndex )
477- if ctx .Written () {
437+ if len (jobs ) == 0 {
438+ ctx .NotFound (nil )
478439 return
479440 }
480441
481- isRunBlocked := run .Status == actions_model .StatusBlocked
482- if jobIndexStr == "" { // rerun all jobs
483- for _ , j := range jobs {
484- // if the job has needs, it should be set to "blocked" status to wait for other jobs
485- shouldBlockJob := len (j .Needs ) > 0 || isRunBlocked
486- if err := rerunJob (ctx , j , shouldBlockJob ); err != nil {
487- ctx .ServerError ("RerunJob" , err )
488- return
489- }
442+ var targetJob * actions_model.ActionRunJob
443+ if jobIndexStr != "" {
444+ if jobIndex >= 0 && jobIndex < int64 (len (jobs )) {
445+ targetJob = jobs [jobIndex ]
446+ } else {
447+ targetJob = jobs [0 ]
490448 }
491- ctx .JSONOK ()
492- return
493449 }
494450
495- rerunJobs := actions_service .GetAllRerunJobs (job , jobs )
496-
497- for _ , j := range rerunJobs {
498- // jobs other than the specified one should be set to "blocked" status
499- shouldBlockJob := j .JobID != job .JobID || isRunBlocked
500- if err := rerunJob (ctx , j , shouldBlockJob ); err != nil {
501- ctx .ServerError ("RerunJob" , err )
502- return
503- }
451+ if err := actions_service .RerunWorkflowRunJobs (ctx , ctx .Repo .Repository , run , jobs , targetJob ); err != nil {
452+ ctx .ServerError ("RerunWorkflowRunJobs" , err )
453+ return
504454 }
505455
506456 ctx .JSONOK ()
507457}
508458
509- func rerunJob (ctx * context_module.Context , job * actions_model.ActionRunJob , shouldBlock bool ) error {
510- status := job .Status
511- if ! status .IsDone () {
512- return nil
513- }
514-
515- job .TaskID = 0
516- job .Status = util .Iif (shouldBlock , actions_model .StatusBlocked , actions_model .StatusWaiting )
517- job .Started = 0
518- job .Stopped = 0
519-
520- job .ConcurrencyGroup = ""
521- job .ConcurrencyCancel = false
522- job .IsConcurrencyEvaluated = false
523- if err := job .LoadRun (ctx ); err != nil {
524- return err
525- }
526-
527- vars , err := actions_model .GetVariablesOfRun (ctx , job .Run )
528- if err != nil {
529- return fmt .Errorf ("get run %d variables: %w" , job .Run .ID , err )
530- }
531-
532- if job .RawConcurrency != "" && ! shouldBlock {
533- err = actions_service .EvaluateJobConcurrencyFillModel (ctx , job .Run , job , vars , nil )
534- if err != nil {
535- return fmt .Errorf ("evaluate job concurrency: %w" , err )
536- }
537-
538- job .Status , err = actions_service .PrepareToStartJobWithConcurrency (ctx , job )
539- if err != nil {
540- return err
541- }
542- }
543-
544- if err := db .WithTx (ctx , func (ctx context.Context ) error {
545- updateCols := []string {"task_id" , "status" , "started" , "stopped" , "concurrency_group" , "concurrency_cancel" , "is_concurrency_evaluated" }
546- _ , err := actions_model .UpdateRunJob (ctx , job , builder.Eq {"status" : status }, updateCols ... )
547- return err
548- }); err != nil {
549- return err
550- }
551-
552- actions_service .CreateCommitStatusForRunJobs (ctx , job .Run , job )
553- notify_service .WorkflowJobStatusUpdate (ctx , job .Run .Repo , job .Run .TriggerUser , job , nil )
554-
555- return nil
556- }
557-
558459func Logs (ctx * context_module.Context ) {
559460 runIndex := getRunIndex (ctx )
560461 jobIndex := ctx .PathParamInt64 ("job" )
0 commit comments