Skip to content

Commit 9c0a353

Browse files
authored
Add a new column schedule_id for action_run to track (#26975)
Fix #26971 And the UI now will display it's scheduled but not triggered by a push. <img width="954" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/d211845c-457e-4c3e-af1f-a0d654d3f365">
1 parent ffa4949 commit 9c0a353

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

models/actions/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type ActionRun struct {
3535
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
3636
TriggerUserID int64 `xorm:"index"`
3737
TriggerUser *user_model.User `xorm:"-"`
38-
Ref string `xorm:"index"` // the commit/tag/… that caused the run
38+
ScheduleID int64
39+
Ref string `xorm:"index"` // the commit/tag/… that caused the run
3940
CommitSHA string
4041
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
4142
NeedApproval bool // may need approval if it's a fork pull request

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ var migrations = []Migration{
530530
NewMigration("Add Action Schedule Table", v1_21.AddActionScheduleTable),
531531
// v274 -> v275
532532
NewMigration("Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable),
533+
// v275 -> v276
534+
NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun),
533535
}
534536

535537
// GetCurrentDBVersion returns the current db version

models/migrations/v1_21/v275.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_21 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddScheduleIDForActionRun(x *xorm.Engine) error {
11+
type ActionRun struct {
12+
ScheduleID int64
13+
}
14+
return x.Sync(new(ActionRun))
15+
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,7 @@ runners.reset_registration_token_success = Runner registration token reset succe
35043504
35053505
runs.all_workflows = All Workflows
35063506
runs.commit = Commit
3507+
runs.scheduled = Scheduled
35073508
runs.pushed_by = pushed by
35083509
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
35093510
runs.no_matching_runner_helper = No matching runner: %s

routers/api/actions/runner/runner.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,14 @@ func (s *Service) UpdateTask(
202202
if err := task.LoadJob(ctx); err != nil {
203203
return nil, status.Errorf(codes.Internal, "load job: %v", err)
204204
}
205+
if err := task.Job.LoadRun(ctx); err != nil {
206+
return nil, status.Errorf(codes.Internal, "load run: %v", err)
207+
}
205208

206-
actions_service.CreateCommitStatus(ctx, task.Job)
209+
// don't create commit status for cron job
210+
if task.Job.Run.ScheduleID == 0 {
211+
actions_service.CreateCommitStatus(ctx, task.Job)
212+
}
207213

208214
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
209215
if err := actions_service.EmitJobsIfReady(task.Job.RunID); err != nil {

services/actions/schedule_tasks.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
113113
CommitSHA: cron.CommitSHA,
114114
Event: cron.Event,
115115
EventPayload: cron.EventPayload,
116+
ScheduleID: cron.ID,
116117
Status: actions_model.StatusWaiting,
117118
}
118119

@@ -127,19 +128,6 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
127128
return err
128129
}
129130

130-
// Retrieve the jobs for the newly created action run
131-
jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID})
132-
if err != nil {
133-
return err
134-
}
135-
136-
// Create commit statuses for each job
137-
for _, job := range jobs {
138-
if err := createCommitStatus(ctx, job); err != nil {
139-
return err
140-
}
141-
}
142-
143131
// Return nil if no errors occurred
144132
return nil
145133
}

templates/repo/actions/runs_list.tmpl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
{{- .Title -}}
1616
</a>
1717
<div class="flex-item-body">
18-
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>
19-
: {{$.locale.Tr "actions.runs.commit"}}
20-
<a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{ShortSha .CommitSHA}}</a>
21-
{{$.locale.Tr "actions.runs.pushed_by"}}
22-
<a href="{{.TriggerUser.HomeLink}}">{{.TriggerUser.GetDisplayName}}</a>
18+
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>:
19+
{{- if .ScheduleID -}}
20+
{{$.locale.Tr "actions.runs.scheduled"}}
21+
{{- else -}}
22+
{{$.locale.Tr "actions.runs.commit"}}
23+
<a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{ShortSha .CommitSHA}}</a>
24+
{{$.locale.Tr "actions.runs.pushed_by"}}
25+
<a href="{{.TriggerUser.HomeLink}}">{{.TriggerUser.GetDisplayName}}</a>
26+
{{- end -}}
2327
</div>
2428
</div>
2529
<div class="flex-item-trailing">

0 commit comments

Comments
 (0)