Skip to content

Commit 35cfd98

Browse files
authored
Show Actions post step when it's running (#29926)
The post step was always waiting, even if all steps were done. Then, once the task was done, the post step became success immediately. Before: <img width="915" alt="xnip_240320_120228" src="https://github.com/go-gitea/gitea/assets/9418365/00347430-f998-4c43-917a-bf6dd6d0e333"> After: <img width="905" alt="xnip_240320_120443" src="https://github.com/go-gitea/gitea/assets/9418365/a419b111-17c2-4029-a022-c761cc419091">
1 parent 02bbdd4 commit 35cfd98

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

modules/actions/task_state.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep {
4141
}
4242
logIndex += preStep.LogLength
4343

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.
4450
var lastHasRunStep *actions_model.ActionTaskStep
4551
for _, step := range task.Steps {
4652
if step.Status.HasRun() {
@@ -56,11 +62,15 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep {
5662
Name: postStepName,
5763
Status: actions_model.StatusWaiting,
5864
}
59-
if task.Status.IsDone() {
65+
// If the lastHasRunStep is the last step, or it has failed, postStep has started.
66+
if lastHasRunStep.Status.IsFailure() || lastHasRunStep == task.Steps[len(task.Steps)-1] {
6067
postStep.LogIndex = logIndex
6168
postStep.LogLength = task.LogLength - postStep.LogIndex
62-
postStep.Status = task.Status
6369
postStep.Started = lastHasRunStep.Stopped
70+
postStep.Status = actions_model.StatusRunning
71+
}
72+
if task.Status.IsDone() {
73+
postStep.Status = task.Status
6474
postStep.Stopped = task.Stopped
6575
}
6676
ret := make([]*actions_model.ActionTaskStep, 0, len(task.Steps)+2)

modules/actions/task_state_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,40 @@ func TestFullSteps(t *testing.T) {
103103
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 100, LogLength: 0, Started: 10100, Stopped: 10100},
104104
},
105105
},
106+
{
107+
name: "all steps finished but task is running",
108+
task: &actions_model.ActionTask{
109+
Steps: []*actions_model.ActionTaskStep{
110+
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
111+
},
112+
Status: actions_model.StatusRunning,
113+
Started: 10000,
114+
Stopped: 0,
115+
LogLength: 100,
116+
},
117+
want: []*actions_model.ActionTaskStep{
118+
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
119+
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
120+
{Name: postStepName, Status: actions_model.StatusRunning, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 0},
121+
},
122+
},
123+
{
124+
name: "skipped task",
125+
task: &actions_model.ActionTask{
126+
Steps: []*actions_model.ActionTaskStep{
127+
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
128+
},
129+
Status: actions_model.StatusSkipped,
130+
Started: 0,
131+
Stopped: 0,
132+
LogLength: 0,
133+
},
134+
want: []*actions_model.ActionTaskStep{
135+
{Name: preStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
136+
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
137+
{Name: postStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
138+
},
139+
},
106140
}
107141
for _, tt := range tests {
108142
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)