diff --git a/action/pipeline/exec.go b/action/pipeline/exec.go index 6958348f..753f08d3 100644 --- a/action/pipeline/exec.go +++ b/action/pipeline/exec.go @@ -17,6 +17,7 @@ import ( "github.com/go-vela/cli/version" api "github.com/go-vela/server/api/types" "github.com/go-vela/server/compiler" + "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/constants" "github.com/go-vela/worker/executor" "github.com/go-vela/worker/runtime" @@ -118,52 +119,16 @@ func (c *Config) Exec(client compiler.Engine) error { // create a slice for steps to be removed stepsToRemove := c.SkipSteps - // filter out steps to be removed - if len(_pipeline.Stages) > 0 { - // counter for total steps to run - totalSteps := 0 - - for i, stage := range _pipeline.Stages { - filteredStageSteps := stage.Steps[:0] - - for _, step := range stage.Steps { - // if c.steps contains step.Name - if !slices.Contains(stepsToRemove, step.Name) { - filteredStageSteps = append(filteredStageSteps, step) - totalSteps++ - } - - _pipeline.Stages[i].Steps = filteredStageSteps - } - } - - // check if any steps are left to run, excluding "init" step - if totalSteps <= 1 { - return fmt.Errorf("no steps left to run after removing skipped steps") + // print steps to be removed to the user + if len(stepsToRemove) > 0 { + for _, stepName := range stepsToRemove { + fmt.Println("skip step: ", stepName) } - } else { - // if not using stages - filteredSteps := _pipeline.Steps[:0] - - for _, step := range _pipeline.Steps { - if !slices.Contains(stepsToRemove, step.Name) { - filteredSteps = append(filteredSteps, step) - } - } - - // print steps to be removed to the user - if len(stepsToRemove) > 0 { - for _, stepName := range stepsToRemove { - fmt.Println("skip step: ", stepName) - } - } - - _pipeline.Steps = filteredSteps + } - // check if any steps are left to run, excluding "init" step - if len(_pipeline.Steps) <= 1 { - return fmt.Errorf("no steps left to run after removing skipped steps") - } + // call the skipSteps function + if err := skipSteps(_pipeline, stepsToRemove); err != nil { + return err } // create current directory path for local mount @@ -266,3 +231,48 @@ func (c *Config) Exec(client compiler.Engine) error { return nil } + +// skipSteps filters out steps to be removed from the pipeline. +func skipSteps(_pipeline *pipeline.Build, stepsToRemove []string) error { + // filter out steps to be removed + if len(_pipeline.Stages) > 0 { + // counter for total steps to run + totalSteps := 0 + + for i, stage := range _pipeline.Stages { + filteredStageSteps := stage.Steps[:0] + + for _, step := range stage.Steps { + if !slices.Contains(stepsToRemove, step.Name) { + filteredStageSteps = append(filteredStageSteps, step) + totalSteps++ + } + } + + _pipeline.Stages[i].Steps = filteredStageSteps + } + + // check if any steps are left to run, excluding "init" step + if totalSteps <= 1 { + return fmt.Errorf("no steps left to run after removing skipped steps") + } + } else { + // if not using stages + filteredSteps := _pipeline.Steps[:0] + + for _, step := range _pipeline.Steps { + if !slices.Contains(stepsToRemove, step.Name) { + filteredSteps = append(filteredSteps, step) + } + } + + _pipeline.Steps = filteredSteps + + // check if any steps are left to run, excluding "init" step + if len(_pipeline.Steps) <= 1 { + return fmt.Errorf("no steps left to run after removing skipped steps") + } + } + + return nil +}