Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(local exec): add ability to skip steps #584

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

KellyMerrick
Copy link
Contributor

@KellyMerrick KellyMerrick commented Nov 7, 2024

Added flags for skipping steps:

// Step Flags
&cli.StringSliceFlag{
EnvVars: []string{"VELA_SKIP_STEP", "SKIP_STEP"},
Name: "skip-step",
Aliases: []string{"sk", "skip"},
Usage: "skip a step in the pipeline",
},

Works for steps, stages, anchors, yaml templates, nested yaml templates.

  • Stages: any steps with the provided name will be skipped, across all stages.
  • Templates and nested templates: prepend the template name(s) to the step name
  • Step names with spaces: wrap in quotes, including template name(s).
$ vela exec pipeline --sk echo_hi --sk child_echo_hi --sk 'child_some grandchild_echo_hi'

cli/action/pipeline/exec.go

Lines 118 to 171 in a51e7aa

// create a slice for steps to be removed
stepsToRemove := c.Steps
// print steps to be removed to the user
if len(stepsToRemove) > 0 {
for _, stepName := range stepsToRemove {
fmt.Println("skip step: ", stepName)
}
}
// filter out steps to be removed
if len(_pipeline.Stages) > 0 {
// if using stages
// 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")
}
} 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")
}
}

Also corrected punctuation for proper display in command help output:

Aliases: []string{"tf", "tfs", "template-files"},

@KellyMerrick KellyMerrick self-assigned this Nov 7, 2024
@KellyMerrick KellyMerrick requested a review from a team as a code owner November 7, 2024 21:21
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.

Project coverage is 78.97%. Comparing base (55c73d4) to head (7d8f639).

Files with missing lines Patch % Lines
action/pipeline/exec.go 0.00% 39 Missing ⚠️
command/pipeline/exec.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #584      +/-   ##
==========================================
- Coverage   79.38%   78.97%   -0.41%     
==========================================
  Files         172      172              
  Lines        7728     7768      +40     
==========================================
  Hits         6135     6135              
- Misses       1357     1397      +40     
  Partials      236      236              
Files with missing lines Coverage Δ
command/pipeline/exec.go 0.00% <0.00%> (ø)
action/pipeline/exec.go 0.00% <0.00%> (ø)

@@ -16,6 +16,7 @@ type Config struct {
Target string
Org string
Repo string
Steps []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Steps []string
SkipSteps []string

Thoughts on making this field more descriptive?

Comment on lines +121 to +126
// print steps to be removed to the user
if len(stepsToRemove) > 0 {
for _, stepName := range stepsToRemove {
fmt.Println("skip step: ", stepName)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on moving this inside the loops below as we prune the pipeline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants