1
0
Fork 0

Step dependencies are not supported in Woodpecker CI

* Add output formatting
This commit is contained in:
Lauris BH 2022-07-29 22:32:55 +03:00
parent b45571326b
commit eb6a846a67
No known key found for this signature in database
GPG Key ID: DFDE60A0093EB926
7 changed files with 52 additions and 9 deletions

View File

@ -28,5 +28,5 @@ Currently supports converting only from Drone CI pipeline format with limited fu
* `status`
* `target` - only single environment condition is supported by Woodpecker CI
* `cron` - not supported by Woodpecker CI
* `depends_on`
* `depends_on` - not supported by Woodpecker CI
* `depends_on`

View File

@ -91,6 +91,10 @@ func WriteDest(pipelines []*transform.Pipeline, path string) error {
if err != nil {
return err
}
buf, err = transform.FormatWoodpeckerYAML(buf)
if err != nil {
return err
}
if err = os.WriteFile(p, buf, 0o644); err != nil {
return err
}

View File

@ -181,6 +181,9 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error)
}
for _, step := range pipeline.Steps {
if len(step.DependsOn) > 0 {
return nil, errors.New("unsupported step property: depends_on")
}
env := make([]string, 0, len(step.Environment))
for k, v := range step.Environment {
if v.Secret != "" {
@ -211,7 +214,6 @@ func (d DronePipeline) Convert(pipeline *Pipeline) (*transform.Pipeline, error)
Settings: step.Settings,
Commands: step.Commands,
When: when,
DependsOn: step.DependsOn,
})
}

View File

@ -60,12 +60,10 @@ func TestTransformSimple(t *testing.T) {
assert.ElementsMatch(t, []string{"CGO=0", "GOOS=linux", "GOARCH=amd64"}, pipeline.Steps[1].Environment)
assert.Len(t, pipeline.Steps[1].Commands, 1)
assert.Nil(t, pipeline.Steps[1].When)
assert.ElementsMatch(t, []string{"test"}, pipeline.Steps[1].DependsOn)
assert.Equal(t, "docker", pipeline.Steps[2].Name)
assert.Equal(t, "plugin/docker", pipeline.Steps[2].Image)
assert.False(t, pipeline.Steps[2].Pull)
assert.ElementsMatch(t, []string{"build"}, pipeline.Steps[2].DependsOn)
assert.ElementsMatch(t, transform.Settings{
{Name: "repo", Value: "org/simple"},
{Name: "username", Value: map[string]interface{}{

View File

@ -28,8 +28,6 @@ steps:
GOARCH: amd64
commands:
- go build
depends_on:
- test
- name: docker
image: plugin/docker
@ -39,8 +37,6 @@ steps:
from_secret: docker_username
password:
from_secret: docker_password
depends_on:
- build
---
kind: pipeline

44
format.go Normal file
View File

@ -0,0 +1,44 @@
// Copyright 2022 Lauris BH. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package transform
import (
"bufio"
"bytes"
"strings"
)
// FormatWoodpeckerYAML add newlines so that the pipeline YAML is easier to read.
func FormatWoodpeckerYAML(data []byte) ([]byte, error) {
scanner := bufio.NewScanner(bytes.NewReader(data))
out := bytes.NewBuffer(nil)
var isPipeline bool
var i int
for scanner.Scan() {
line := scanner.Text()
if line == "pipeline:" {
isPipeline = true
i = 0
} else if isPipeline && len(line) > 0 && line[0] != ' ' && line[0] != '\t' {
isPipeline = false
out.WriteByte('\n')
i = 0
} else if i > 0 && len(line) > 0 && line[0] != ' ' && line[0] != '\t' && line[0] != '-' {
out.WriteByte('\n')
}
if isPipeline && i > 1 &&
((strings.HasPrefix(line, " ") && len(line) > 2 && line[3] != ' ') ||
(len(line) > 1 && line[0] == '\t' && line[1] != '\t')) {
out.WriteString("\n")
}
out.WriteString(line)
out.WriteByte('\n')
i++
}
if err := scanner.Err(); err != nil {
return nil, err
}
return out.Bytes(), nil
}

View File

@ -49,7 +49,6 @@ type Step struct {
Commands []string `yaml:"commands,omitempty"`
Settings Settings `yaml:"settings,omitempty"`
When *StepWhen `yaml:"when,omitempty"`
DependsOn []string `yaml:"depends_on,omitempty"`
}
type Steps []*Step