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

Commit 3648f1b

Browse files
authored
fix diff script parsing issue (#127)
* fix failing tests * test script * diff command supports eval * enable logging in tests * upgrade version in readme
1 parent 159143d commit 3648f1b

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

.buildkite/pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ steps:
3434

3535
- label: ":bomb: Testing groups"
3636
plugins:
37-
- monebag/monorepo-diff#v2.5.6:
37+
- monebag/monorepo-diff#v2.5.7:
3838
diff: "cat ./e2e/multiple-paths"
3939
watch:
4040
- path:
@@ -46,7 +46,7 @@ steps:
4646

4747
- label: ":bomb: Testing hooks"
4848
plugins:
49-
- monebag/monorepo-diff#v2.5.6:
49+
- monebag/monorepo-diff#v2.5.7:
5050
diff: "cat ./e2e/multiple-paths"
5151
watch:
5252
- path: "user-service/"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If the version number is not provided then the most recent version of the plugin
1818
steps:
1919
- label: "Triggering pipelines"
2020
plugins:
21-
- monebag/monorepo-diff#v2.5.6:
21+
- monebag/monorepo-diff#v2.5.7:
2222
diff: "git diff --name-only HEAD~1"
2323
watch:
2424
- path: "bar-service/"
@@ -35,7 +35,7 @@ steps:
3535
steps:
3636
- label: "Triggering pipelines"
3737
plugins:
38-
- monebag/monorepo-diff#v2.5.6:
38+
- monebag/monorepo-diff#v2.5.7:
3939
diff: "git diff --name-only $(head -n 1 last_successful_build)"
4040
interpolation: false
4141
env:
@@ -151,7 +151,7 @@ Add `log_level` property to set the log level. Supported log levels are `debug`
151151
steps:
152152
- label: "Triggering pipelines"
153153
plugins:
154-
- monebag/monorepo-diff#v2.5.6:
154+
- monebag/monorepo-diff#v2.5.7:
155155
diff: "git diff --name-only HEAD~1"
156156
log_level: "debug" # defaults to "info"
157157
watch:
@@ -227,7 +227,7 @@ hooks:
227227
steps:
228228
- label: "Triggering pipelines"
229229
plugins:
230-
- monebag/monorepo-diff#v2.5.6:
230+
- monebag/monorepo-diff#v2.5.7:
231231
diff: "git diff --name-only HEAD~1"
232232
watch:
233233
- path: app/cms/

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func main() {
3737

3838
setupLogger(plugin.LogLevel)
3939

40+
if env("BUILDKITE_PLUGIN_MONOREPO_DIFF_BUILDKITE_PLUGIN_TEST_MODE", "false") == "true" {
41+
return
42+
}
43+
4044
if _, _, err = uploadPipeline(plugin, generatePipeline); err != nil {
4145
log.Fatalf("+++ failed to upload pipeline: %v", err)
4246
}

main_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
54
"os"
65
"testing"
76

@@ -12,9 +11,6 @@ import (
1211
func TestMain(m *testing.M) {
1312
log.SetLevel(log.DebugLevel)
1413

15-
// disable logs in test
16-
log.SetOutput(ioutil.Discard)
17-
1814
// set some env variables for using in tests
1915
os.Setenv("BUILDKITE_COMMIT", "123")
2016
os.Setenv("BUILDKITE_MESSAGE", "fix: temp file not correctly deleted")

pipeline.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,16 @@ func uploadPipeline(plugin Plugin, generatePipeline PipelineGenerator) (string,
8484
func diff(command string) ([]string, error) {
8585
log.Infof("Running diff command: %s", command)
8686

87-
split := strings.Split(command, " ")
88-
cmd, args := split[0], split[1:]
87+
output, err := executeCommand(
88+
env("SHELL", "bash"),
89+
[]string{"-c", strings.Replace(command, "\n", " ", -1)},
90+
)
8991

90-
output, err := executeCommand(cmd, args)
9192
if err != nil {
9293
return nil, fmt.Errorf("diff command failed: %v", err)
9394
}
9495

95-
f := func(c rune) bool {
96-
return c == '\n'
97-
}
98-
99-
return strings.FieldsFunc(strings.TrimSpace(output), f), nil
96+
return strings.Fields(strings.TrimSpace(output)), nil
10097
}
10198

10299
func stepsToTrigger(files []string, watch []WatchConfig) ([]Step, error) {

pipeline_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ README.md`)
6161
assert.Equal(t, want, got)
6262
}
6363

64+
func TestDiffWithSubshell(t *testing.T) {
65+
want := []string{
66+
"user-service/infrastructure/cloudfront.yaml",
67+
"user-service/serverless.yaml",
68+
}
69+
got, err := diff("echo $(cat e2e/multiple-paths)")
70+
assert.NoError(t, err)
71+
assert.Equal(t, want, got)
72+
}
73+
6474
func TestPipelinesToTriggerGetsListOfPipelines(t *testing.T) {
6575
want := []string{"service-1", "service-2", "service-4"}
6676

tests/command.bats

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ EOM
257257

258258
assert_success
259259

260-
assert_output --partial "--- running monorepo-diff"
261-
assert_output --partial "Running diff command: echo foo-service/ \nbat-service/"
262-
assert_output --partial "Output from diff: \nfoo-service/ \nbat-service/"
260+
assert_output --partial "--- running monorepo-diff-buildkite-plugin"
263261

264262
assert_output --partial << EOM
265263
steps:

0 commit comments

Comments
 (0)