mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-01 17:38:33 +00:00
feat(api): return run info for dispatched workflows (#7193)
- When the API endpoint `/repos/{owner}/{repo}/actions/workflows/{workflowname}/dispatches` is used to launch a workflow, it currently returns no data; `/repos/{owner}/{repo}/actions/tasks` can be used to track the progress of a workflow, but you need at least that workflow's run_id and the quantity of its child jobs. Tracking workflow progress is especially important if you want to chain together multiple workflows that exist within different repositories, which is desired for https://codeberg.org/forgejo/forgejo/issues/6312. - Make it possible to track the progress of manually triggered workflows by modifying the `/repos/{owner}/{repo}/actions/workflows/{workflowname}/dispatches` to return a JSON object containing the triggered workflow's id and a list of its child job names. Co-authored-by: Andrii Chyrva <achyrva@amcbridge.com> Co-authored-by: Andrii Chyrva <andrii.s.chyrva@hotmail.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7193 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: markturney <markturney@gmail.com> Co-committed-by: markturney <markturney@gmail.com>
This commit is contained in:
parent
c7cb5f9978
commit
7a19d3c2be
7 changed files with 88 additions and 13 deletions
|
@ -20,6 +20,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
|
||||
|
@ -49,15 +50,15 @@ type Workflow struct {
|
|||
|
||||
type InputValueGetter func(key string) string
|
||||
|
||||
func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGetter, repo *repo_model.Repository, doer *user.User) error {
|
||||
func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGetter, repo *repo_model.Repository, doer *user.User) (r *actions_model.ActionRun, j []string, err error) {
|
||||
content, err := actions.GetContentFromEntry(entry.GitEntry)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
wf, err := act_model.ReadWorkflow(bytes.NewReader(content))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
fullWorkflowID := ".forgejo/workflows/" + entry.WorkflowID
|
||||
|
@ -79,7 +80,7 @@ func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGette
|
|||
if len(name) == 0 {
|
||||
name = key
|
||||
}
|
||||
return InputRequiredErr{Name: name}
|
||||
return nil, nil, InputRequiredErr{Name: name}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -92,9 +93,11 @@ func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGette
|
|||
}
|
||||
|
||||
if int64(len(inputs)) > setting.Actions.LimitDispatchInputs {
|
||||
return errors.New("to many inputs")
|
||||
return nil, nil, errors.New("to many inputs")
|
||||
}
|
||||
|
||||
jobNames := util.KeysOfMap(wf.Jobs)
|
||||
|
||||
payload := &structs.WorkflowDispatchPayload{
|
||||
Inputs: inputs,
|
||||
Ref: entry.Ref,
|
||||
|
@ -105,7 +108,7 @@ func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGette
|
|||
|
||||
p, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
run := &actions_model.ActionRun{
|
||||
|
@ -126,15 +129,15 @@ func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGette
|
|||
|
||||
vars, err := actions_model.GetVariablesOfRun(ctx, run)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
jobs, err := jobparser.Parse(content, jobparser.WithVars(vars))
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return actions_model.InsertRun(ctx, run, jobs)
|
||||
return run, jobNames, actions_model.InsertRun(ctx, run, jobs)
|
||||
}
|
||||
|
||||
func GetWorkflowFromCommit(gitRepo *git.Repository, ref, workflowID string) (*Workflow, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue