Add pipeline triggers
This commit is contained in:
parent
15b249ca07
commit
c84f01d9ce
|
@ -17,6 +17,15 @@ Currently supports converting only from Drone CI pipeline format with limited fu
|
|||
* `arch`
|
||||
* `version` - not supported by Woodpecker CI
|
||||
* `node`
|
||||
* `trigger`
|
||||
* `branch`
|
||||
* `event` - not supported by Woodpecker CI.
|
||||
* `refs` - not supported by Woodpecker CI.
|
||||
* `repo` - not supported by Woodpecker CI
|
||||
* `status`
|
||||
* `target` - not supported by Woodpecker CI.
|
||||
* `cron` - not supported by Woodpecker CI
|
||||
* `action` - not supported by Woodpecker CI.
|
||||
* `workspace`
|
||||
* `path`
|
||||
* `services`
|
||||
|
|
|
@ -14,6 +14,13 @@ type Conditions struct {
|
|||
Exclude core.Strings `yaml:"exclude,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Conditions) IsEmpty() bool {
|
||||
if c == nil {
|
||||
return true
|
||||
}
|
||||
return len(c.Conditions) == 0 && len(c.Include) == 0 && len(c.Exclude) == 0
|
||||
}
|
||||
|
||||
func (c *Conditions) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
v := &struct {
|
||||
Include core.Strings `yaml:"include,omitempty"`
|
||||
|
@ -48,3 +55,14 @@ type When struct {
|
|||
Target *Conditions `yaml:"target"`
|
||||
Cron *Conditions `yaml:"cron"`
|
||||
}
|
||||
|
||||
type Trigger struct {
|
||||
Branch *Conditions `yaml:"branch"`
|
||||
Event core.Strings `yaml:"event"`
|
||||
Refs *Conditions `yaml:"refs"`
|
||||
Repositories *Conditions `yaml:"repo"`
|
||||
Status core.Strings `yaml:"status"`
|
||||
Target *Conditions `yaml:"target"`
|
||||
Cron *Conditions `yaml:"cron"`
|
||||
Action *Conditions `yaml:"action"`
|
||||
}
|
||||
|
|
|
@ -254,6 +254,29 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error)
|
|||
}
|
||||
}
|
||||
|
||||
// Trigger
|
||||
if pipeline.Trigger != nil {
|
||||
if !pipeline.Trigger.Branch.IsEmpty() {
|
||||
p.Branches = &transform.Conditions{
|
||||
Conditions: pipeline.Trigger.Branch.Conditions,
|
||||
Include: pipeline.Trigger.Branch.Include,
|
||||
Exclude: pipeline.Trigger.Branch.Exclude,
|
||||
}
|
||||
}
|
||||
if len(pipeline.Trigger.Status) > 0 {
|
||||
p.RunsOn = pipeline.Trigger.Status
|
||||
}
|
||||
// Unsupported trigger conditions
|
||||
if !pipeline.Trigger.Action.IsEmpty() ||
|
||||
!pipeline.Trigger.Cron.IsEmpty() ||
|
||||
len(pipeline.Trigger.Event) > 0 ||
|
||||
!pipeline.Trigger.Refs.IsEmpty() ||
|
||||
!pipeline.Trigger.Repositories.IsEmpty() ||
|
||||
!pipeline.Trigger.Target.IsEmpty() {
|
||||
return nil, errors.New("unsupported trigger condition")
|
||||
}
|
||||
}
|
||||
|
||||
// Steps
|
||||
for _, step := range pipeline.Steps {
|
||||
if len(step.DependsOn) > 0 {
|
||||
|
|
|
@ -68,7 +68,7 @@ func TestTransformSimple(t *testing.T) {
|
|||
assert.False(t, pipeline.Steps[0].Privileged)
|
||||
assert.Len(t, pipeline.Steps[0].Commands, 1)
|
||||
require.NotNil(t, pipeline.Steps[0].When)
|
||||
assert.ElementsMatch(t, []string{"push"}, pipeline.Steps[0].When.Event)
|
||||
assert.ElementsMatch(t, []string{"push", "pull_request"}, pipeline.Steps[0].When.Event)
|
||||
assert.Empty(t, pipeline.Steps[0].When.Branch.Conditions)
|
||||
assert.Empty(t, pipeline.Steps[0].When.Branch.Include)
|
||||
assert.ElementsMatch(t, []string{"main", "release/*"}, pipeline.Steps[0].When.Branch.Exclude)
|
||||
|
@ -101,6 +101,7 @@ func TestTransformSimple(t *testing.T) {
|
|||
require.NotNil(t, pipeline, "deploy pipeline not found")
|
||||
|
||||
assert.True(t, pipeline.SkipClone)
|
||||
assert.ElementsMatch(t, []string{"success"}, pipeline.RunsOn)
|
||||
|
||||
require.Len(t, pipeline.Steps, 1)
|
||||
assert.Equal(t, "deploy", pipeline.Steps[0].Name)
|
||||
|
|
|
@ -59,5 +59,6 @@ type Pipeline struct {
|
|||
Clone *Clone `yaml:"clone"`
|
||||
Services []*Service `yaml:"services"`
|
||||
Steps []*Step `yaml:"steps"`
|
||||
Trigger *Trigger `yaml:"trigger"`
|
||||
DependsOn []string `yaml:"depends_on"`
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ steps:
|
|||
when:
|
||||
event:
|
||||
- push
|
||||
- pull_request
|
||||
branch:
|
||||
exclude:
|
||||
- main
|
||||
|
|
|
@ -82,10 +82,12 @@ type Pipeline struct {
|
|||
Name string `yaml:"-"`
|
||||
Platform string `yaml:"platform,omitempty"`
|
||||
Labels map[string]string `yaml:"labels,omitempty"`
|
||||
RunsOn []string `yaml:"runs_on,omitempty"`
|
||||
Branches *Conditions `yaml:"branches,omitempty"`
|
||||
DependsOn []string `yaml:"depends_on,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"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue