Skip to content

Commit

Permalink
hotfix: support Retry Policies in TestWorkflows (#5199)
Browse files Browse the repository at this point in the history
* fix: use `retry` policy for TestWorkflow stages
* fix: process Retry Policy in TestWorkflows init process
  • Loading branch information
rangoo94 authored Mar 15, 2024
1 parent 57c9791 commit 8319648
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cmd/tcl/testworkflow-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ func main() {
}

// Load the rest of the configuration
var err error
for k, v := range config {
value, err := data.Template(v)
config[k], err = data.Template(v)
if err != nil {
output.Failf(output.CodeInputError, `resolving "%s" param: %s: %s`, k, v, err.Error())
}
data.LoadConfig(map[string]string{k: value})
}
data.LoadConfig(config)

// Compute templates in the cmd/args
original := slices.Clone(args)
var err error
for i := range args {
args[i], err = data.Template(args[i])
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func ProcessShellCommand(_ InternalProcessor, layer Intermediate, container Cont
shell := container.CreateChild().SetCommand(defaultShell).SetArgs("-c", step.Shell)
stage := NewContainerStage(layer.NextRef(), shell)
stage.SetCategory("Run shell command")
stage.SetRetryPolicy(step.Retry)
return stage, nil
}

Expand All @@ -55,6 +56,7 @@ func ProcessRunCommand(_ InternalProcessor, layer Intermediate, container Contai
}
container = container.CreateChild().ApplyCR(&step.Run.ContainerConfig)
stage := NewContainerStage(layer.NextRef(), container)
stage.SetRetryPolicy(step.Retry)
stage.SetCategory("Run")
return stage, nil
}
Expand Down Expand Up @@ -89,6 +91,7 @@ func ProcessExecute(_ InternalProcessor, layer Intermediate, container Container
}
container = container.CreateChild()
stage := NewContainerStage(layer.NextRef(), container)
stage.SetRetryPolicy(step.Retry)
hasWorkflows := len(step.Execute.Workflows) > 0
hasTests := len(step.Execute.Tests) > 0

Expand Down Expand Up @@ -212,6 +215,7 @@ func ProcessContentGit(_ InternalProcessor, layer Intermediate, container Contai

selfContainer := container.CreateChild()
stage := NewContainerStage(layer.NextRef(), selfContainer)
stage.SetRetryPolicy(step.Retry)
stage.SetCategory("Clone Git repository")

// Compute mount path
Expand Down Expand Up @@ -283,6 +287,7 @@ func ProcessArtifacts(_ InternalProcessor, layer Intermediate, container Contain
selfContainer := container.CreateChild().
ApplyCR(&testworkflowsv1.ContainerConfig{WorkingDir: step.Artifacts.WorkingDir})
stage := NewContainerStage(layer.NextRef(), selfContainer)
stage.SetRetryPolicy(step.Retry)
stage.SetCondition("always")
stage.SetCategory("Upload artifacts")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type StageLifecycle interface {
SetOptional(optional bool) StageLifecycle
SetCondition(expr string) StageLifecycle
AppendConditions(expr ...string) StageLifecycle
SetRetryPolicy(policy testworkflowsv1.RetryPolicy) StageLifecycle
SetRetryPolicy(policy *testworkflowsv1.RetryPolicy) StageLifecycle
SetTimeout(tpl string) StageLifecycle
}

Expand Down Expand Up @@ -100,8 +100,11 @@ func (s *stageLifecycle) AppendConditions(expr ...string) StageLifecycle {
return s
}

func (s *stageLifecycle) SetRetryPolicy(policy testworkflowsv1.RetryPolicy) StageLifecycle {
s.retry = policy
func (s *stageLifecycle) SetRetryPolicy(policy *testworkflowsv1.RetryPolicy) StageLifecycle {
if policy == nil {
policy = &testworkflowsv1.RetryPolicy{}
}
s.retry = *policy
return s
}

Expand Down

0 comments on commit 8319648

Please sign in to comment.