Skip to content
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
13 changes: 13 additions & 0 deletions modules/actions/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) {
return events, nil
}

// ValidateWorkflowContent catches structural errors (e.g. blank lines in run: | blocks)
// that model.ReadWorkflow alone does not detect.
func ValidateWorkflowContent(content []byte) error {
_, err := jobparser.Parse(content)
return err
}

func DetectWorkflows(
gitRepo *git.Repository,
commit *git.Commit,
Expand All @@ -129,6 +136,9 @@ func DetectWorkflows(

// one workflow may have multiple events
events, err := GetEventsFromContent(content)
if err == nil {
err = ValidateWorkflowContent(content)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? GetEventsFromContent already does something.

image

if err != nil {
log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
continue
Expand Down Expand Up @@ -173,6 +183,9 @@ func DetectScheduledWorkflows(gitRepo *git.Repository, commit *git.Commit) ([]*D

// one workflow may have multiple events
events, err := GetEventsFromContent(content)
if err == nil {
err = ValidateWorkflowContent(content)
}
if err != nil {
log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
continue
Expand Down
5 changes: 5 additions & 0 deletions routers/web/repo/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func prepareWorkflowTemplate(ctx *context.Context, commit *git.Commit) (workflow
workflows = append(workflows, workflow)
continue
}
if err := actions.ValidateWorkflowContent(content); err != nil {
workflow.ErrMsg = ctx.Locale.TrString("actions.runs.invalid_workflow_helper", err.Error())
workflows = append(workflows, workflow)
continue
}
workflow.Workflow = wf
// 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
Expand Down
5 changes: 1 addition & 4 deletions routers/web/repo/view_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context"
issue_service "code.gitea.io/gitea/services/issue"

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

func prepareLatestCommitInfo(ctx *context.Context) bool {
Expand Down Expand Up @@ -184,8 +182,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {
if err != nil {
log.Error("actions.GetContentFromEntry: %v", err)
}
_, workFlowErr := model.ReadWorkflow(bytes.NewReader(content))
if workFlowErr != nil {
if workFlowErr := actions.ValidateWorkflowContent(content); workFlowErr != nil {
ctx.Data["FileError"] = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", workFlowErr.Error())
}
} else if issue_service.IsCodeOwnerFile(ctx.Repo.TreePath) {
Expand Down