diff --git a/models/actions/run.go b/models/actions/run.go index 4656aa22a2933..2c73eb942f76c 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -375,3 +375,34 @@ func UpdateRun(ctx context.Context, run *ActionRun, cols ...string) error { } type ActionRunIndex db.ResourceIndex + +type WorkflowRunsStatus struct { + NumRuns int64 + NumOpenRuns int64 + NumClosedRuns int64 +} + +func GetRepoWorkflowRunsStatus(ctx context.Context, repoID int64, workflowID string) (wrs WorkflowRunsStatus, err error) { + wrs.NumRuns, err = db.Count[ActionRun](ctx, FindRunOptions{ + RepoID: repoID, + WorkflowID: workflowID, + }) + if err != nil { + return wrs, err + } + wrs.NumClosedRuns, err = db.Count[ActionRun](ctx, FindRunOptions{ + RepoID: repoID, + WorkflowID: workflowID, + Status: []Status{ + StatusSuccess, + StatusFailure, + StatusCancelled, + StatusSkipped, + }, + }) + if err != nil { + return wrs, err + } + wrs.NumOpenRuns = wrs.NumRuns - wrs.NumClosedRuns + return wrs, err +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index fa7eee9bc5587..78c06d9d0fe77 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3534,6 +3534,7 @@ runs.no_workflows.quick_start = Don't know how to start with Gitea Action? See < runs.no_workflows.documentation = For more information on the Gitea Action, see the documentation. runs.no_runs = The workflow has no runs yet. runs.empty_commit_message = (empty commit message) +runs.status_count = %d workflow runs (%d open runs, %d closed runs) workflow.disable = Disable Workflow workflow.disable_success = Workflow '%s' disabled successfully. diff --git a/routers/web/repo/actions/actions.go b/routers/web/repo/actions/actions.go index 3b10f0b9571eb..2af7124498bd6 100644 --- a/routers/web/repo/actions/actions.go +++ b/routers/web/repo/actions/actions.go @@ -30,8 +30,34 @@ const ( ) type Workflow struct { - Entry git.TreeEntry - ErrMsg string + Entry git.TreeEntry + RunsStatus actions_model.WorkflowRunsStatus + ErrMsg string +} +type WorkflowMap map[string]Workflow + +func (wfs WorkflowMap) TotalRuns() int64 { + var total int64 + for _, wf := range wfs { + total += wf.RunsStatus.NumRuns + } + return total +} + +func (wfs WorkflowMap) TotalOpenRuns() int64 { + var total int64 + for _, wf := range wfs { + total += wf.RunsStatus.NumOpenRuns + } + return total +} + +func (wfs WorkflowMap) TotalClosedRuns() int64 { + var total int64 + for _, wf := range wfs { + total += wf.RunsStatus.NumClosedRuns + } + return total } // MustEnableActions check if actions are enabled in settings @@ -58,7 +84,7 @@ func List(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("actions.actions") ctx.Data["PageIsActions"] = true - var workflows []Workflow + var workflows WorkflowMap if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return @@ -88,9 +114,18 @@ func List(ctx *context.Context) { allRunnerLabels.AddMultiple(r.AgentLabels...) } - workflows = make([]Workflow, 0, len(entries)) + workflows = make(WorkflowMap, 0) for _, entry := range entries { workflow := Workflow{Entry: *entry} + workflowID := entry.Name() + + // Get workflow runs status + workflow.RunsStatus, err = actions_model.GetRepoWorkflowRunsStatus(ctx, ctx.Repo.Repository.ID, entry.Name()) + if err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + content, err := actions.GetContentFromEntry(entry) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) @@ -99,9 +134,10 @@ func List(ctx *context.Context) { wf, err := model.ReadWorkflow(bytes.NewReader(content)) if err != nil { workflow.ErrMsg = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", err.Error()) - workflows = append(workflows, workflow) + workflows[workflowID] = workflow continue } + // Check whether have matching runner for _, j := range wf.Jobs { runsOnList := j.RunsOn() @@ -121,10 +157,10 @@ func List(ctx *context.Context) { break } } - workflows = append(workflows, workflow) + workflows[workflowID] = workflow } } - ctx.Data["workflows"] = workflows + ctx.Data["Workflows"] = workflows ctx.Data["RepoLink"] = ctx.Repo.Repository.Link() page := ctx.FormInt("page") diff --git a/templates/repo/actions/list.tmpl b/templates/repo/actions/list.tmpl index ede4c82602da2..5aeaca5451cab 100644 --- a/templates/repo/actions/list.tmpl +++ b/templates/repo/actions/list.tmpl @@ -4,77 +4,95 @@