mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Add workflow error notification in ui (#23404)
  --------- Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		@@ -44,6 +44,32 @@ func ListWorkflows(commit *git.Commit) (git.Entries, error) {
 | 
				
			|||||||
	return ret, nil
 | 
						return ret, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetContentFromEntry(entry *git.TreeEntry) ([]byte, error) {
 | 
				
			||||||
 | 
						f, err := entry.Blob().DataAsync()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						content, err := io.ReadAll(f)
 | 
				
			||||||
 | 
						_ = f.Close()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return content, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) {
 | 
				
			||||||
 | 
						workflow, err := model.ReadWorkflow(bytes.NewReader(content))
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						events, err := jobparser.ParseRawOn(&workflow.RawOn)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return events, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventType, payload api.Payloader) (map[string][]byte, error) {
 | 
					func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventType, payload api.Payloader) (map[string][]byte, error) {
 | 
				
			||||||
	entries, err := ListWorkflows(commit)
 | 
						entries, err := ListWorkflows(commit)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -52,21 +78,11 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	workflows := make(map[string][]byte, len(entries))
 | 
						workflows := make(map[string][]byte, len(entries))
 | 
				
			||||||
	for _, entry := range entries {
 | 
						for _, entry := range entries {
 | 
				
			||||||
		f, err := entry.Blob().DataAsync()
 | 
							content, err := GetContentFromEntry(entry)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		content, err := io.ReadAll(f)
 | 
							events, err := GetEventsFromContent(content)
 | 
				
			||||||
		_ = f.Close()
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, err
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		workflow, err := model.ReadWorkflow(bytes.NewReader(content))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		events, err := jobparser.ParseRawOn(&workflow.RawOn)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
 | 
								log.Warn("ignore invalid workflow %q: %v", entry.Name(), err)
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3360,5 +3360,7 @@ runs.open_tab = %d Open
 | 
				
			|||||||
runs.closed_tab = %d Closed
 | 
					runs.closed_tab = %d Closed
 | 
				
			||||||
runs.commit = Commit
 | 
					runs.commit = Commit
 | 
				
			||||||
runs.pushed_by = Pushed by
 | 
					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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
need_approval_desc = Need approval to run workflows for fork pull request.
 | 
					need_approval_desc = Need approval to run workflows for fork pull request.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,12 @@ const (
 | 
				
			|||||||
	tplViewActions base.TplName = "repo/actions/view"
 | 
						tplViewActions base.TplName = "repo/actions/view"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Workflow struct {
 | 
				
			||||||
 | 
						Entry     git.TreeEntry
 | 
				
			||||||
 | 
						IsInvalid bool
 | 
				
			||||||
 | 
						ErrMsg    string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// MustEnableActions check if actions are enabled in settings
 | 
					// MustEnableActions check if actions are enabled in settings
 | 
				
			||||||
func MustEnableActions(ctx *context.Context) {
 | 
					func MustEnableActions(ctx *context.Context) {
 | 
				
			||||||
	if !setting.Actions.Enabled {
 | 
						if !setting.Actions.Enabled {
 | 
				
			||||||
@@ -47,7 +53,7 @@ func List(ctx *context.Context) {
 | 
				
			|||||||
	ctx.Data["Title"] = ctx.Tr("actions.actions")
 | 
						ctx.Data["Title"] = ctx.Tr("actions.actions")
 | 
				
			||||||
	ctx.Data["PageIsActions"] = true
 | 
						ctx.Data["PageIsActions"] = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var workflows git.Entries
 | 
						var workflows []Workflow
 | 
				
			||||||
	if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil {
 | 
						if empty, err := ctx.Repo.GitRepo.IsEmpty(); err != nil {
 | 
				
			||||||
		ctx.Error(http.StatusInternalServerError, err.Error())
 | 
							ctx.Error(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
@@ -62,13 +68,27 @@ func List(ctx *context.Context) {
 | 
				
			|||||||
			ctx.Error(http.StatusInternalServerError, err.Error())
 | 
								ctx.Error(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		workflows, err = actions.ListWorkflows(commit)
 | 
							entries, err := actions.ListWorkflows(commit)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			ctx.Error(http.StatusInternalServerError, err.Error())
 | 
								ctx.Error(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							workflows = make([]Workflow, 0, len(entries))
 | 
				
			||||||
 | 
							for _, entry := range entries {
 | 
				
			||||||
 | 
								workflow := Workflow{Entry: *entry}
 | 
				
			||||||
 | 
								content, err := actions.GetContentFromEntry(entry)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									ctx.Error(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
 | 
									return
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								_, err = actions.GetEventsFromContent(content)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									workflow.IsInvalid = true
 | 
				
			||||||
 | 
									workflow.ErrMsg = err.Error()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								workflows = append(workflows, workflow)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	ctx.Data["workflows"] = workflows
 | 
						ctx.Data["workflows"] = workflows
 | 
				
			||||||
	ctx.Data["RepoLink"] = ctx.Repo.Repository.Link()
 | 
						ctx.Data["RepoLink"] = ctx.Repo.Repository.Link()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,17 @@
 | 
				
			|||||||
					<a class="item{{if not $.CurWorkflow}} active{{end}}" href="{{$.Link}}">{{.locale.Tr "actions.runs.all_workflows"}}</a>
 | 
										<a class="item{{if not $.CurWorkflow}} active{{end}}" href="{{$.Link}}">{{.locale.Tr "actions.runs.all_workflows"}}</a>
 | 
				
			||||||
					<div class="divider"></div>
 | 
										<div class="divider"></div>
 | 
				
			||||||
					{{range .workflows}}
 | 
										{{range .workflows}}
 | 
				
			||||||
						<a class="item{{if eq .Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Name}}">{{.Name}}</a>
 | 
											<a class="item{{if eq .Entry.Name $.CurWorkflow}} active{{end}}" href="{{$.Link}}?workflow={{.Entry.Name}}">{{.Entry.Name}}
 | 
				
			||||||
 | 
												{{if .IsInvalid}}
 | 
				
			||||||
 | 
													<span class="tooltip" data-content="{{$.locale.Tr "actions.runs.invalid_workflow_helper" (.ErrMsg)}}">
 | 
				
			||||||
 | 
														<i class="warning icon red"></i>
 | 
				
			||||||
 | 
													</span>
 | 
				
			||||||
 | 
												{{else}}
 | 
				
			||||||
 | 
													<span class="tooltip" data-content="{{$.locale.Tr "actions.runs.valid_workflow_helper"}}">
 | 
				
			||||||
 | 
														<i class="check icon green"></i>
 | 
				
			||||||
 | 
													</span>
 | 
				
			||||||
 | 
												{{end}}
 | 
				
			||||||
 | 
											</a>
 | 
				
			||||||
					{{end}}
 | 
										{{end}}
 | 
				
			||||||
				</div>
 | 
									</div>
 | 
				
			||||||
			</div>
 | 
								</div>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user