Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Workflow names instead of workflow file name #31474

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ const (
)

type Workflow struct {
Entry git.TreeEntry
ErrMsg string
Entry git.TreeEntry
ErrMsg string
Name string
WorkflowID string
}

type Run struct {
ActionRun actions_model.ActionRun
Workflow Workflow
}

// MustEnableActions check if actions are enabled in settings
Expand Down Expand Up @@ -60,6 +67,7 @@ func List(ctx *context.Context) {
ctx.Data["PageIsActions"] = true

var workflows []Workflow
var runs []Run
if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil {
ctx.ServerError("IsEmpty", err)
return
Expand Down Expand Up @@ -92,7 +100,7 @@ func List(ctx *context.Context) {

workflows = make([]Workflow, 0, len(entries))
for _, entry := range entries {
workflow := Workflow{Entry: *entry}
workflow := Workflow{Entry: *entry, WorkflowID: entry.Name(), Name: entry.Name()}
content, err := actions.GetContentFromEntry(entry)
if err != nil {
ctx.ServerError("GetContentFromEntry", err)
Expand All @@ -104,6 +112,12 @@ func List(ctx *context.Context) {
workflows = append(workflows, workflow)
continue
}

// The workflow name is the name from the yaml file, otherwise remains the filename.
if wf.Name != "" {
workflow.Name = wf.Name
}

// 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"
Expand Down Expand Up @@ -186,22 +200,32 @@ func List(ctx *context.Context) {
opts.Status = []actions_model.Status{actions_model.Status(status)}
}

runs, total, err := db.FindAndCount[actions_model.ActionRun](ctx, opts)
actionRuns, total, err := db.FindAndCount[actions_model.ActionRun](ctx, opts)
if err != nil {
ctx.ServerError("FindAndCount", err)
return
}

for _, run := range runs {
run.Repo = ctx.Repo.Repository
}

if err := actions_model.RunList(runs).LoadTriggerUser(ctx); err != nil {
if err := actions_model.RunList(actionRuns).LoadTriggerUser(ctx); err != nil {
ctx.ServerError("LoadTriggerUser", err)
return
}

ctx.Data["Runs"] = runs
runs = make([]Run, 0, len(actionRuns))
for _, actionRun := range actionRuns {
actionRun.Repo = ctx.Repo.Repository
run := Run{ActionRun: *actionRun}

// Connect the workflow to the run
for _, wf := range workflows {
if wf.WorkflowID == actionRun.WorkflowID {
run.Workflow = wf
}
}
runs = append(runs, run)
}

ctx.Data["WorkflowActionRuns"] = runs

actors, err := actions_model.GetActors(ctx, ctx.Repo.Repository.ID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/actions/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="ui fluid vertical menu">
<a class="item{{if not $.CurWorkflow}} active{{end}}" href="?actor={{$.CurActor}}&status={{$.CurStatus}}">{{ctx.Locale.Tr "actions.runs.all_workflows"}}</a>
{{range .workflows}}
<a class="item{{if eq .Entry.Name $.CurWorkflow}} active{{end}}" href="?workflow={{.Entry.Name}}&actor={{$.CurActor}}&status={{$.CurStatus}}">{{.Entry.Name}}
<a class="item{{if eq .Entry.Name $.CurWorkflow}} active{{end}}" href="?workflow={{.Entry.Name}}&actor={{$.CurActor}}&status={{$.CurStatus}}">{{.Name}}
{{if .ErrMsg}}
<span data-tooltip-content="{{.ErrMsg}}">
{{svg "octicon-alert" 16 "text red"}}
Expand Down
30 changes: 16 additions & 14 deletions templates/repo/actions/runs_list.tmpl
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
<div class="flex-list run-list">
{{if not .Runs}}
{{if not .WorkflowActionRuns}}
<div class="empty-placeholder">
{{svg "octicon-no-entry" 48}}
<h2>{{if $.IsFiltered}}{{ctx.Locale.Tr "actions.runs.no_results"}}{{else}}{{ctx.Locale.Tr "actions.runs.no_runs"}}{{end}}</h2>
</div>
{{end}}
{{range .Runs}}
{{range $run := .WorkflowActionRuns}}
{{$actionRun := $run.ActionRun}}
{{$workflow := $run.Workflow}}
<div class="flex-item tw-items-center">
<div class="flex-item-leading">
{{template "repo/actions/status" (dict "status" .Status.String)}}
{{template "repo/actions/status" (dict "status" $actionRun.Status.String)}}
</div>
<div class="flex-item-main">
<a class="flex-item-title" title="{{.Title}}" href="{{if .Link}}{{.Link}}{{else}}{{$.Link}}/{{.Index}}{{end}}">
{{if .Title}}{{.Title}}{{else}}{{ctx.Locale.Tr "actions.runs.empty_commit_message"}}{{end}}
<a class="flex-item-title" title="{{$actionRun.Title}}" href="{{if $actionRun.Link}}{{$actionRun.Link}}{{else}}{{$.Link}}/{{$actionRun.Index}}{{end}}">
{{if $actionRun.Title}}{{$actionRun.Title}}{{else}}{{ctx.Locale.Tr "actions.runs.empty_commit_message"}}{{end}}
</a>
<div class="flex-item-body">
<span><b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>:</span>
{{- if .ScheduleID -}}
<span><b>{{if not $.CurWorkflow}}{{$workflow.Name}} {{end}}#{{$actionRun.Index}}</b>:</span>
{{- if $actionRun.ScheduleID -}}
{{ctx.Locale.Tr "actions.runs.scheduled"}}
{{- else -}}
{{ctx.Locale.Tr "actions.runs.commit"}}
<a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{ShortSha .CommitSHA}}</a>
<a href="{{$.RepoLink}}/commit/{{$actionRun.CommitSHA}}">{{ShortSha $actionRun.CommitSHA}}</a>
{{ctx.Locale.Tr "actions.runs.pushed_by"}}
<a href="{{.TriggerUser.HomeLink}}">{{.TriggerUser.GetDisplayName}}</a>
<a href="{{$actionRun.TriggerUser.HomeLink}}">{{$actionRun.TriggerUser.GetDisplayName}}</a>
{{- end -}}
</div>
</div>
<div class="flex-item-trailing">
{{if .RefLink}}
<a class="ui label run-list-ref gt-ellipsis" href="{{.RefLink}}">{{.PrettyRef}}</a>
{{if $actionRun.RefLink}}
<a class="ui label run-list-ref gt-ellipsis" href="{{$actionRun.RefLink}}">{{$actionRun.PrettyRef}}</a>
{{else}}
<span class="ui label run-list-ref gt-ellipsis">{{.PrettyRef}}</span>
<span class="ui label run-list-ref gt-ellipsis">{{$actionRun.PrettyRef}}</span>
{{end}}
<div class="run-list-item-right">
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{TimeSinceUnix .Updated ctx.Locale}}</div>
<div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{.Duration}}</div>
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{TimeSinceUnix $actionRun.Updated ctx.Locale}}</div>
<div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{$actionRun.Duration}}</div>
</div>
</div>
</div>
Expand Down