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

Add runner check in repo action page #24124

Merged
merged 7 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3407,5 +3407,6 @@ runs.commit = Commit
runs.pushed_by = Pushed by
runs.valid_workflow_helper = Workflow config file is valid.
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
runs.no_matching_runner_helper = No matching runner in job: %s

need_approval_desc = Need approval to run workflows for fork pull request.
46 changes: 43 additions & 3 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/convert"

"github.com/nektos/act/pkg/jobparser"
)

const (
Expand All @@ -24,9 +28,10 @@ const (
)

type Workflow struct {
Entry git.TreeEntry
IsInvalid bool
ErrMsg string
Entry git.TreeEntry
IsInvalid bool
HaveMatchingRunner bool
ErrMsg string
}

// MustEnableActions check if actions are enabled in settings
Expand Down Expand Up @@ -86,6 +91,41 @@ func List(ctx *context.Context) {
workflow.IsInvalid = true
workflow.ErrMsg = err.Error()
}
// Check whether have matching runner
opts := actions_model.FindRunnerOptions{
RepoID: ctx.Repo.Repository.ID,
WithAvailable: true,
}
runners, err := actions_model.FindRunners(ctx, opts)
if err != nil {
ctx.ServerError("FindRunners", err)
return
}
allRunnerLabels := make(container.Set[string])
for _, r := range runners {
allRunnerLabels.AddMultiple(r.AgentLabels...)
allRunnerLabels.AddMultiple(r.CustomLabels...)
}
jobs, err := jobparser.Parse(content)
if err != nil {
log.Error("jobparser.Parse: %v", err)
continue
}
matchRunner := true
for _, v := range jobs {
id, job := v.Job()
runsOnList := job.RunsOn()
for _, ro := range runsOnList {
if !allRunnerLabels.Contains(ro) {
matchRunner = false
workflow.ErrMsg = id
break
}
}
}
if matchRunner {
workflow.HaveMatchingRunner = true
}
workflows = append(workflows, workflow)
}
}
Expand Down
5 changes: 5 additions & 0 deletions templates/repo/actions/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<i class="check icon green"></i>
</span>
{{end}}
{{if not .HaveMatchingRunner}}
<span data-tooltip-content="{{$.locale.Tr "actions.runs.no_matching_runner_helper" (.ErrMsg)}}">
<i class="warning icon red"></i>
</span>
{{end}}
</a>
{{end}}
</div>
Expand Down