Skip to content

Commit

Permalink
move new code to new func skipSteps
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick committed Jan 7, 2025
1 parent bb78239 commit 8b19480
Showing 1 changed file with 54 additions and 44 deletions.
98 changes: 54 additions & 44 deletions action/pipeline/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 8b19480

Please sign in to comment.