8000 fix(api): avoid two worflows files on push (#3481) · ovh/cds@4c725a6 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 4c725a6

Browse files
authored
fix(api): avoid two worflows files on push (#3481)
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
1 parent 6b5c785 commit 4c725a6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

engine/api/workflow/dao.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
954954
return nil, nil, sdk.WithStack(err)
955955
}
956956

957+
var workflowFileName string
957958
b := buff.Bytes()
958959
switch {
959960
case strings.Contains(hdr.Name, ".app."):
@@ -981,11 +982,18 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
981982
}
982983
envs[hdr.Name] = env
983984
default:
985+
// if a workflow was already found, it's a mistake
986+
if workflowFileName != "" {
987+
log.Error("two workflows files found: %s and %s", workflowFileName, hdr.Name)
988+
mError.Append(fmt.Errorf("two workflows files found: %s and %s", workflowFileName, hdr.Name))
989+
break
990+
}
984991
if err := yaml.Unmarshal(b, &wrkflw); err != nil {
985992
log.Error("Push> Unable to unmarshal workflow %s: %v", hdr.Name, err)
986993
mError.Append(fmt.Errorf("Unable to unmarshal workflow %s: %v", hdr.Name, err))
987994
continue
988995
}
996+
workflowFileName = hdr.Name
989997
}
990998
}
991999

engine/api/workflow/dao_outgoing_hook_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func LoadOutgoingHookModelByID(db gorp.SqlExecutor, id int64) (*sdk.WorkflowHook
114114
query := "select id, name, type, command, default_config, author, description, identifier, icon from workflow_outgoing_hook_model where id = $1"
115115
if err := db.SelectOne(&m, query, id); err != nil {
116116
if err == sql.ErrNoRows {
117-
return nil, sdk.WrapError(sdk.ErrNotFound, "LoadOutgoingHookModelByID> Unable to load WorkflowHookModel")
117+
return nil, sdk.WrapError(sdk.ErrNotFound, "workflow_outgoing_hook_model with id %d not found", id)
118118
}
119119
return nil, sdk.WrapError(err, "Unable to load WorkflowHookModel")
120120
}

engine/api/workflow_run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,10 @@ func (api *API) postWorkflowRunHandler() service.Handler {
807807
}
808808
}
809809

810+
if name != wf.Name {
811+
return sdk.WrapError(sdk.ErrWorkflowInvalid, "workflow %s asked, but workflow %s found", name, wf.Name)
812+
}
813+
810814
report, errS := startWorkflowRun(ctx, api.mustDB(), api.Cache, p, wf, lastRun, opts, u, asCodeInfosMsg)
811815
if errS != nil {
812816
return sdk.WrapError(errS, "postWorkflowRunHandler> Unable to start workflow %s/%s", key, name)

0 commit comments

Comments
 (0)
0