skip step if state not pending

pull/5/head
Brad Rydzewski 4 years ago
parent df774e029a
commit 9f0ba71ae2

@ -187,9 +187,13 @@ func (e *Execer) exec(ctx context.Context, state *pipeline.State, spec Spec, ste
}
switch {
case state.Skipped():
case state.Finished(step.GetName()):
// skip if the step if already in a finished state,
// for example, if the step is marked as skipped.
return nil
case state.Cancelled():
// skip if the pipeline was cancelled, either by the
// end user or due to timeout.
return nil
case step.GetRunPolicy() == RunNever:
return nil

@ -73,7 +73,7 @@ func (s *State) Skip(name string) {
s.Unlock()
}
// SkipAll skips all pipeilne steps.
// SkipAll skips all pipeline steps.
func (s *State) SkipAll() {
s.Lock()
s.skipall()
@ -81,14 +81,6 @@ func (s *State) SkipAll() {
s.Unlock()
}
// Skipped returns true if all pipeline steps are skipped.
func (s *State) Skipped() bool {
s.Lock()
v := s.skipped()
s.Unlock()
return v
}
// Start sets the named pipeline step to started.
func (s *State) Start(name string) {
s.Lock()
@ -114,6 +106,15 @@ func (s *State) FinishAll() {
s.Unlock()
}
// Finished returns true if the step is finished.
func (s *State) Finished(name string) bool {
s.Lock()
v := s.find(name)
d := s.finished(v)
s.Unlock()
return d
}
// Find returns the named pipeline step.
func (s *State) Find(name string) *drone.Step {
s.Lock()
@ -145,20 +146,6 @@ func (s *State) skip(v *drone.Step) {
}
}
// helper function returns true if the overall pipeline is
// finished and remaining steps skipped.
func (s *State) skipped() bool {
if s.finished() == false {
return false
}
for _, v := range s.Stage.Steps {
if v.Status == drone.StatusSkipped {
return true
}
}
return false
}
// helper function kills all pipeline steps.
func (s *State) killall() {
s.Stage.Error = ""
@ -226,16 +213,14 @@ func (s *State) finish(v *drone.Step, code int) {
}
}
// helper function returns true if the overall pipeline status
// is failing.
func (s *State) finished() bool {
for _, v := range s.Stage.Steps {
switch v.Status {
case drone.StatusRunning, drone.StatusPending:
return false
}
// helper function returns true if the step is finished.
func (s *State) finished(v *drone.Step) bool {
switch v.Status {
case drone.StatusRunning, drone.StatusPending:
return false
default:
return true
}
return true
}
// helper function finishes all pipeline steps.

@ -56,47 +56,27 @@ func TestStateKilled(t *testing.T) {
}
func TestStateFinished(t *testing.T) {
step := &drone.Step{}
step := &drone.Step{Name: "test"}
state := &State{
Stage: &drone.Stage{
Steps: []*drone.Step{step},
},
}
step.Status = drone.StatusRunning
if state.finished() == true {
if state.Finished(step.Name) == true {
t.Errorf("Expect finished false")
}
step.Status = drone.StatusPending
if state.finished() == true {
if state.Finished(step.Name) == true {
t.Errorf("Expect finished false")
}
step.Status = drone.StatusKilled
if state.finished() == false {
if state.Finished(step.Name) == false {
t.Errorf("Expect finished true")
}
}
func TestStateSkipped(t *testing.T) {
state := &State{
Stage: &drone.Stage{
Steps: []*drone.Step{
{Status: drone.StatusPassing},
{Status: drone.StatusRunning},
},
},
}
if state.skipped() == true {
t.Errorf("Expect skipped false")
}
state.Stage.Steps[1].Status = drone.StatusPassing
if state.skipped() == true {
t.Errorf("Expect skipped false")
}
state.Stage.Steps[1].Status = drone.StatusSkipped
if state.skipped() == false {
t.Errorf("Expect skipped true")
step.Status = drone.StatusSkipped
if state.Finished(step.Name) == false {
t.Errorf("Expect finished true")
}
}

Loading…
Cancel
Save