@@ -18,8 +18,32 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep {
1818 return fullStepsOfEmptySteps (task )
1919 }
2020
21- firstStep := task .Steps [0 ]
21+ // firstStep is the first step that has run or running, not include preStep.
22+ // For example,
23+ // 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): firstStep is step1.
24+ // 2. preStep(Success) -> step1(Skipped) -> step2(Success) -> postStep(Success): firstStep is step2.
25+ // 3. preStep(Success) -> step1(Running) -> step2(Waiting) -> postStep(Waiting): firstStep is step1.
26+ // 4. preStep(Success) -> step1(Skipped) -> step2(Skipped) -> postStep(Skipped): firstStep is nil.
27+ // 5. preStep(Success) -> step1(Cancelled) -> step2(Cancelled) -> postStep(Cancelled): firstStep is nil.
28+ var firstStep * actions_model.ActionTaskStep
29+ // lastHasRunStep is the last step that has run.
30+ // For example,
31+ // 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): lastHasRunStep is step1.
32+ // 2. preStep(Success) -> step1(Success) -> step2(Success) -> step3(Success) -> postStep(Success): lastHasRunStep is step3.
33+ // 3. preStep(Success) -> step1(Success) -> step2(Failure) -> step3 -> postStep(Waiting): lastHasRunStep is step2.
34+ // So its Stopped is the Started of postStep when there are no more steps to run.
35+ var lastHasRunStep * actions_model.ActionTaskStep
36+
2237 var logIndex int64
38+ for _ , step := range task .Steps {
39+ if firstStep == nil && (step .Status .HasRun () || step .Status .IsRunning ()) {
40+ firstStep = step
41+ }
42+ if step .Status .HasRun () {
43+ lastHasRunStep = step
44+ }
45+ logIndex += step .LogLength
46+ }
2347
2448 preStep := & actions_model.ActionTaskStep {
2549 Name : preStepName ,
@@ -28,32 +52,17 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep {
2852 Status : actions_model .StatusRunning ,
2953 }
3054
31- if firstStep .Status .HasRun () || firstStep .Status .IsRunning () {
55+ // No step has run or is running, so preStep is equal to the task
56+ if firstStep == nil {
57+ preStep .Stopped = task .Stopped
58+ preStep .Status = task .Status
59+ } else {
3260 preStep .LogLength = firstStep .LogIndex
3361 preStep .Stopped = firstStep .Started
3462 preStep .Status = actions_model .StatusSuccess
35- } else if task .Status .IsDone () {
36- preStep .Stopped = task .Stopped
37- preStep .Status = actions_model .StatusFailure
38- if task .Status .IsSkipped () {
39- preStep .Status = actions_model .StatusSkipped
40- }
4163 }
4264 logIndex += preStep .LogLength
4365
44- // lastHasRunStep is the last step that has run.
45- // For example,
46- // 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): lastHasRunStep is step1.
47- // 2. preStep(Success) -> step1(Success) -> step2(Success) -> step3(Success) -> postStep(Success): lastHasRunStep is step3.
48- // 3. preStep(Success) -> step1(Success) -> step2(Failure) -> step3 -> postStep(Waiting): lastHasRunStep is step2.
49- // So its Stopped is the Started of postStep when there are no more steps to run.
50- var lastHasRunStep * actions_model.ActionTaskStep
51- for _ , step := range task .Steps {
52- if step .Status .HasRun () {
53- lastHasRunStep = step
54- }
55- logIndex += step .LogLength
56- }
5766 if lastHasRunStep == nil {
5867 lastHasRunStep = preStep
5968 }
0 commit comments