From 0ba7c597ee1e7015e297815a2386d571e8591eaa Mon Sep 17 00:00:00 2001 From: Lauris BH Date: Sat, 30 Jul 2022 19:52:50 +0300 Subject: [PATCH] Add exec pipeline support --- README.md | 2 +- drone/drone.go | 10 ++++++++-- drone/drone_test.go | 14 +++++++++++++- drone/testdata/.drone.yml | 19 +++++++++++++++++++ pipeline.go | 2 +- secrets.go | 4 +++- 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9c8ded5..8517e34 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Currently supports converting only from Drone CI pipeline format with limited fu ## Drone pipeline supported features * `kind` - must be `pipeline` -* `type` - only `docker` supported +* `type` - only `docker` and `exec` are supported * `name` * `platform` * `os` diff --git a/drone/drone.go b/drone/drone.go index cc02177..34fdc34 100644 --- a/drone/drone.go +++ b/drone/drone.go @@ -193,7 +193,7 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error) if pipeline.Kind != "pipeline" { return nil, transform.UnsupportedError } - if pipeline.Type != "docker" { + if pipeline.Type != "docker" && pipeline.Type != "exec" { return nil, transform.UnsupportedError } if pipeline.Platform != nil && len(pipeline.Platform.Version) > 0 { @@ -338,9 +338,15 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error) if err != nil { return nil, err } + var image string + if pipeline.Type == "docker" { + image = d.ConvertImage(step.Image) + } else if pipeline.Type == "exec" { + image = "bash" + } p.Steps = append(p.Steps, &transform.Step{ Name: step.Name, - Image: d.ConvertImage(step.Image), + Image: image, Pull: step.Pull == "always", Environment: env, Secrets: secrets, diff --git a/drone/drone_test.go b/drone/drone_test.go index ef8593e..df1cfca 100644 --- a/drone/drone_test.go +++ b/drone/drone_test.go @@ -37,7 +37,7 @@ func TestTransformSimple(t *testing.T) { }) require.NoError(t, err) - require.Len(t, pipelines, 2) + require.Len(t, pipelines, 3) pipeline := getPipelineByName(pipelines, "build") require.NotNil(t, pipeline, "build pipeline not found") @@ -120,4 +120,16 @@ func TestTransformSimple(t *testing.T) { assert.Equal(t, "staging", pipeline.Steps[0].When.Environment) assert.ElementsMatch(t, []string{"build"}, pipeline.DependsOn) + + pipeline = getPipelineByName(pipelines, "update-nlb") + require.NotNil(t, pipeline, "update-nlb pipeline not found") + + assert.True(t, pipeline.SkipClone) + + require.Len(t, pipeline.Steps, 1) + assert.Equal(t, "update", pipeline.Steps[0].Name) + assert.Equal(t, "bash", pipeline.Steps[0].Image) + assert.Len(t, pipeline.Steps[0].Commands, 1) + + assert.ElementsMatch(t, []string{"deploy"}, pipeline.DependsOn) } diff --git a/drone/testdata/.drone.yml b/drone/testdata/.drone.yml index f942f38..284e4ba 100644 --- a/drone/testdata/.drone.yml +++ b/drone/testdata/.drone.yml @@ -103,3 +103,22 @@ steps: refs: - refs/tags/v* - refs/tags/RELEASE-* + +--- +kind: pipeline +type: exec +name: update-nlb + +depends_on: +- deploy + +clone: + disable: true + +node: + server: nlb + +steps: + - name: update + commands: + - systemctl reload haproxy diff --git a/pipeline.go b/pipeline.go index cc7b171..dc627c4 100644 --- a/pipeline.go +++ b/pipeline.go @@ -14,7 +14,7 @@ var UnsupportedError = errors.New("unsupported pipeline") type Step struct { Name string `yaml:"-"` - Image string `yaml:"image"` + Image string `yaml:"image,omitempty"` Pull bool `yaml:"pull,omitempty"` Environment []string `yaml:"environment,omitempty"` Secrets Secrets `yaml:"secrets,omitempty"` diff --git a/secrets.go b/secrets.go index fc91adc..238e04d 100644 --- a/secrets.go +++ b/secrets.go @@ -4,7 +4,9 @@ package transform -import "strings" +import ( + "strings" +) type Secret struct { Source string `yaml:"source"`