Skip to content

Commit e8c1fb0

Browse files
authored
Merge pull request #123 from altana-ai/jwb/add-depends-on-support
feat: add support for depends_on in step definitions
2 parents ae3c884 + 1ddd258 commit e8c1fb0

3 files changed

Lines changed: 129 additions & 0 deletions

File tree

pipeline_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,48 @@ func TestGeneratePipelineWithCondition(t *testing.T) {
592592

593593
assert.Equal(t, want, string(got))
594594
}
595+
596+
func TestGeneratePipelineWithDependsOn(t *testing.T) {
597+
steps := []Step{
598+
{
599+
Command: "echo build",
600+
Label: "Build",
601+
},
602+
{
603+
Command: "echo test",
604+
Label: "Test",
605+
DependsOn: "build-step",
606+
},
607+
{
608+
Trigger: "deploy-pipeline",
609+
DependsOn: []interface{}{"build-step", "test-step"},
610+
},
611+
}
612+
613+
want := `steps:
614+
- label: Build
615+
command: echo build
616+
- label: Test
617+
command: echo test
618+
depends_on: build-step
619+
- trigger: deploy-pipeline
620+
depends_on:
621+
- build-step
622+
- test-step
623+
`
624+
625+
plugin := Plugin{Wait: false}
626+
627+
pipeline, _, err := generatePipeline(steps, plugin)
628+
require.NoError(t, err)
629+
defer func() {
630+
if err = os.Remove(pipeline.Name()); err != nil {
631+
t.Logf("Failed to remove temporary pipeline file: %v", err)
632+
}
633+
}()
634+
635+
got, err := os.ReadFile(pipeline.Name())
636+
require.NoError(t, err)
637+
638+
assert.Equal(t, want, string(got))
639+
}

plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Step struct {
9393
SoftFail interface{} `json:"soft_fail" yaml:"soft_fail,omitempty"`
9494
RawNotify []map[string]interface{} `json:"notify" yaml:",omitempty"`
9595
Notify []StepNotify `yaml:"notify,omitempty"`
96+
DependsOn interface{} `json:"depends_on" yaml:"depends_on,omitempty"`
9697
Steps []Step `yaml:"steps,omitempty"`
9798
}
9899

plugin_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,86 @@ func TestPluginShouldClearRawEnvFromNestedSteps(t *testing.T) {
943943
assert.Nil(t, secondStep.RawEnv, "Second nested step RawEnv should be nil")
944944
assert.Nil(t, secondStep.Build.RawEnv, "Second nested step Build.RawEnv should be nil")
945945
}
946+
947+
func TestPluginShouldPreserveDependsOnString(t *testing.T) {
948+
param := `[{
949+
"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#commit": {
950+
"watch": [
951+
{
952+
"path": "service/**/*",
953+
"config": {
954+
"command": "echo deploy",
955+
"depends_on": "build-step"
956+
}
957+
}
958+
]
959+
}
960+
}]`
961+
962+
got, err := initializePlugin(param)
963+
assert.NoError(t, err)
964+
965+
expected := Plugin{
966+
Diff: "git diff --name-only HEAD~1",
967+
Wait: false,
968+
LogLevel: "info",
969+
Interpolation: true,
970+
Watch: []WatchConfig{
971+
{
972+
Paths: []string{"service/**/*"},
973+
Step: Step{
974+
Command: "echo deploy",
975+
DependsOn: "build-step",
976+
},
977+
},
978+
},
979+
}
980+
981+
if diff := cmp.Diff(expected, got); diff != "" {
982+
t.Fatalf("plugin diff (-want +got):\n%s", diff)
983+
}
984+
}
985+
986+
func TestPluginShouldPreserveDependsOnArray(t *testing.T) {
987+
param := `[{
988+
"github.com/buildkite-plugins/monorepo-diff-buildkite-plugin#commit": {
989+
"watch": [
990+
{
991+
"path": "service/**/*",
992+
"config": {
993+
"trigger": "deploy-pipeline",
994+
"depends_on": ["build-step", "test-step"]
995+
}
996+
}
997+
]
998+
}
999+
}]`
1000+
1001+
got, err := initializePlugin(param)
1002+
assert.NoError(t, err)
1003+
1004+
expected := Plugin{
1005+
Diff: "git diff --name-only HEAD~1",
1006+
Wait: false,
1007+
LogLevel: "info",
1008+
Interpolation: true,
1009+
Watch: []WatchConfig{
1010+
{
1011+
Paths: []string{"service/**/*"},
1012+
Step: Step{
1013+
Trigger: "deploy-pipeline",
1014+
Build: Build{
1015+
Message: "fix: temp file not correctly deleted",
1016+
Branch: "go-rewrite",
1017+
Commit: "123",
1018+
},
1019+
DependsOn: []interface{}{"build-step", "test-step"},
1020+
},
1021+
},
1022+
},
1023+
}
1024+
1025+
if diff := cmp.Diff(expected, got); diff != "" {
1026+
t.Fatalf("plugin diff (-want +got):\n%s", diff)
1027+
}
1028+
}

0 commit comments

Comments
 (0)