Skip to content

Commit 01214c8

Browse files
authored
Add runner check in repo action page (#24124)
![image](https://user-images.githubusercontent.com/18380374/232996647-13c2b9f1-c9e9-42d9-acbf-8a6e16b175a6.png) Maybe we can also add online runner check? e.g. : Target runner is offline.
1 parent 5e7543f commit 01214c8

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

options/locale/locale_en-US.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -3407,7 +3407,7 @@ runs.open_tab = %d Open
34073407
runs.closed_tab = %d Closed
34083408
runs.commit = Commit
34093409
runs.pushed_by = Pushed by
3410-
runs.valid_workflow_helper = Workflow config file is valid.
34113410
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
3411+
runs.no_matching_runner_helper = No matching runner: %s
34123412
34133413
need_approval_desc = Need approval to run workflows for fork pull request.

routers/web/repo/actions/actions.go

+40-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
package actions
55

66
import (
7+
"bytes"
78
"net/http"
89

910
actions_model "code.gitea.io/gitea/models/actions"
1011
"code.gitea.io/gitea/models/db"
1112
"code.gitea.io/gitea/models/unit"
1213
"code.gitea.io/gitea/modules/actions"
1314
"code.gitea.io/gitea/modules/base"
15+
"code.gitea.io/gitea/modules/container"
1416
"code.gitea.io/gitea/modules/context"
1517
"code.gitea.io/gitea/modules/git"
1618
"code.gitea.io/gitea/modules/setting"
1719
"code.gitea.io/gitea/modules/util"
1820
"code.gitea.io/gitea/services/convert"
21+
22+
"github.com/nektos/act/pkg/model"
1923
)
2024

2125
const (
@@ -24,9 +28,8 @@ const (
2428
)
2529

2630
type Workflow struct {
27-
Entry git.TreeEntry
28-
IsInvalid bool
29-
ErrMsg string
31+
Entry git.TreeEntry
32+
ErrMsg string
3033
}
3134

3235
// MustEnableActions check if actions are enabled in settings
@@ -73,6 +76,23 @@ func List(ctx *context.Context) {
7376
ctx.Error(http.StatusInternalServerError, err.Error())
7477
return
7578
}
79+
80+
// Get all runner labels
81+
opts := actions_model.FindRunnerOptions{
82+
RepoID: ctx.Repo.Repository.ID,
83+
WithAvailable: true,
84+
}
85+
runners, err := actions_model.FindRunners(ctx, opts)
86+
if err != nil {
87+
ctx.ServerError("FindRunners", err)
88+
return
89+
}
90+
allRunnerLabels := make(container.Set[string])
91+
for _, r := range runners {
92+
allRunnerLabels.AddMultiple(r.AgentLabels...)
93+
allRunnerLabels.AddMultiple(r.CustomLabels...)
94+
}
95+
7696
workflows = make([]Workflow, 0, len(entries))
7797
for _, entry := range entries {
7898
workflow := Workflow{Entry: *entry}
@@ -81,10 +101,24 @@ func List(ctx *context.Context) {
81101
ctx.Error(http.StatusInternalServerError, err.Error())
82102
return
83103
}
84-
_, err = actions.GetEventsFromContent(content)
104+
wf, err := model.ReadWorkflow(bytes.NewReader(content))
85105
if err != nil {
86-
workflow.IsInvalid = true
87-
workflow.ErrMsg = err.Error()
106+
workflow.ErrMsg = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", err.Error())
107+
workflows = append(workflows, workflow)
108+
continue
109+
}
110+
// Check whether have matching runner
111+
for _, j := range wf.Jobs {
112+
runsOnList := j.RunsOn()
113+
for _, ro := range runsOnList {
114+
if !allRunnerLabels.Contains(ro) {
115+
workflow.ErrMsg = ctx.Locale.Tr("actions.runs.no_matching_runner_helper", ro)
116+
break
117+
}
118+
}
119+
if workflow.ErrMsg != "" {
120+
break
121+
}
88122
}
89123
workflows = append(workflows, workflow)
90124
}

templates/repo/actions/list.tmpl

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
<div class="divider"></div>
1111
{{range .workflows}}
1212
<a class="item{{if eq .Entry.Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Entry.Name}}">{{.Entry.Name}}
13-
{{if .IsInvalid}}
14-
<span data-tooltip-content="{{$.locale.Tr "actions.runs.invalid_workflow_helper" (.ErrMsg)}}">
13+
{{if .ErrMsg}}
14+
<span data-tooltip-content="{{.ErrMsg}}">
1515
<i class="warning icon red"></i>
1616
</span>
17-
{{else}}
18-
<span data-tooltip-content="{{$.locale.Tr "actions.runs.valid_workflow_helper"}}">
19-
<i class="check icon green"></i>
20-
</span>
2117
{{end}}
2218
</a>
2319
{{end}}

0 commit comments

Comments
 (0)