Skip to content

Commit

Permalink
Fixes #26: Loop control in workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic authored and jaredoconnell committed Apr 18, 2023
1 parent 6403cfd commit 49cd890
Show file tree
Hide file tree
Showing 13 changed files with 693 additions and 16 deletions.
5 changes: 4 additions & 1 deletion internal/step/dummy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func (p *dummyProvider) Kind() string {
type dummyProvider struct {
}

func (p *dummyProvider) Register(_ step.Registry) {
}

func (p *dummyProvider) ProviderSchema() map[string]*schema.PropertySchema {
// We don't need any steps to set up the provider.
return map[string]*schema.PropertySchema{}
Expand Down Expand Up @@ -64,7 +67,7 @@ func (p *dummyProvider) Lifecycle() step.Lifecycle[step.LifecycleStage] {
}
}

func (p *dummyProvider) LoadSchema(_ map[string]any) (step.RunnableStep, error) {
func (p *dummyProvider) LoadSchema(_ map[string]any, _ map[string][]byte) (step.RunnableStep, error) {
return &runnableStep{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/step/dummy/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *stageChangeHandler) OnStepComplete(
func TestProvider(t *testing.T) {
provider := dummy.New()
assert.Equals(t, provider.Kind(), "dummy")
runnable, err := provider.LoadSchema(map[string]any{})
runnable, err := provider.LoadSchema(map[string]any{}, map[string][]byte{})
assert.NoError(t, err)

handler := &stageChangeHandler{
Expand Down
26 changes: 26 additions & 0 deletions internal/step/foreach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Foreach step provider

This provider allows you to loop over a list of inputs and execute (potentially parallel) workflows for each item. The subworkflows must only have one possible output named "success" and this output will be collected into a list as a result.

## Usage

```yaml
steps:
your_step:
kind: foreach
workflow: some_workflow_file.yaml # This must be in the workflow directory
items: !expr $.input.some_list_of_items
parallelism: 5 # How many workflows to run in parallel
output:
result: !expr $.steps.your_step.outputs.success.data # This will be a list of result objects
```
### Handling errors
In case one or more subworkflows exit with an error, you can also recover.
```yaml
output:
result: !expr $.steps.your_step.failed.error.data # This will be a map of int keys to provide the subworkflows with a successful execution.
errors: !expr $.steps.your_step.failed.error.messages # This will be a map of int to error messages for the subworkflows that failed.
```
2 changes: 2 additions & 0 deletions internal/step/foreach/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package foreach provides the ability to loop over items.
package foreach
Loading

0 comments on commit 49cd890

Please sign in to comment.