Skip to content

Commit

Permalink
fix(api): avoid two worflows files on push (#3481)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Oct 22, 2018
1 parent 6b5c785 commit 4c725a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions engine/api/workflow/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
return nil, nil, sdk.WithStack(err)
}

var workflowFileName string
b := buff.Bytes()
switch {
case strings.Contains(hdr.Name, ".app."):
Expand Down Expand Up @@ -981,11 +982,18 @@ func Push(ctx context.Context, db *gorp.DbMap, store cache.Store, proj *sdk.Proj
}
envs[hdr.Name] = env
default:
// if a workflow was already found, it's a mistake
if workflowFileName != "" {
log.Error("two workflows files found: %s and %s", workflowFileName, hdr.Name)
mError.Append(fmt.Errorf("two workflows files found: %s and %s", workflowFileName, hdr.Name))
break
}
if err := yaml.Unmarshal(b, &wrkflw); err != nil {
log.Error("Push> Unable to unmarshal workflow %s: %v", hdr.Name, err)
mError.Append(fmt.Errorf("Unable to unmarshal workflow %s: %v", hdr.Name, err))
continue
}
workflowFileName = hdr.Name
}
}

Expand Down
2 changes: 1 addition & 1 deletion engine/api/workflow/dao_outgoing_hook_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func LoadOutgoingHookModelByID(db gorp.SqlExecutor, id int64) (*sdk.WorkflowHook
query := "select id, name, type, command, default_config, author, description, identifier, icon from workflow_outgoing_hook_model where id = $1"
if err := db.SelectOne(&m, query, id); err != nil {
if err == sql.ErrNoRows {
return nil, sdk.WrapError(sdk.ErrNotFound, "LoadOutgoingHookModelByID> Unable to load WorkflowHookModel")
return nil, sdk.WrapError(sdk.ErrNotFound, "workflow_outgoing_hook_model with id %d not found", id)
}
return nil, sdk.WrapError(err, "Unable to load WorkflowHookModel")
}
Expand Down
4 changes: 4 additions & 0 deletions engine/api/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,10 @@ func (api *API) postWorkflowRunHandler() service.Handler {
}
}

if name != wf.Name {
return sdk.WrapError(sdk.ErrWorkflowInvalid, "workflow %s asked, but workflow %s found", name, wf.Name)
}

report, errS := startWorkflowRun(ctx, api.mustDB(), api.Cache, p, wf, lastRun, opts, u, asCodeInfosMsg)
if errS != nil {
return sdk.WrapError(errS, "postWorkflowRunHandler> Unable to start workflow %s/%s", key, name)
Expand Down

0 comments on commit 4c725a6

Please sign in to comment.