1
0
Fork 0

Add pipeline clone options

This commit is contained in:
Lauris BH 2022-07-30 14:46:54 +03:00
parent 16da6300c2
commit 15b249ca07
No known key found for this signature in database
GPG Key ID: DFDE60A0093EB926
6 changed files with 54 additions and 0 deletions

View File

@ -27,6 +27,9 @@ Currently supports converting only from Drone CI pipeline format with limited fu
* `environment` - including `from_secret`
* `entrypoint`
* `commands`
* `clone`
* `disable`
* `depth`
* `steps`
* `name`
* `image`

View File

@ -234,6 +234,26 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error)
})
}
// Clone
if pipeline.Clone != nil {
if pipeline.Clone.Disable {
p.SkipClone = true
}
if pipeline.Clone.Depth != nil {
p.Clone = &transform.Clone{
Git: &transform.CloneStep{
Image: "woodpeckerci/plugin-git",
Settings: transform.Settings{
transform.Setting{
Name: "depth",
Value: *pipeline.Clone.Depth,
},
},
},
}
}
}
// Steps
for _, step := range pipeline.Steps {
if len(step.DependsOn) > 0 {

View File

@ -54,6 +54,11 @@ func TestTransformSimple(t *testing.T) {
assert.Equal(t, "linux/amd64", pipeline.Platform)
assert.Equal(t, map[string]string{"location": "europe"}, pipeline.Labels)
require.NotNil(t, pipeline.Clone)
require.NotNil(t, pipeline.Clone.Git)
assert.Equal(t, "woodpeckerci/plugin-git", pipeline.Clone.Git.Image)
assert.ElementsMatch(t, transform.Settings{transform.Setting{Name: "depth", Value: 50}}, pipeline.Clone.Git.Settings)
require.Len(t, pipeline.Steps, 3)
assert.Equal(t, "test", pipeline.Steps[0].Name)
assert.Equal(t, "golang:1.18", pipeline.Steps[0].Image)
@ -95,6 +100,8 @@ func TestTransformSimple(t *testing.T) {
pipeline = getPipelineByName(pipelines, "deploy")
require.NotNil(t, pipeline, "deploy pipeline not found")
assert.True(t, pipeline.SkipClone)
require.Len(t, pipeline.Steps, 1)
assert.Equal(t, "deploy", pipeline.Steps[0].Name)
assert.Equal(t, "alpine:latest", pipeline.Steps[0].Image)

View File

@ -19,6 +19,11 @@ type Workspace struct {
Path string `yaml:"path"`
}
type Clone struct {
Disable bool `yaml:"disable"`
Depth *int `yaml:"depth"`
}
type Step struct {
Name string `yaml:"name"`
Image string `yaml:"image"`
@ -51,6 +56,7 @@ type Pipeline struct {
Platform *Platform `yaml:"platform"`
Workspace *Workspace `yaml:"workspace"`
Node map[string]string `yaml:"node"`
Clone *Clone `yaml:"clone"`
Services []*Service `yaml:"services"`
Steps []*Step `yaml:"steps"`
DependsOn []string `yaml:"depends_on"`

View File

@ -20,6 +20,9 @@ services:
commands:
- "docker-entrypoint.sh postgres"
clone:
depth: 50
steps:
- name: test
image: golang:1.18
@ -67,6 +70,9 @@ trigger:
status:
- success
clone:
disable: true
steps:
- name: deploy
image: alpine:latest

View File

@ -68,12 +68,24 @@ type Workspace struct {
Path string `yaml:"path"`
}
type CloneStep struct {
Image string `yaml:"image,omitempty"`
Settings Settings `yaml:"settings,omitempty"`
}
type Clone struct {
Git *CloneStep `yaml:"git,omitempty"`
Hg *CloneStep `yaml:"hg,omitempty"`
}
type Pipeline struct {
Name string `yaml:"-"`
Platform string `yaml:"platform,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Services Services `yaml:"services,omitempty"`
Workspace *Workspace `yaml:"workspace,omitempty"`
SkipClone bool `yaml:"skip_clone,omitempty"`
Clone *Clone `yaml:"clone,omitempty"`
Steps Steps `yaml:"pipeline"`
DependsOn []string `yaml:"depends_on,omitempty"`
}