diff --git a/engine/compiler/compiler.go b/engine/compiler/compiler.go index 67c10af..8d12f69 100644 --- a/engine/compiler/compiler.go +++ b/engine/compiler/compiler.go @@ -22,6 +22,7 @@ import ( "github.com/drone/runner-go/shell" "github.com/dchest/uniuri" + "github.com/gosimple/slug" ) // random generator function @@ -194,7 +195,8 @@ func (c *Compiler) Compile(ctx context.Context) *engine.Spec { // create steps for _, src := range c.Pipeline.Steps { - buildpath := filepath.Join(spec.Root, "opt", src.Name+shell.Suffix) + buildslug := slug.Make(src.Name) + buildpath := filepath.Join(spec.Root, "opt", buildslug+shell.Suffix) buildfile := shell.Script(src.Commands) cmd, args := shell.Command() diff --git a/engine/compiler/compiler_test.go b/engine/compiler/compiler_test.go index 1683afc..9ba2e32 100644 --- a/engine/compiler/compiler_test.go +++ b/engine/compiler/compiler_test.go @@ -176,8 +176,15 @@ func testCompile(t *testing.T, source, golden string) *engine.Spec { ignore := cmpopts.IgnoreFields(engine.Step{}, "Envs", "Secrets") if diff := cmp.Diff(got, want, ignore); len(diff) != 0 { + dump(got) t.Errorf(diff) } return got } + +func dump(v interface{}) { + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", " ") + enc.Encode(v) +} diff --git a/engine/compiler/testdata/graph.json b/engine/compiler/testdata/graph.json index 68075b5..4c9de2d 100644 --- a/engine/compiler/testdata/graph.json +++ b/engine/compiler/testdata/graph.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/clone", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3RlcgoK" + "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" } ], "secrets": [], @@ -55,7 +55,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCg==" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], "secrets": [], @@ -75,7 +75,7 @@ { "path": "/tmp/drone-random/opt/test", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cgo=" + "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], "secrets": [], diff --git a/engine/compiler/testdata/match.json b/engine/compiler/testdata/match.json index 27ad6d2..6ffb3fa 100644 --- a/engine/compiler/testdata/match.json +++ b/engine/compiler/testdata/match.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCg==" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], "name": "build", @@ -53,7 +53,7 @@ { "path": "/tmp/drone-random/opt/test", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cgo=" + "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], "name": "test", diff --git a/engine/compiler/testdata/noclone_graph.json b/engine/compiler/testdata/noclone_graph.json index 8871644..09b1bc5 100644 --- a/engine/compiler/testdata/noclone_graph.json +++ b/engine/compiler/testdata/noclone_graph.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCg==" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], "name": "build", @@ -54,7 +54,7 @@ { "path": "/tmp/drone-random/opt/test", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cgo=" + "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], "name": "test", diff --git a/engine/compiler/testdata/noclone_serial.json b/engine/compiler/testdata/noclone_serial.json index 8ae4751..5b3a6e9 100644 --- a/engine/compiler/testdata/noclone_serial.json +++ b/engine/compiler/testdata/noclone_serial.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCmVjaG8gKyAiZ28gdGVzdCIKZ28gdGVzdAoK" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCmVjaG8gKyAiZ28gdGVzdCIKZ28gdGVzdAo=" } ], "name": "build", diff --git a/engine/compiler/testdata/run_always.json b/engine/compiler/testdata/run_always.json index 495e267..4e26029 100644 --- a/engine/compiler/testdata/run_always.json +++ b/engine/compiler/testdata/run_always.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCg==" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], "name": "build", diff --git a/engine/compiler/testdata/run_failure.json b/engine/compiler/testdata/run_failure.json index 8929a71..f271a13 100644 --- a/engine/compiler/testdata/run_failure.json +++ b/engine/compiler/testdata/run_failure.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCg==" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], "name": "build", diff --git a/engine/compiler/testdata/serial.json b/engine/compiler/testdata/serial.json index 68075b5..4c9de2d 100644 --- a/engine/compiler/testdata/serial.json +++ b/engine/compiler/testdata/serial.json @@ -34,7 +34,7 @@ { "path": "/tmp/drone-random/opt/clone", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3RlcgoK" + "data": "CnNldCAtZQoKZWNobyArICJnaXQgaW5pdCIKZ2l0IGluaXQKCmVjaG8gKyAiZ2l0IHJlbW90ZSBhZGQgb3JpZ2luICIKZ2l0IHJlbW90ZSBhZGQgb3JpZ2luIAoKZWNobyArICJnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6IgpnaXQgZmV0Y2ggIG9yaWdpbiArcmVmcy9oZWFkcy9tYXN0ZXI6CgplY2hvICsgImdpdCBjaGVja291dCAgLWIgbWFzdGVyIgpnaXQgY2hlY2tvdXQgIC1iIG1hc3Rlcgo=" } ], "secrets": [], @@ -55,7 +55,7 @@ { "path": "/tmp/drone-random/opt/build", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQKCg==" + "data": "CnNldCAtZQoKZWNobyArICJnbyBidWlsZCIKZ28gYnVpbGQK" } ], "secrets": [], @@ -75,7 +75,7 @@ { "path": "/tmp/drone-random/opt/test", "mode": 448, - "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cgo=" + "data": "CnNldCAtZQoKZWNobyArICJnbyB0ZXN0IgpnbyB0ZXN0Cg==" } ], "secrets": [], diff --git a/go.mod b/go.mod index 86f13dd..690937a 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/drone/signal v1.0.0 github.com/golang/mock v1.3.1 github.com/google/go-cmp v0.3.0 + github.com/gosimple/slug v1.5.0 github.com/hashicorp/go-multierror v1.0.0 github.com/joho/godotenv v1.3.0 github.com/kardianos/service v1.0.0 @@ -23,6 +24,7 @@ require ( github.com/mattn/go-isatty v0.0.8 github.com/natessilva/dag v0.0.0-20180124060714-7194b8dcc5c4 github.com/orandin/lumberjackrus v1.0.1 + github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect github.com/sirupsen/logrus v1.4.2 golang.org/x/sync v0.0.0-20190423024810-112230192c58 gopkg.in/alecthomas/kingpin.v2 v2.2.6 diff --git a/go.sum b/go.sum index 9480f7d..d79df01 100644 --- a/go.sum +++ b/go.sum @@ -147,6 +147,8 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/gosimple/slug v1.5.0 h1:AIIjgCjHcLpX8LzM2NpG4QGW9kUfqv0OLiFRfPv/H3E= +github.com/gosimple/slug v1.5.0/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= @@ -166,6 +168,8 @@ github.com/natessilva/dag v0.0.0-20180124060714-7194b8dcc5c4/go.mod h1:cojhOHk1g github.com/orandin/lumberjackrus v1.0.1 h1:7ysDQ0MHD79zIFN9/EiDHjUcgopNi5ehtxFDy8rUkWo= github.com/orandin/lumberjackrus v1.0.1/go.mod h1:xYLt6H8W93pKnQgUQaxsApS0Eb4BwHLOkxk5DVzf5H0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ= +github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q= github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=