Skip to content

Commit 9701c2d

Browse files
committed
set failure status in each return
Signed-off-by: Prune <prune@lecentre.net>
1 parent a83788f commit 9701c2d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

internal/promotion/runner/builtin/yaml_merger.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,17 @@ func (y *yamlMerger) run(
6666
cfg builtin.YAMLMergeConfig,
6767
) (promotion.StepResult, error) {
6868

69-
result := promotion.StepResult{Status: kargoapi.PromotionStepStatusSucceeded}
70-
failure := promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}
71-
7269
// sanity check
7370
if len(cfg.InFiles) == 0 || cfg.OutFile == "" {
74-
return failure, fmt.Errorf("inFiles and OutFile must not be empty")
71+
return promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}, fmt.Errorf("inFiles and OutFile must not be empty")
7572
}
7673

7774
// Secure join the input paths to prevent path traversal attacks.
7875
filePaths := []string{}
7976
for _, path := range cfg.InFiles {
8077
inFile, err := securejoin.SecureJoin(stepCtx.WorkDir, path)
8178
if err != nil {
82-
return failure, fmt.Errorf("could not secure join input file %q: %w", path, err)
79+
return promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}, fmt.Errorf("could not secure join input file %q: %w", path, err)
8380
}
8481

8582
// only add existing files
@@ -88,7 +85,7 @@ func (y *yamlMerger) run(
8885
if cfg.IgnoreMissingFiles {
8986
continue
9087
}
91-
return failure, fmt.Errorf("input file not found: %s", inFile)
88+
return promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}, fmt.Errorf("input file not found: %s", inFile)
9289

9390
}
9491
filePaths = append(filePaths, inFile)
@@ -98,21 +95,22 @@ func (y *yamlMerger) run(
9895
// Secure join the output path to prevent path traversal attacks.
9996
outFile, err := securejoin.SecureJoin(stepCtx.WorkDir, cfg.OutFile)
10097
if err != nil {
101-
return failure, fmt.Errorf("could not secure join outFile %q: %w", cfg.OutFile, err)
98+
return promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}, fmt.Errorf("could not secure join outFile %q: %w", cfg.OutFile, err)
10299
}
103100

104101
// ensure output path fully exist
105102
if err = os.MkdirAll(filepath.Dir(outFile), 0o700); err != nil {
106-
return failure, fmt.Errorf("error creating directory structure %s: %w", filepath.Dir(outFile), err)
103+
return promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}, fmt.Errorf("error creating directory structure %s: %w", filepath.Dir(outFile), err)
107104
}
108105

109106
// Merge files
110107
err = yaml.MergeYAMLFiles(filePaths, outFile)
111108
if err != nil {
112-
return failure, fmt.Errorf("could not merge YAML files: %w", err)
109+
return promotion.StepResult{Status: kargoapi.PromotionStepStatusErrored}, fmt.Errorf("could not merge YAML files: %w", err)
113110
}
114111

115112
// Add a commit message fragment to the step's output.
113+
result := promotion.StepResult{Status: kargoapi.PromotionStepStatusSucceeded}
116114
if commitMsg := y.generateCommitMessage(cfg.OutFile, filePaths); commitMsg != "" {
117115
result.Output = map[string]any{
118116
"commitMessage": commitMsg,

0 commit comments

Comments
 (0)