github.com/profzone/eden-framework@v1.0.10/internal/project/drone/step.go (about)

     1  package drone
     2  
     3  import (
     4  	"github.com/imdario/mergo"
     5  	"github.com/profzone/eden-framework/internal/project/drone/enums"
     6  )
     7  
     8  type PipelineStep struct {
     9  	Name        string                   `yaml:"name" json:"name"`
    10  	Image       string                   `yaml:"image" json:"image"`
    11  	Pull        enums.DroneCiStepPull    `yaml:"pull,omitempty" json:"pull,omitempty"`
    12  	Commands    []string                 `yaml:"commands,omitempty" json:"commands,omitempty"`
    13  	Environment map[string]string        `yaml:"environment,omitempty" json:"environment,omitempty"`
    14  	Settings    map[string]interface{}   `yaml:"settings,omitempty" json:"settings,omitempty"`
    15  	When        *PipelineTrigger         `yaml:"when,omitempty" json:"when,omitempty"`
    16  	Failure     enums.DroneCiStepFailure `yaml:"failure,omitempty" json:"failure,omitempty"`
    17  	Detach      bool                     `yaml:"detach,omitempty" json:"detach,omitempty"`
    18  	Privileged  bool                     `yaml:"privileged,omitempty" json:"privileged,omitempty"`
    19  	DependsOn   []string                 `yaml:"depends_on,omitempty" json:"depends_on,omitempty"`
    20  	Volumes     []PipelineStepVolume     `yaml:"volumes,omitempty" json:"volumes,omitempty"`
    21  }
    22  
    23  func NewPipelineStep() *PipelineStep {
    24  	return new(PipelineStep)
    25  }
    26  
    27  func (s *PipelineStep) WithName(n string) *PipelineStep {
    28  	s.Name = n
    29  	return s
    30  }
    31  
    32  func (s *PipelineStep) WithImage(img string) *PipelineStep {
    33  	s.Image = img
    34  	return s
    35  }
    36  
    37  func (s *PipelineStep) WithCommands(cmd ...string) *PipelineStep {
    38  	s.Commands = append(s.Commands, cmd...)
    39  	return s
    40  }
    41  
    42  func (s *PipelineStep) WithEnvs(envs map[string]string) *PipelineStep {
    43  	_ = mergo.Merge(&s.Environment, envs)
    44  	return s
    45  }
    46  
    47  func (s *PipelineStep) WithEnv(key string, value string) *PipelineStep {
    48  	s.Environment[key] = value
    49  	return s
    50  }
    51  
    52  func (s *PipelineStep) WithSetting(key string, value interface{}) *PipelineStep {
    53  	s.Settings[key] = value
    54  	return s
    55  }
    56  
    57  func (s *PipelineStep) WithFailureIgnore() *PipelineStep {
    58  	s.Failure = enums.DRONE_CI_STEP_FAILURE__ignore
    59  	return s
    60  }
    61  
    62  func (s *PipelineStep) WithFailureNotIgnore() *PipelineStep {
    63  	s.Failure = enums.DRONE_CI_STEP_FAILURE_UNKNOWN
    64  	return s
    65  }
    66  
    67  func (s *PipelineStep) WithDetach() *PipelineStep {
    68  	s.Detach = true
    69  	return s
    70  }
    71  
    72  func (s *PipelineStep) WithNoDetach() *PipelineStep {
    73  	s.Detach = false
    74  	return s
    75  }
    76  
    77  func (s *PipelineStep) WithPrivileged() *PipelineStep {
    78  	s.Privileged = true
    79  	return s
    80  }
    81  
    82  func (s *PipelineStep) WithNoPrivileged() *PipelineStep {
    83  	s.Privileged = false
    84  	return s
    85  }
    86  
    87  func (s *PipelineStep) WithBranchInclude(name string) *PipelineStep {
    88  	if s.When == nil {
    89  		s.When = NewPipelineTrigger()
    90  	}
    91  	s.When.WithBranchInclude(name)
    92  	return s
    93  }
    94  
    95  func (s *PipelineStep) WithBranchExclude(name string) *PipelineStep {
    96  	if s.When == nil {
    97  		s.When = NewPipelineTrigger()
    98  	}
    99  	s.When.WithBranchExclude(name)
   100  	return s
   101  }
   102  
   103  func (s *PipelineStep) WithEventInclude(evt enums.DroneCiTriggerEvent) *PipelineStep {
   104  	if s.When == nil {
   105  		s.When = NewPipelineTrigger()
   106  	}
   107  	s.When.WithEventInclude(evt)
   108  	return s
   109  }
   110  
   111  func (s *PipelineStep) WithEventExclude(evt enums.DroneCiTriggerEvent) *PipelineStep {
   112  	if s.When == nil {
   113  		s.When = NewPipelineTrigger()
   114  	}
   115  	s.When.WithEventExclude(evt)
   116  	return s
   117  }
   118  
   119  func (s *PipelineStep) WithRefInclude(name string) *PipelineStep {
   120  	if s.When == nil {
   121  		s.When = NewPipelineTrigger()
   122  	}
   123  	s.When.WithRefInclude(name)
   124  	return s
   125  }
   126  
   127  func (s *PipelineStep) WithRefExclude(name string) *PipelineStep {
   128  	if s.When == nil {
   129  		s.When = NewPipelineTrigger()
   130  	}
   131  	s.When.WithRefExclude(name)
   132  	return s
   133  }
   134  
   135  func (s *PipelineStep) WithRepoInclude(name string) *PipelineStep {
   136  	if s.When == nil {
   137  		s.When = NewPipelineTrigger()
   138  	}
   139  	s.When.WithRepoInclude(name)
   140  	return s
   141  }
   142  
   143  func (s *PipelineStep) WithRepoExclude(name string) *PipelineStep {
   144  	if s.When == nil {
   145  		s.When = NewPipelineTrigger()
   146  	}
   147  	s.When.WithRepoExclude(name)
   148  	return s
   149  }
   150  
   151  func (s *PipelineStep) WithStatus(status enums.DroneCiTriggerStatus) *PipelineStep {
   152  	if s.When == nil {
   153  		s.When = NewPipelineTrigger()
   154  	}
   155  	s.When.WithStatus(status)
   156  	return s
   157  }
   158  
   159  func (s *PipelineStep) WithTargetInclude(name string) *PipelineStep {
   160  	if s.When == nil {
   161  		s.When = NewPipelineTrigger()
   162  	}
   163  	s.When.WithTargetInclude(name)
   164  	return s
   165  }
   166  
   167  func (s *PipelineStep) WithTargetExclude(name string) *PipelineStep {
   168  	if s.When == nil {
   169  		s.When = NewPipelineTrigger()
   170  	}
   171  	s.When.WithTargetExclude(name)
   172  	return s
   173  }
   174  
   175  func (s *PipelineStep) WithDependsOn(deps ...string) *PipelineStep {
   176  	s.DependsOn = append(s.DependsOn, deps...)
   177  	return s
   178  }
   179  
   180  func (s *PipelineStep) WithVolume(volume ...PipelineStepVolume) *PipelineStep {
   181  	s.Volumes = append(s.Volumes, volume...)
   182  	return s
   183  }