Skip to content

Commit 8dd1f90

Browse files
authored
Merge pull request #133 from toadzky/add-key-field-to-steps
feat: add support for `key` in watch config steps
2 parents dac2b9d + 2e3d44d commit 8dd1f90

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ Default: `true`
297297

298298
By setting `wait` to `true`, the build will wait until the triggered pipeline builds are successful before proceeding
299299

300+
### `key` (optional)
301+
302+
Add `key` to set the step or group key.
303+
304+
```yaml
305+
steps:
306+
- label: "Setting Key"
307+
plugins:
308+
- monorepo-diff#v1.5.2:
309+
diff: "git diff --name-only HEAD~1"
310+
watch:
311+
- path: "bar-service/"
312+
config:
313+
key: echo-step
314+
command: "echo deploy-bar"
315+
```
316+
300317
## Example
301318

302319
```yaml
@@ -317,6 +334,7 @@ steps:
317334
config:
318335
command: "buildkite-agent pipeline upload ops/.buildkite/pipeline.yml"
319336
label: "Upload pipeline"
337+
key: pipeline-upload
320338
# following configs are available in command. notify is not available in trigger step
321339
notify:
322340
- basecamp_campfire: https://basecamp-url

pipeline_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,52 @@ func TestGeneratePipelineWithDependsOn(t *testing.T) {
665665

666666
assert.Equal(t, want, string(got))
667667
}
668+
669+
func TestGeneratePipelineWithStepKey(t *testing.T) {
670+
steps := []Step{
671+
{
672+
Command: "echo build",
673+
Label: "Build",
674+
Key: "build-step",
675+
},
676+
{
677+
Command: "echo test",
678+
Label: "Test",
679+
Key: "test-step",
680+
DependsOn: "build-step",
681+
},
682+
{
683+
Trigger: "deploy-pipeline",
684+
DependsOn: []interface{}{"build-step", "test-step"},
685+
},
686+
}
687+
688+
want := `steps:
689+
- label: Build
690+
command: echo build
691+
key: build-step
692+
- label: Test
693+
command: echo test
694+
depends_on: build-step
695+
key: test-step
696+
- trigger: deploy-pipeline
697+
depends_on:
698+
- build-step
699+
- test-step
700+
`
701+
702+
plugin := Plugin{Wait: false}
703+
704+
pipeline, _, err := generatePipeline(steps, plugin)
705+
require.NoError(t, err)
706+
defer func() {
707+
if err = os.Remove(pipeline.Name()); err != nil {
708+
t.Logf("Failed to remove temporary pipeline file: %v", err)
709+
}
710+
}()
711+
712+
got, err := os.ReadFile(pipeline.Name())
713+
require.NoError(t, err)
714+
715+
assert.Equal(t, want, string(got))
716+
}

plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type Step struct {
9494
RawNotify []map[string]interface{} `json:"notify" yaml:",omitempty"`
9595
Notify []StepNotify `yaml:"notify,omitempty"`
9696
DependsOn interface{} `json:"depends_on" yaml:"depends_on,omitempty"`
97+
Key string `yaml:"key,omitempty"`
9798
Steps []Step `yaml:"steps,omitempty"`
9899
}
99100

plugin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ configuration:
4242
config:
4343
type: object
4444
properties:
45+
key:
46+
type: string
4547
command:
4648
type: string
4749
trigger:

0 commit comments

Comments
 (0)