diff --git a/database/pipeline.go b/database/pipeline.go index 21936294..f78549b4 100644 --- a/database/pipeline.go +++ b/database/pipeline.go @@ -7,6 +7,7 @@ import ( "errors" "github.com/go-vela/types/library" + "github.com/lib/pq" ) var ( @@ -48,6 +49,7 @@ type Pipeline struct { Steps sql.NullBool `sql:"steps"` Templates sql.NullBool `sql:"templates"` Data []byte `sql:"data"` + Warnings pq.StringArray `sql:"warnings" gorm:"type:varchar(1000)"` } // Compress will manipulate the existing data for the @@ -158,6 +160,7 @@ func (p *Pipeline) ToLibrary() *library.Pipeline { pipeline.SetSteps(p.Steps.Bool) pipeline.SetTemplates(p.Templates.Bool) pipeline.SetData(p.Data) + pipeline.SetWarnings(p.Warnings) return pipeline } @@ -200,6 +203,10 @@ func (p *Pipeline) Validate() error { p.Type = sql.NullString{String: sanitize(p.Type.String), Valid: p.Type.Valid} p.Version = sql.NullString{String: sanitize(p.Version.String), Valid: p.Version.Valid} + for i, v := range p.Warnings { + p.Warnings[i] = sanitize(v) + } + return nil } @@ -222,6 +229,8 @@ func PipelineFromLibrary(p *library.Pipeline) *Pipeline { Steps: sql.NullBool{Bool: p.GetSteps(), Valid: true}, Templates: sql.NullBool{Bool: p.GetTemplates(), Valid: true}, Data: p.GetData(), + + Warnings: pq.StringArray(p.GetWarnings()), } return pipeline.Nullify() diff --git a/library/pipeline.go b/library/pipeline.go index 1a706604..de2d580d 100644 --- a/library/pipeline.go +++ b/library/pipeline.go @@ -10,20 +10,21 @@ import ( // // swagger:model Pipeline type Pipeline struct { - ID *int64 `json:"id,omitempty"` - RepoID *int64 `json:"repo_id,omitempty"` - Commit *string `json:"commit,omitempty"` - Flavor *string `json:"flavor,omitempty"` - Platform *string `json:"platform,omitempty"` - Ref *string `json:"ref,omitempty"` - Type *string `json:"type,omitempty"` - Version *string `json:"version,omitempty"` - ExternalSecrets *bool `json:"external_secrets,omitempty"` - InternalSecrets *bool `json:"internal_secrets,omitempty"` - Services *bool `json:"services,omitempty"` - Stages *bool `json:"stages,omitempty"` - Steps *bool `json:"steps,omitempty"` - Templates *bool `json:"templates,omitempty"` + ID *int64 `json:"id,omitempty"` + RepoID *int64 `json:"repo_id,omitempty"` + Commit *string `json:"commit,omitempty"` + Flavor *string `json:"flavor,omitempty"` + Platform *string `json:"platform,omitempty"` + Ref *string `json:"ref,omitempty"` + Type *string `json:"type,omitempty"` + Version *string `json:"version,omitempty"` + ExternalSecrets *bool `json:"external_secrets,omitempty"` + InternalSecrets *bool `json:"internal_secrets,omitempty"` + Services *bool `json:"services,omitempty"` + Stages *bool `json:"stages,omitempty"` + Steps *bool `json:"steps,omitempty"` + Templates *bool `json:"templates,omitempty"` + Warnings *[]string `json:"warnings,omitempty"` // swagger:strfmt base64 Data *[]byte `json:"data,omitempty"` } @@ -223,6 +224,15 @@ func (p *Pipeline) GetData() []byte { return *p.Data } +func (p *Pipeline) GetWarnings() []string { + // return zero value if Pipeline type or field is nil + if p == nil || p.Data == nil { + return []string{} + } + + return *p.Warnings +} + // SetID sets the ID field. // // When the provided Pipeline type is nil, it @@ -418,6 +428,15 @@ func (p *Pipeline) SetData(v []byte) { p.Data = &v } +func (p *Pipeline) SetWarnings(v []string) { + // return if Pipeline type is nil + if p == nil { + return + } + + p.Warnings = &v +} + // String implements the Stringer interface for the Pipeline type. func (p *Pipeline) String() string { return fmt.Sprintf(`{ diff --git a/yaml/build.go b/yaml/build.go index c8ed9dbb..79cff8ea 100644 --- a/yaml/build.go +++ b/yaml/build.go @@ -57,6 +57,12 @@ func (b *Build) ToPipelineLibrary() *library.Pipeline { pipeline.SetExternalSecrets(external) pipeline.SetInternalSecrets(internal) + w := ([]string{}) + for _, s := range b.Steps { + w = append(w, s.Warnings...) + } + pipeline.Warnings = &w + return pipeline } diff --git a/yaml/step.go b/yaml/step.go index 012f2161..e53cd4ec 100644 --- a/yaml/step.go +++ b/yaml/step.go @@ -38,6 +38,7 @@ type ( User string `yaml:"user,omitempty" json:"user,omitempty" jsonschema:"description=Set the user for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-user-key"` ReportAs string `yaml:"report_as,omitempty" json:"report_as,omitempty" jsonschema:"description=Set the name of the step to report as.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-report_as-key"` IDRequest string `yaml:"id_request,omitempty" json:"id_request,omitempty" jsonschema:"description=Request ID Request Token for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-id_request-key"` + Warnings []string `yaml:"-" json:"-"` } ) @@ -88,6 +89,7 @@ func (s *StepSlice) UnmarshalYAML(v *yaml.Node) error { for _, st := range v.Content { // make local var tmpStep := *st + warnings := []string{} // steps are mapping nodes if tmpStep.Kind != yaml.MappingNode { @@ -113,6 +115,8 @@ func (s *StepSlice) UnmarshalYAML(v *yaml.Node) error { if anchorKey == nil { anchorKey = key anchorSequence = value + + warnings = append(warnings, fmt.Sprintf("%d:contains anchor reference, behavior may have changed", key.Line)) } // append value to anchor list @@ -172,6 +176,9 @@ func (s *StepSlice) UnmarshalYAML(v *yaml.Node) error { step.Pull = constants.PullNotPresent } + // append warnings + step.Warnings = append(step.Warnings, warnings...) + *stepSlice = append(*stepSlice, step) }