mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	show workflow config error on file view also (#24267)
As title, follow #24124  --------- Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -29,6 +29,14 @@ func init() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func IsWorkflow(path string) bool {
 | 
				
			||||||
 | 
						if (!strings.HasSuffix(path, ".yaml")) && (!strings.HasSuffix(path, ".yml")) {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return strings.HasPrefix(path, ".gitea/workflows") || strings.HasPrefix(path, ".github/workflows")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ListWorkflows(commit *git.Commit) (git.Entries, error) {
 | 
					func ListWorkflows(commit *git.Commit) (git.Entries, error) {
 | 
				
			||||||
	tree, err := commit.SubTree(".gitea/workflows")
 | 
						tree, err := commit.SubTree(".gitea/workflows")
 | 
				
			||||||
	if _, ok := err.(git.ErrNotExist); ok {
 | 
						if _, ok := err.(git.ErrNotExist); ok {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ import (
 | 
				
			|||||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
						repo_model "code.gitea.io/gitea/models/repo"
 | 
				
			||||||
	unit_model "code.gitea.io/gitea/models/unit"
 | 
						unit_model "code.gitea.io/gitea/models/unit"
 | 
				
			||||||
	user_model "code.gitea.io/gitea/models/user"
 | 
						user_model "code.gitea.io/gitea/models/user"
 | 
				
			||||||
 | 
						"code.gitea.io/gitea/modules/actions"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/base"
 | 
						"code.gitea.io/gitea/modules/base"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/charset"
 | 
						"code.gitea.io/gitea/modules/charset"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/container"
 | 
						"code.gitea.io/gitea/modules/container"
 | 
				
			||||||
@@ -39,6 +40,8 @@ import (
 | 
				
			|||||||
	"code.gitea.io/gitea/modules/typesniffer"
 | 
						"code.gitea.io/gitea/modules/typesniffer"
 | 
				
			||||||
	"code.gitea.io/gitea/modules/util"
 | 
						"code.gitea.io/gitea/modules/util"
 | 
				
			||||||
	"code.gitea.io/gitea/routers/web/feed"
 | 
						"code.gitea.io/gitea/routers/web/feed"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/nektos/act/pkg/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
@@ -348,6 +351,15 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
 | 
				
			|||||||
		if issueConfigErr != nil {
 | 
							if issueConfigErr != nil {
 | 
				
			||||||
			ctx.Data["FileError"] = strings.TrimSpace(issueConfigErr.Error())
 | 
								ctx.Data["FileError"] = strings.TrimSpace(issueConfigErr.Error())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						} else if actions.IsWorkflow(ctx.Repo.TreePath) {
 | 
				
			||||||
 | 
							content, err := actions.GetContentFromEntry(entry)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								log.Error("actions.GetContentFromEntry: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							_, workFlowErr := model.ReadWorkflow(bytes.NewReader(content))
 | 
				
			||||||
 | 
							if workFlowErr != nil {
 | 
				
			||||||
 | 
								ctx.Data["FileError"] = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", workFlowErr.Error())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	isDisplayingSource := ctx.FormString("display") == "source"
 | 
						isDisplayingSource := ctx.FormString("display") == "source"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user