github.com/profzone/eden-framework@v1.0.10/internal/project/drone/drone_ci.go (about) 1 package drone 2 3 import ( 4 "github.com/profzone/eden-framework/internal/project/drone/enums" 5 "gopkg.in/yaml.v2" 6 "io/ioutil" 7 "os" 8 ) 9 10 type CIDroneBase struct { 11 Kind enums.DroneCiKind `yaml:"kind" json:"kind"` 12 Name string `yaml:"name,omitempty" json:"name,omitempty"` 13 } 14 15 func (b *CIDroneBase) WithKind(k enums.DroneCiKind) *CIDroneBase { 16 b.Kind = k 17 return b 18 } 19 20 func (b *CIDroneBase) WithName(n string) *CIDroneBase { 21 b.Name = n 22 return b 23 } 24 25 type CIDroneSecret struct { 26 CIDroneBase `yaml:",inline"` 27 Data string `yaml:"data" json:"data"` 28 } 29 30 func NewCIDroneSecret(name string) *CIDroneSecret { 31 s := new(CIDroneSecret) 32 s.WithKind(enums.DRONE_CI_KIND__secret).WithName(name) 33 return s 34 } 35 36 func (s *CIDroneSecret) WithData(d string) *CIDroneSecret { 37 s.Data = d 38 return s 39 } 40 41 type CIDroneSignature struct { 42 CIDroneBase `yaml:",inline"` 43 Hmac string `yaml:"hmac" json:"hmac"` 44 } 45 46 func NewCIDroneSignature() *CIDroneSignature { 47 s := new(CIDroneSignature) 48 s.WithKind(enums.DRONE_CI_KIND__signature) 49 return s 50 } 51 52 func (s *CIDroneSignature) WithHmac(h string) *CIDroneSignature { 53 s.Hmac = h 54 return s 55 } 56 57 type CIDronePipeline struct { 58 CIDroneBase `yaml:",inline"` 59 Type enums.DroneCiType `yaml:"type" json:"type"` 60 } 61 62 func NewCIDronePipeline() *CIDronePipeline { 63 p := new(CIDronePipeline) 64 p.WithKind(enums.DRONE_CI_KIND__pipeline) 65 return p 66 } 67 68 func (p *CIDronePipeline) WithType(t enums.DroneCiType) *CIDronePipeline { 69 p.Type = t 70 return p 71 } 72 73 type CIDronePipelineDocker struct { 74 CIDronePipeline `yaml:",inline"` 75 Volumes []PipelineVolume `yaml:"volumes,omitempty" json:"volumes,omitempty"` 76 Trigger *PipelineTrigger `yaml:"trigger,omitempty" json:"trigger,omitempty"` 77 Platform *PipelinePlatform `yaml:"platform,omitempty" json:"platform,omitempty"` 78 Workspace *PipelineWorkspace `yaml:"workspace,omitempty" json:"workspace,omitempty"` 79 Clone *PipelineClone `yaml:"clone,omitempty" json:"clone,omitempty"` 80 Steps []PipelineStep `yaml:"steps,omitempty" json:"steps,omitempty"` 81 Services []PipelineService `yaml:"services,omitempty" json:"services,omitempty"` 82 Node map[string]string `yaml:"node,omitempty" json:"node,omitempty"` 83 } 84 85 func NewCIDronePipelineDocker() *CIDronePipelineDocker { 86 p := new(CIDronePipelineDocker) 87 p.CIDronePipeline = *NewCIDronePipeline() 88 p.WithType(enums.DRONE_CI_TYPE__docker) 89 return p 90 } 91 92 // Deprecated 93 func (c *CIDronePipelineDocker) WriteToFile() { 94 bytes, err := yaml.Marshal(c) 95 if err != nil { 96 panic(err) 97 } 98 ioutil.WriteFile(".drone.yml", bytes, os.ModePerm) 99 } 100 101 func (c *CIDronePipelineDocker) String() string { 102 bytes, err := yaml.Marshal(c) 103 if err != nil { 104 panic(err) 105 } 106 107 return string(bytes) 108 }