Skip to content

Commit e17c17d

Browse files
committed
fix
1 parent 763938e commit e17c17d

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

models/actions/run.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ type ActionRun struct {
4646
TriggerEvent string // the trigger event defined in the `on` configuration of the triggered workflow
4747
Status Status `xorm:"index"`
4848
Version int `xorm:"version default 0"` // Status could be updated concomitantly, so an optimistic lock is needed
49-
Started timeutil.TimeStamp
50-
Stopped timeutil.TimeStamp
51-
Created timeutil.TimeStamp `xorm:"created"`
52-
Updated timeutil.TimeStamp `xorm:"updated"`
49+
// Started and Stopped is used for recording last run time, if rerun happened, they will be reset to 0
50+
Started timeutil.TimeStamp
51+
Stopped timeutil.TimeStamp
52+
// TotalDuration is used for recording the total duration of the workflow
53+
TotalDuration time.Duration
54+
Created timeutil.TimeStamp `xorm:"created"`
55+
Updated timeutil.TimeStamp `xorm:"updated"`
5356
}
5457

5558
func init() {
@@ -121,6 +124,18 @@ func (run *ActionRun) Duration() time.Duration {
121124
return calculateDuration(run.Started, run.Stopped, run.Status)
122125
}
123126

127+
func (run *ActionRun) DisplayDuration() time.Duration {
128+
duration := calculateDuration(run.Started, run.Stopped, run.Status)
129+
if run.Status.IsDone() {
130+
// there was a bug when record stopped time, see https://github.com/go-gitea/gitea/issues/28323#issuecomment-1841867298
131+
// and duration will be negitive because of the incorrect stopped time in db
132+
// there's no way to fix them now, so in order to avoid displaying incorrect duration time,
133+
// we will display 0 instead of negitive time
134+
return slices.Max([]time.Duration{run.TotalDuration, duration})
135+
}
136+
return duration
137+
}
138+
124139
func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) {
125140
if run.Event == webhook_module.HookEventPush {
126141
var payload api.PushPayload

models/actions/run_job.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
143143
}
144144
if run.Stopped.IsZero() && run.Status.IsDone() {
145145
run.Stopped = timeutil.TimeStampNow()
146+
run.TotalDuration += run.Duration()
146147
}
147-
if err := UpdateRun(ctx, run, "status", "started", "stopped"); err != nil {
148+
if err := UpdateRun(ctx, run, "status", "started", "stopped", "total_duration"); err != nil {
148149
return 0, fmt.Errorf("update run %d: %w", run.ID, err)
149150
}
150151
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,7 @@ runs.no_workflows.quick_start = Don't know how to start with Gitea Action? See <
35343534
runs.no_workflows.documentation = For more information on the Gitea Action, see <a target="_blank" rel="noopener noreferrer" href="%s">the documentation</a>.
35353535
runs.no_runs = The workflow has no runs yet.
35363536
runs.empty_commit_message = (empty commit message)
3537+
runs.last_run_time = Last run: %s
35373538
35383539
workflow.disable = Disable Workflow
35393540
workflow.disable_success = Workflow '%s' disabled successfully.

routers/web/repo/actions/view.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ func Rerun(ctx *context_module.Context) {
279279
return
280280
}
281281

282+
// reset run's start and stop time
283+
run.Started = 0
284+
run.Stopped = 0
285+
if err := actions_model.UpdateRun(ctx, run, "started", "stopped"); err != nil {
286+
ctx.Error(http.StatusInternalServerError, err.Error())
287+
return
288+
}
289+
282290
job, jobs := getRunJobs(ctx, runIndex, jobIndex)
283291
if ctx.Written() {
284292
return

templates/repo/actions/runs_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
<div class="run-list-item-right">
3737
<div class="run-list-meta">{{svg "octicon-calendar" 16}}{{TimeSinceUnix .Updated ctx.Locale}}</div>
38-
<div class="run-list-meta">{{svg "octicon-stopwatch" 16}}{{.Duration}}</div>
38+
<div class="run-list-meta" data-tooltip-placement="top" data-tooltip-content="{{ctx.Locale.Tr "actions.runs.last_run_time" .Duration}}">{{svg "octicon-stopwatch" 16}}{{.DisplayDuration}}</div>
3939
</div>
4040
</div>
4141
{{end}}

0 commit comments

Comments
 (0)