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

Merged
merged 9 commits into from
Jan 8, 2025

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 44 lines in your changes missing coverage. Please review.

Project coverage is 78.93%. Comparing base (55c73d4) to head (53f93fa).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
action/pipeline/exec.go 0.00% 43 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.93%   -0.45%     
==========================================
  Files         172      172              
  Lines        7728     7772      +44     
==========================================
  Hits         6135     6135              
- Misses       1357     1401      +44     
  Partials      236      236              
Files with missing lines Coverage Δ
command/pipeline/exec.go 0.00% <0.00%> (ø)
action/pipeline/exec.go 0.00% <0.00%> (ø)

action/pipeline/pipeline.go Outdated Show resolved Hide resolved
action/pipeline/exec.go Outdated Show resolved Hide resolved
@KellyMerrick KellyMerrick requested a review from ecrupper January 7, 2025 21:17
action/pipeline/exec.go Outdated Show resolved Hide resolved
@KellyMerrick KellyMerrick merged commit 441e1bf into main Jan 8, 2025
15 of 17 checks passed
@KellyMerrick KellyMerrick deleted the feat/local_exec_skip_steps branch January 8, 2025 15:19
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.

3 participants