diff --git a/engine/api/action/children.go b/engine/api/action/children.go index 01612fe7b0..e1f04bb301 100644 --- a/engine/api/action/children.go +++ b/engine/api/action/children.go @@ -10,11 +10,11 @@ import ( "github.com/ovh/cds/sdk/log" ) -func insertEdge(db gorp.SqlExecutor, parentID, childID int64, execOrder int, optional, alwaysExecuted, enabled bool) (int64, error) { - query := `INSERT INTO action_edge (parent_id, child_id, exec_order, optional, always_executed, enabled) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id` +func insertEdge(db gorp.SqlExecutor, parentID, childID int64, execOrder int, stepName string, optional, alwaysExecuted, enabled bool) (int64, error) { + query := `INSERT INTO action_edge (parent_id, child_id, exec_order, step_name, optional, always_executed, enabled) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id` var id int64 - err := db.QueryRow(query, parentID, childID, execOrder, optional, alwaysExecuted, enabled).Scan(&id) + err := db.QueryRow(query, parentID, childID, execOrder, stepName, optional, alwaysExecuted, enabled).Scan(&id) if err != nil { return 0, err } @@ -27,7 +27,12 @@ func insertActionChild(db gorp.SqlExecutor, actionID int64, child sdk.Action, ex return fmt.Errorf("insertActionChild: child action has no id") } - id, err := insertEdge(db, actionID, child.ID, execOrder, child.Optional, child.AlwaysExecuted, child.Enabled) + //Useful to not save a step_name if it's the same than the default name (for ascode) + if strings.ToLower(child.Name) == strings.ToLower(child.StepName) { + child.StepName = "" + } + + id, err := insertEdge(db, actionID, child.ID, execOrder, child.StepName, child.Optional, child.AlwaysExecuted, child.Enabled) if err != nil { return err } @@ -54,7 +59,7 @@ func insertChildActionParameter(db gorp.SqlExecutor, edgeID, parentID, childID i name, type, value, - description, + description, advanced) VALUES ($1, $2, $3, $4, $5, $6)` if _, err := db.Exec(query, edgeID, param.Name, string(param.Type), param.Value, param.Description, param.Advanced); err != nil { @@ -68,7 +73,7 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro var children []sdk.Action var edgeIDs []int64 var childrenIDs []int64 - query := `SELECT id, child_id, exec_order, optional, always_executed, enabled FROM action_edge WHERE parent_id = $1 ORDER BY exec_order ASC` + query := `SELECT id, child_id, exec_order, step_name, optional, always_executed, enabled FROM action_edge WHERE parent_id = $1 ORDER BY exec_order ASC` rows, err := db.Query(query, actionID) if err != nil { @@ -78,18 +83,21 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro var edgeID, childID int64 var execOrder int + var stepName string var optional, alwaysExecuted, enabled bool + var mapStepName = make(map[int64]string) var mapOptional = make(map[int64]bool) var mapAlwaysExecuted = make(map[int64]bool) var mapEnabled = make(map[int64]bool) for rows.Next() { - err = rows.Scan(&edgeID, &childID, &execOrder, &optional, &alwaysExecuted, &enabled) + err = rows.Scan(&edgeID, &childID, &execOrder, &stepName, &optional, &alwaysExecuted, &enabled) if err != nil { return nil, err } edgeIDs = append(edgeIDs, edgeID) childrenIDs = append(childrenIDs, childID) + mapStepName[edgeID] = stepName mapOptional[edgeID] = optional mapAlwaysExecuted[edgeID] = alwaysExecuted mapEnabled[edgeID] = enabled @@ -114,6 +122,7 @@ func loadActionChildren(db gorp.SqlExecutor, actionID int64) ([]sdk.Action, erro // If child action has been modified, new parameters will show // and delete one won't be there anymore replaceChildActionParameters(&children[i], params) + children[i].StepName = mapStepName[edgeIDs[i]] // Get optional & always_executed flags children[i].Optional = mapOptional[edgeIDs[i]] children[i].AlwaysExecuted = mapAlwaysExecuted[edgeIDs[i]] diff --git a/engine/api/pipeline/pipeline_action.go b/engine/api/pipeline/pipeline_action.go index 807722831c..2eb5ebf51f 100644 --- a/engine/api/pipeline/pipeline_action.go +++ b/engine/api/pipeline/pipeline_action.go @@ -118,9 +118,7 @@ func UpdateJob(db gorp.SqlExecutor, job *sdk.Job, userID int64) error { return sdk.ErrForbidden } - query := `UPDATE pipeline_action set action_id=$1, pipeline_stage_id=$2, enabled=$4 WHERE id=$3` - _, err = db.Exec(query, job.Action.ID, job.PipelineStageID, job.PipelineActionID, job.Enabled) - if err != nil { + if err := UpdatePipelineAction(db, *job); err != nil { return err } job.Action.Enabled = job.Enabled @@ -134,10 +132,8 @@ func DeleteJob(db gorp.SqlExecutor, job sdk.Job, userID int64) error { // UpdatePipelineAction Update an action in a pipeline func UpdatePipelineAction(db gorp.SqlExecutor, job sdk.Job) error { - query := `UPDATE pipeline_action set action_id=$1, pipeline_stage_id=$2, enabled=$4 WHERE id=$3` - - _, err := db.Exec(query, job.Action.ID, job.PipelineStageID, job.PipelineActionID, job.Enabled) - if err != nil { + query := `UPDATE pipeline_action set action_id=$1, pipeline_stage_id=$2, enabled=$3 WHERE id=$4` + if _, err := db.Exec(query, job.Action.ID, job.PipelineStageID, job.Enabled, job.PipelineActionID); err != nil { return err } diff --git a/engine/api/pipeline/pipeline_stage.go b/engine/api/pipeline/pipeline_stage.go index fcdfeb3e82..a004027233 100644 --- a/engine/api/pipeline/pipeline_stage.go +++ b/engine/api/pipeline/pipeline_stage.go @@ -104,13 +104,13 @@ func LoadPipelineStage(ctx context.Context, db gorp.SqlExecutor, p *sdk.Pipeline } query := ` - SELECT pipeline_stage_R.id as stage_id, pipeline_stage_R.pipeline_id, pipeline_stage_R.name, pipeline_stage_R.last_modified, + SELECT pipeline_stage_R.id as stage_id, pipeline_stage_R.pipeline_id, pipeline_stage_R.name, pipeline_stage_R.last_modified, pipeline_stage_R.build_order, pipeline_stage_R.enabled, pipeline_stage_R.parameter, pipeline_stage_R.expected_value, pipeline_action_R.id as pipeline_action_id, pipeline_action_R.action_id, pipeline_action_R.action_last_modified, pipeline_action_R.action_args, pipeline_action_R.action_enabled FROM ( - SELECT pipeline_stage.id, pipeline_stage.pipeline_id, - pipeline_stage.name, pipeline_stage.last_modified ,pipeline_stage.build_order, + SELECT pipeline_stage.id, pipeline_stage.pipeline_id, + pipeline_stage.name, pipeline_stage.last_modified, pipeline_stage.build_order, pipeline_stage.enabled, pipeline_stage_prerequisite.parameter, pipeline_stage_prerequisite.expected_value FROM pipeline_stage @@ -118,7 +118,7 @@ func LoadPipelineStage(ctx context.Context, db gorp.SqlExecutor, p *sdk.Pipeline WHERE pipeline_id = $1 ) as pipeline_stage_R LEFT OUTER JOIN ( - SELECT pipeline_action.id, action.id as action_id, action.name as action_name, action.last_modified as action_last_modified, + SELECT pipeline_action.id, action.id as action_id, action.name as action_name, action.last_modified as action_last_modified, pipeline_action.args as action_args, pipeline_action.enabled as action_enabled, pipeline_action.pipeline_stage_id FROM action diff --git a/engine/api/workflow/process.go b/engine/api/workflow/process.go index d69bb96b75..738f60f13f 100644 --- a/engine/api/workflow/process.go +++ b/engine/api/workflow/process.go @@ -623,7 +623,7 @@ func processWorkflowNodeRun(ctx context.Context, db gorp.SqlExecutor, store cach // Tag VCS infos : add in tag only if it does not exist if !w.TagExists(tagGitRepository) { w.Tag(tagGitRepository, run.VCSRepository) - if run.VCSBranch != "" { + if run.VCSBranch != "" && run.VCSTag == "" { w.Tag(tagGitBranch, run.VCSBranch) } if run.VCSTag != "" { diff --git a/engine/api/workflow/resync_workflow.go b/engine/api/workflow/resync_workflow.go index 90b3e973ee..d8546c82cc 100644 --- a/engine/api/workflow/resync_workflow.go +++ b/engine/api/workflow/resync_workflow.go @@ -135,7 +135,7 @@ func ResyncNodeRunsWithCommits(ctx context.Context, db gorp.SqlExecutor, store c } tagsUpdated := false - if curVCSInfos.Branch != "" { + if curVCSInfos.Branch != "" && curVCSInfos.Tag == "" { tagsUpdated = wr.Tag(tagGitBranch, curVCSInfos.Branch) } if curVCSInfos.Hash != "" { diff --git a/engine/sql/123_action_custom_name.sql b/engine/sql/123_action_custom_name.sql new file mode 100644 index 0000000000..349c0f09a6 --- /dev/null +++ b/engine/sql/123_action_custom_name.sql @@ -0,0 +1,5 @@ +-- +migrate Up +ALTER TABLE action_edge ADD COLUMN step_name TEXT DEFAULT ''; + +-- +migrate Down +ALTER TABLE action_edge DROP COLUMN step_name; diff --git a/sdk/action.go b/sdk/action.go index 888dbca63a..aa260feac5 100644 --- a/sdk/action.go +++ b/sdk/action.go @@ -10,6 +10,7 @@ import ( type Action struct { ID int64 `json:"id" yaml:"-"` Name string `json:"name" cli:"name"` + StepName string `json:"step_name,omitempty" yaml:"step_name,omitempty" cli:"step_name"` Type string `json:"type" yaml:"-" cli:"type"` Description string `json:"description" yaml:"desc,omitempty"` Requirements []Requirement `json:"requirements"` diff --git a/sdk/exportentities/action.go b/sdk/exportentities/action.go index 5e4db62601..97695121a7 100644 --- a/sdk/exportentities/action.go +++ b/sdk/exportentities/action.go @@ -62,6 +62,9 @@ func newSteps(a sdk.Action) []Step { for i := range a.Actions { act := &a.Actions[i] s := Step{} + if act.StepName != "" { + s["name"] = act.StepName + } if !act.Enabled { s["enabled"] = act.Enabled } @@ -267,6 +270,10 @@ func (s Step) AsScript() (*sdk.Action, bool, error) { a := sdk.NewStepScript(bS) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -311,6 +318,10 @@ func (s Step) AsAction() (*sdk.Action, bool, error) { } a.Enabled, err = s.IsFlagged("enabled") + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } if err != nil { return nil, true, err } @@ -344,6 +355,10 @@ func (s Step) AsJUnitReport() (*sdk.Action, bool, error) { a := sdk.NewStepJUnitReport(bS) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -383,6 +398,10 @@ func (s Step) AsGitClone() (*sdk.Action, bool, error) { a := sdk.NewStepGitClone(argss) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -428,6 +447,10 @@ func (s Step) AsArtifactUpload() (*sdk.Action, bool, error) { } var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -462,6 +485,10 @@ func (s Step) AsArtifactDownload() (*sdk.Action, bool, error) { a := sdk.NewStepArtifactDownload(argss) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -495,6 +522,10 @@ func (s Step) AsCheckoutApplication() (*sdk.Action, bool, error) { a := sdk.NewCheckoutApplication(bS) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -528,6 +559,10 @@ func (s Step) AsCoverageAction() (*sdk.Action, bool, error) { a := sdk.NewCoverage(argss) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -561,6 +596,10 @@ func (s Step) AsDeployApplication() (*sdk.Action, bool, error) { a := sdk.NewDeployApplication(bS) var err error + a.StepName, err = s.Name() + if err != nil { + return nil, true, err + } a.Enabled, err = s.IsFlagged("enabled") if err != nil { return nil, true, err @@ -591,6 +630,18 @@ func (s Step) IsFlagged(flag string) (bool, error) { return bS, nil } +// Name returns true the step name if exist +func (s Step) Name() (string, error) { + if stepAttr, ok := s["name"]; ok { + if stepName, okName := stepAttr.(string); okName { + return stepName, nil + } else { + return "", fmt.Errorf("Malformatted Step : name must be a string") + } + } + return "", nil +} + // Action returns an sdk.Action func (act *Action) Action() (*sdk.Action, error) { a := new(sdk.Action) diff --git a/sdk/exportentities/pipeline.go b/sdk/exportentities/pipeline.go index bc04d8a4d9..872e2aeeb4 100644 --- a/sdk/exportentities/pipeline.go +++ b/sdk/exportentities/pipeline.go @@ -68,7 +68,7 @@ type Step map[string]interface{} func (s Step) IsValid() bool { keys := []string{} for k := range s { - if k != "enabled" && k != "optional" && k != "always_executed" { + if k != "enabled" && k != "optional" && k != "always_executed" && k != "name" { keys = append(keys, k) } } @@ -78,7 +78,7 @@ func (s Step) IsValid() bool { func (s Step) key() string { keys := []string{} for k := range s { - if k != "enabled" && k != "optional" && k != "always_executed" { + if k != "enabled" && k != "optional" && k != "always_executed" && k != "name" { keys = append(keys, k) } } diff --git a/sdk/workflow_run_easyjson.go b/sdk/workflow_run_easyjson.go index 495f545540..0bd96f8f93 100644 --- a/sdk/workflow_run_easyjson.go +++ b/sdk/workflow_run_easyjson.go @@ -1766,6 +1766,8 @@ func easyjsonD7860c2dDecodeGithubComOvhCdsSdk2(in *jlexer.Lexer, out *Parameter) out.Value = string(in.String()) case "description": out.Description = string(in.String()) + case "advanced": + out.Advanced = bool(in.Bool()) default: in.SkipRecursive() } @@ -1830,6 +1832,16 @@ func easyjsonD7860c2dEncodeGithubComOvhCdsSdk2(out *jwriter.Writer, in Parameter } out.String(string(in.Description)) } + if in.Advanced { + const prefix string = ",\"advanced\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.Bool(bool(in.Advanced)) + } out.RawByte('}') } func easyjsonD7860c2dDecodeGithubComOvhCdsSdk1(in *jlexer.Lexer, out *ExecutedJob) { @@ -2133,6 +2145,8 @@ func easyjsonD7860c2dDecodeGithubComOvhCdsSdk12(in *jlexer.Lexer, out *Action) { out.ID = int64(in.Int64()) case "name": out.Name = string(in.String()) + case "step_name": + out.StepName = string(in.String()) case "type": out.Type = string(in.String()) case "description": @@ -2252,6 +2266,16 @@ func easyjsonD7860c2dEncodeGithubComOvhCdsSdk12(out *jwriter.Writer, in Action) } out.String(string(in.Name)) } + if in.StepName != "" { + const prefix string = ",\"step_name\":" + if first { + first = false + out.RawString(prefix[1:]) + } else { + out.RawString(prefix) + } + out.String(string(in.StepName)) + } { const prefix string = ",\"type\":" if first { diff --git a/tests/fixtures/action_disabled.yml b/tests/fixtures/action_disabled.yml index 6858c47876..a76dadcfb6 100644 --- a/tests/fixtures/action_disabled.yml +++ b/tests/fixtures/action_disabled.yml @@ -4,7 +4,8 @@ enabled: false requirements: - binary: bash steps: -- script: +- name: my empty script + script: - '#!/bin/bash' - set -e - "" diff --git a/tests/fixtures/action_git_clone.yml b/tests/fixtures/action_git_clone.yml index e275a8ca04..f501838478 100644 --- a/tests/fixtures/action_git_clone.yml +++ b/tests/fixtures/action_git_clone.yml @@ -6,7 +6,8 @@ parameters: requirements: - binary: git steps: -- gitClone: +- name: 'gitClone' + gitClone: branch: '{{.git.branch}}' commit: '{{.git.hash}}' depth: "10" diff --git a/ui/src/app/model/action.model.ts b/ui/src/app/model/action.model.ts index e992b38425..e7c4acb6f1 100644 --- a/ui/src/app/model/action.model.ts +++ b/ui/src/app/model/action.model.ts @@ -4,6 +4,7 @@ import {Requirement} from './requirement.model'; export class Action { id: number; name: string; + step_name: string; type: string; description = ''; requirements: Array; diff --git a/ui/src/app/shared/action/step/step.component.ts b/ui/src/app/shared/action/step/step.component.ts index 66afbba8ad..b503871439 100644 --- a/ui/src/app/shared/action/step/step.component.ts +++ b/ui/src/app/shared/action/step/step.component.ts @@ -18,6 +18,7 @@ export class ActionStepComponent { this._step = step; if (step && step.parameters) { this.withAdvanced = step.parameters.some((parameter) => parameter.advanced); + this._step.step_name = this._step.step_name || this._step.name; } } get step(): Action { diff --git a/ui/src/app/shared/action/step/step.html b/ui/src/app/shared/action/step/step.html index 3647f6f5e5..21d009a95b 100644 --- a/ui/src/app/shared/action/step/step.html +++ b/ui/src/app/shared/action/step/step.html @@ -1,13 +1,19 @@
-
- - - - {{step.name}} - - + + + + + +
+ +
+
+ + + {{step.step_name}} + ({{step.name}}) {{'common_deprecated' | translate}} @@ -24,20 +30,24 @@
- +
- - -
- +
- - -
diff --git a/ui/src/app/shared/action/step/step.scss b/ui/src/app/shared/action/step/step.scss index 2719943d36..506f6ae540 100644 --- a/ui/src/app/shared/action/step/step.scss +++ b/ui/src/app/shared/action/step/step.scss @@ -15,3 +15,12 @@ .textOrange { color: $cds_color_orange; } + +.stepname { + font-size: 0.85em; + color: grey; +} + +.inputStepname { + padding-right: 2px !important; +} diff --git a/ui/src/app/views/workflow/run/node/pipeline/step/step.log.html b/ui/src/app/views/workflow/run/node/pipeline/step/step.log.html index 196f55badd..ab67715e88 100644 --- a/ui/src/app/views/workflow/run/node/pipeline/step/step.log.html +++ b/ui/src/app/views/workflow/run/node/pipeline/step/step.log.html @@ -4,7 +4,7 @@
- {{step.name}} {{duration}} + {{step.name}}{{step.step_name}} {{duration}}
{{ 'action_optional' | translate }}