Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions api/types/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Pipeline struct {
Stages *bool `json:"stages,omitempty"`
Steps *bool `json:"steps,omitempty"`
Templates *bool `json:"templates,omitempty"`
TestReport *bool `json:"test_report,omitempty"`
Warnings *[]string `json:"warnings,omitempty"`
// swagger:strfmt base64
Data *[]byte `json:"data,omitempty"`
Expand Down Expand Up @@ -237,6 +238,19 @@ func (p *Pipeline) GetData() []byte {
return *p.Data
}

// GetTestReport returns the TestReport results field.
//
// When the provided Pipeline type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (p *Pipeline) GetTestReport() bool {
// return zero value if Pipeline type or TestReport field is nil
if p == nil || p.TestReport == nil {
return false
}

return *p.TestReport
}

// SetID sets the ID field.
//
// When the provided Pipeline type is nil, it
Expand Down Expand Up @@ -419,6 +433,19 @@ func (p *Pipeline) SetTemplates(v bool) {
p.Templates = &v
}

// SetTestReport sets the TestReport field.
//
// When the provided Pipeline type is nil, it
// will set nothing and immediately return.
func (p *Pipeline) SetTestReport(v bool) {
// return if Pipeline type is nil
if p == nil {
return
}

p.TestReport = &v
}

// SetWarnings sets the Warnings field.
//
// When the provided Pipeline type is nil, it
Expand Down Expand Up @@ -461,6 +488,7 @@ func (p *Pipeline) String() string {
Stages: %t,
Steps: %t,
Templates: %t,
TestReport: %t,
Type: %s,
Version: %s,
Warnings: %v,
Expand All @@ -478,6 +506,7 @@ func (p *Pipeline) String() string {
p.GetStages(),
p.GetSteps(),
p.GetTemplates(),
p.GetTestReport(),
p.GetType(),
p.GetVersion(),
p.GetWarnings(),
Expand Down
3 changes: 3 additions & 0 deletions api/types/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func TestAPI_Pipeline_String(t *testing.T) {
Stages: %t,
Steps: %t,
Templates: %t,
TestReport: %t,
Type: %s,
Version: %s,
Warnings: %v,
Expand All @@ -231,6 +232,7 @@ func TestAPI_Pipeline_String(t *testing.T) {
p.GetStages(),
p.GetSteps(),
p.GetTemplates(),
p.GetTestReport(),
p.GetType(),
p.GetVersion(),
p.GetWarnings(),
Expand Down Expand Up @@ -263,6 +265,7 @@ func testPipeline() *Pipeline {
p.SetStages(false)
p.SetSteps(true)
p.SetTemplates(false)
p.SetTestReport(true)
p.SetData(testPipelineData())
p.SetWarnings([]string{"42:this is a warning"})

Expand Down
62 changes: 62 additions & 0 deletions api/types/test_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package types

Check failure on line 1 in api/types/test_report.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] api/types/test_report.go#L1

Missed header for check (goheader)
Raw output
api/types/test_report.go:1:1: Missed header for check (goheader)
package types
^
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Missed header for check (goheader)


import "fmt"

// TestReport is the API representation of a test report for a pipeline.
//
// swagger:model TestReport
type TestReport struct {
Results *string `json:"results,omitempty"`
Attachments *string `json:"attachments,omitempty"`
}

// GetResults returns the Results field.
//
// When the provided TestReport type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (t *TestReport) GetResults() string {
// return zero value if TestReport type or Results field is nil
if t == nil || t.Results == nil {
return ""
}

return *t.Results
}

// GetAttachments returns the Attachments field.
//
// When the provided TestReport type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (t *TestReport) GetAttachments() string {
// return zero value if TestReport type or Attachments field is nil
if t == nil || t.Attachments == nil {
return ""
}

return *t.Attachments
}

// SetResults sets the Results field.
func (t *TestReport) SetResults(v string) {
// return if TestReport type is nil
if t == nil {
return
}
// set the Results field
t.Results = &v
}

// SetAttachments sets the Attachments field.
func (t *TestReport) SetAttachments(v string) {
// return if TestReport type is nil
if t == nil {
return
}
// set the Attachments field
t.Attachments = &v
}

// String implements the Stringer interface for the TestReport type.
func (t *TestReport) String() string {
return fmt.Sprintf("Results: %s, Attachments: %s", t.GetResults(), t.GetAttachments())
}
4 changes: 3 additions & 1 deletion compiler/native/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@

if len(step.Commands) == 0 && len(step.Environment) == 0 &&
len(step.Parameters) == 0 && len(step.Secrets) == 0 &&
len(step.Template.Name) == 0 && !step.Detach {
len(step.Template.Name) == 0 && len(step.TestReport.Results) == 0 &&
len(step.TestReport.Attachments) == 0 && !step.Detach {

Check failure on line 112 in compiler/native/validate.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/native/validate.go#L112

unnecessary leading newline (whitespace)
Raw output
compiler/native/validate.go:112:59: unnecessary leading newline (whitespace)
			len(step.TestReport.Attachments) == 0 && !step.Detach {
			                                                       ^
8 issues:
* goheader: 3
* tagalign: 4
* whitespace: 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
unnecessary leading newline (whitespace)


return fmt.Errorf("no commands, environment, parameters, secrets or template provided for step %s", step.Name)
}
}
Expand Down
31 changes: 31 additions & 0 deletions compiler/native/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,34 @@ func TestNative_Validate_Steps_StepNameConflict(t *testing.T) {
t.Errorf("Validate should have returned err")
}
}

func TestNative_Validate_TestReport(t *testing.T) {
// setup types
str := "foo"
p := &yaml.Build{
Version: "v1",
Steps: yaml.StepSlice{
&yaml.Step{
Commands: raw.StringSlice{"echo hello"},
Image: "alpine",
Name: str,
Pull: "always",
TestReport: yaml.TestReport{
Results: []string{"results.xml"},
Attachments: []string{"attachments"},
},
},
},
}

// run test
compiler, err := FromCLICommand(context.Background(), testCommand(t, "http://foo.example.com"))
if err != nil {
t.Errorf("Unable to create new compiler: %v", err)
}

err = compiler.ValidateYAML(p)
if err != nil {
t.Errorf("Validate returned err: %v", err)
}
}
4 changes: 3 additions & 1 deletion compiler/types/pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Pull string `json:"pull,omitempty" yaml:"pull,omitempty"`
Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"`
Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"`
TestReport TestReport `json:"test_report,omitempty" yaml:"test_report,omitempty"`

Check failure on line 51 in compiler/types/pipeline/container.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/types/pipeline/container.go#L51

tag is not aligned, should be: json:"test_report,omitempty" yaml:"test_report,omitempty" (tagalign)
Raw output
compiler/types/pipeline/container.go:51:33: tag is not aligned, should be: json:"test_report,omitempty" yaml:"test_report,omitempty" (tagalign)
		TestReport  TestReport        `json:"test_report,omitempty"     yaml:"test_report,omitempty"`
		                              ^
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
tag is not aligned, should be: json:"test_report,omitempty" yaml:"test_report,omitempty" (tagalign)

Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"`
Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
Expand Down Expand Up @@ -137,7 +138,8 @@
len(c.Volumes) == 0 &&
len(c.User) == 0 &&
len(c.ReportAs) == 0 &&
len(c.IDRequest) == 0 {
len(c.IDRequest) == 0 &&
reflect.DeepEqual(c.TestReport, TestReport{}) {
return true
}

Expand Down
54 changes: 54 additions & 0 deletions compiler/types/pipeline/test_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package pipeline

Check failure on line 1 in compiler/types/pipeline/test_report.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/types/pipeline/test_report.go#L1

Missed header for check (goheader)
Raw output
compiler/types/pipeline/test_report.go:1:1: Missed header for check (goheader)
package pipeline
^
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Missed header for check (goheader)


// TestReport represents the structure for test report configuration.
type (
// TestReportSlice is the pipleine representation
//of a slice of TestReport.
//
// swagger:model PipelineTestReportSlice
TestReportSlice []*TestReport

// TestReport is the pipeline representation
// of a test report for a pipeline.
//
// swagger:model PipelineTestReport
TestReport struct {
Results []string `yaml:"results,omitempty" json:"results,omitempty"`

Check failure on line 16 in compiler/types/pipeline/test_report.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/types/pipeline/test_report.go#L16

tag is not aligned, should be: yaml:"results,omitempty" json:"results,omitempty" (tagalign)
Raw output
compiler/types/pipeline/test_report.go:16:24: tag is not aligned, should be: yaml:"results,omitempty"     json:"results,omitempty" (tagalign)
		Results     []string `yaml:"results,omitempty" json:"results,omitempty"`
		                     ^
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
tag is not aligned, should be: yaml:"results,omitempty" json:"results,omitempty" (tagalign)

Attachments []string `yaml:"attachments,omitempty" json:"attachments,omitempty"`
}
)

// Purge removes the test report configuration from the pipeline
// if it does not match the provided ruledata. If both results
// and attachments are provided, then an empty test report is returned.
//func (t *TestReport) Purge(r *RuleData) (*TestReport, error) {
// // return an empty test report if both results and attachments are provided
// if len(t.Results) > 0 && len(t.Attachments) > 0 {
// return nil, fmt.Errorf("cannot have both results and attachments in the test report")
// }
//
// // purge results if provided
// if len(t.Results) > 0 {
// t.Results = ""
// }
//
// // purge attachments if provided
// if len(t.Attachments) > 0 {
// t.Attachments = ""
// }
//
// // return the purged test report
// return t, nil
//}

// Empty returns true if the provided test report is empty.
func (t *TestReport) Empty() bool {
// return true if every test report field is empty
if len(t.Results) == 0 &&
len(t.Attachments) == 0 {
return true
}

// return false if any of the test report fields are provided
return false
}
29 changes: 29 additions & 0 deletions compiler/types/pipeline/test_report_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pipeline

Check failure on line 1 in compiler/types/pipeline/test_report_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] compiler/types/pipeline/test_report_test.go#L1

Missed header for check (goheader)
Raw output
compiler/types/pipeline/test_report_test.go:1:1: Missed header for check (goheader)
package pipeline
^
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
Missed header for check (goheader)


import "testing"

func TestPipeline_TestReport_Empty(t *testing.T) {
// setup tests
tests := []struct {
report *TestReport
want bool
}{
{
report: &TestReport{Results: []string{"foo"}},
want: false,
},
{
report: new(TestReport),
want: true,
},
}

// run tests
for _, test := range tests {
got := test.report.Empty()

if got != test.want {
t.Errorf("Empty is %v, want %t", got, test.want)
}
}
}
3 changes: 3 additions & 0 deletions compiler/types/yaml/buildkite/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type (
Commands raw.StringSlice `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema:"description=Execution instructions to run inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-commands-key"`
Entrypoint raw.StringSlice `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty" jsonschema:"description=Command to execute inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-entrypoint-key"`
Secrets StepSecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Sensitive variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-secrets-key"`
TestReport TestReport `yaml:"test_report,omitempty" json:"test_report,omitempty" jsonschema:"description=Test report configuration for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-test_report-key"`
Template StepTemplate `yaml:"template,omitempty" json:"template,omitempty" jsonschema:"oneof_required=template,description=Name of template to expand in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-template-key"`
Ulimits UlimitSlice `yaml:"ulimits,omitempty" json:"ulimits,omitempty" jsonschema:"description=Set the user limits for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ulimits-key"`
Volumes VolumeSlice `yaml:"volumes,omitempty" json:"volumes,omitempty" jsonschema:"description=Mount volumes for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-volume-key"`
Expand Down Expand Up @@ -60,6 +61,7 @@ func (s *StepSlice) ToPipeline() *pipeline.ContainerSlice {
Pull: step.Pull,
Ruleset: *step.Ruleset.ToPipeline(),
Secrets: *step.Secrets.ToPipeline(),
TestReport: *step.TestReport.ToPipeline(),
Ulimits: *step.Ulimits.ToPipeline(),
Volumes: *step.Volumes.ToPipeline(),
User: step.User,
Expand Down Expand Up @@ -165,6 +167,7 @@ func (s *Step) ToYAML() *yaml.Step {
Ruleset: *s.Ruleset.ToYAML(),
Secrets: *s.Secrets.ToYAML(),
Template: s.Template.ToYAML(),
TestReport: s.TestReport.ToYAML(),
Ulimits: *s.Ulimits.ToYAML(),
Volumes: *s.Volumes.ToYAML(),
Parameters: s.Parameters,
Expand Down
17 changes: 17 additions & 0 deletions compiler/types/yaml/buildkite/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func TestYaml_StepSlice_ToPipeline(t *testing.T) {
AccessMode: "ro",
},
},
TestReport: TestReport{
Results: []string{"test-results/*.xml"},
Attachments: []string{"screenshots/**/*.png", " video/*.mp4"},
},
},
},
want: &pipeline.ContainerSlice{
Expand Down Expand Up @@ -134,6 +138,10 @@ func TestYaml_StepSlice_ToPipeline(t *testing.T) {
AccessMode: "ro",
},
},
TestReport: pipeline.TestReport{
Results: []string{"test-results/*.xml"},
Attachments: []string{"screenshots/**/*.png", " video/*.mp4"},
},
},
},
},
Expand Down Expand Up @@ -213,6 +221,15 @@ func TestYaml_StepSlice_UnmarshalYAML(t *testing.T) {
},
},
},
{
Name: "test-reports",
Pull: "always",
Image: "golang:1.20",
TestReport: TestReport{
Results: []string{"test-results/*.xml"},
Attachments: []string{"screenshots/**/*.png", " video/*.mp4"},
},
},
},
},
{
Expand Down
Loading
Loading