Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
support build meta data (#134)
Browse files Browse the repository at this point in the history
* Add support to pass build meta_data in trigger steps

* fix bats tests

* add test for pipeline input

* fix bats tests

---------

Co-authored-by: Iaroslav Ciupin <iaroslav@union.ai>
  • Loading branch information
adikari and iaroslav-ciupin authored Aug 17, 2023
1 parent dc63d7b commit 83fe839
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
4 changes: 0 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func main() {

setupLogger(plugin.LogLevel)

if env("BUILDKITE_PLUGIN_MONOREPO_DIFF_BUILDKITE_PLUGIN_TEST_MODE", "false") == "true" {
return
}

if _, _, err = uploadPipeline(plugin, generatePipeline); err != nil {
log.Fatalf("+++ failed to upload pipeline: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestGeneratePipeline(t *testing.T) {
steps := []Step{
{
Trigger: "foo-service-pipeline",
Build: Build{Message: "build message"},
Build: Build{Message: "build message", MetaData: map[string]string{"build_number": "123"}},
SoftFail: true,
Notify: []StepNotify{
{Slack: "@adikari"},
Expand Down Expand Up @@ -295,6 +295,8 @@ steps:
- trigger: foo-service-pipeline
build:
message: build message
meta_data:
build_number: "123"
soft_fail: true
notify:
- slack: '@adikari'
Expand Down
11 changes: 6 additions & 5 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ type Agent map[string]string

// Build is buildkite build definition
type Build struct {
Message string `yaml:"message,omitempty"`
Branch string `yaml:"branch,omitempty"`
Commit string `yaml:"commit,omitempty"`
RawEnv interface{} `json:"env" yaml:",omitempty"`
Env map[string]string `yaml:"env,omitempty"`
Message string `yaml:"message,omitempty"`
Branch string `yaml:"branch,omitempty"`
Commit string `yaml:"commit,omitempty"`
RawEnv interface{} `json:"env" yaml:",omitempty"`
Env map[string]string `yaml:"env,omitempty"`
MetaData map[string]string `json:"meta_data,omitempty" yaml:"meta_data,omitempty"`
// Notify []Notify `yaml:"notify,omitempty"`
}

Expand Down
8 changes: 7 additions & 1 deletion plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ func TestPluginShouldUnmarshallCorrectly(t *testing.T) {
"config": {
"trigger": "service-2",
"build": {
"message": "some message"
"message": "some message",
"meta_data": {
"foo": "bar"
}
}
}
},
Expand Down Expand Up @@ -182,6 +185,9 @@ func TestPluginShouldUnmarshallCorrectly(t *testing.T) {
"env2": "env-2",
"env3": "env-3",
},
MetaData: map[string]string{
"foo": "bar",
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . .

RUN goreleaser build --rm-dist --skip-validate --config .goreleaser-test.yml

FROM buildkite/plugin-tester
FROM buildkite/plugin-tester:v3.0.1

COPY tests /plugin/tests
COPY hooks /plugin/hooks
Expand Down
12 changes: 9 additions & 3 deletions tests/command.bats
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env bats

load '/usr/local/lib/bats/load.bash'

setup() {
load "$BATS_PLUGIN_PATH/load.bash"
export BUILDKITE_PLUGIN_MONOREPO_DIFF_BUILDKITE_PLUGIN_TEST_MODE="true"

stub buildkite-agent pipeline upload
Expand Down Expand Up @@ -182,7 +181,11 @@ EOM
"build": {
"message": "some-message",
"commit": "commit-hash",
"branch": "go-rewrite"
"branch": "go-rewrite",
"meta_data": {
"build_number": "123",
"build_message": "message"
}
},
"async": true,
"agents": {
Expand Down Expand Up @@ -267,6 +270,9 @@ steps:
message: some-message
branch: go-rewrite
commit: commit-hash
meta_data:
build_message: message
build_number: "123"
agents:
queue: foo-service-queue
artifacts:
Expand Down

0 comments on commit 83fe839

Please sign in to comment.