mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-29 04:30:07 +08:00
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">
This commit is contained in:
parent
ffa4949eaa
commit
9c0a3532a4
|
@ -35,6 +35,7 @@ type ActionRun struct {
|
||||||
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
|
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
|
||||||
TriggerUserID int64 `xorm:"index"`
|
TriggerUserID int64 `xorm:"index"`
|
||||||
TriggerUser *user_model.User `xorm:"-"`
|
TriggerUser *user_model.User `xorm:"-"`
|
||||||
|
ScheduleID int64
|
||||||
Ref string `xorm:"index"` // the commit/tag/… that caused the run
|
Ref string `xorm:"index"` // the commit/tag/… that caused the run
|
||||||
CommitSHA string
|
CommitSHA string
|
||||||
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.
|
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.
|
||||||
|
|
|
@ -530,6 +530,8 @@ var migrations = []Migration{
|
||||||
NewMigration("Add Action Schedule Table", v1_21.AddActionScheduleTable),
|
NewMigration("Add Action Schedule Table", v1_21.AddActionScheduleTable),
|
||||||
// v274 -> v275
|
// v274 -> v275
|
||||||
NewMigration("Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable),
|
NewMigration("Add Actions artifacts expiration date", v1_21.AddExpiredUnixColumnInActionArtifactTable),
|
||||||
|
// v275 -> v276
|
||||||
|
NewMigration("Add ScheduleID for ActionRun", v1_21.AddScheduleIDForActionRun),
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentDBVersion returns the current db version
|
// GetCurrentDBVersion returns the current db version
|
||||||
|
|
15
models/migrations/v1_21/v275.go
Normal file
15
models/migrations/v1_21/v275.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package v1_21 //nolint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AddScheduleIDForActionRun(x *xorm.Engine) error {
|
||||||
|
type ActionRun struct {
|
||||||
|
ScheduleID int64
|
||||||
|
}
|
||||||
|
return x.Sync(new(ActionRun))
|
||||||
|
}
|
|
@ -3504,6 +3504,7 @@ runners.reset_registration_token_success = Runner registration token reset succe
|
||||||
|
|
||||||
runs.all_workflows = All Workflows
|
runs.all_workflows = All Workflows
|
||||||
runs.commit = Commit
|
runs.commit = Commit
|
||||||
|
runs.scheduled = Scheduled
|
||||||
runs.pushed_by = pushed by
|
runs.pushed_by = pushed by
|
||||||
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
|
runs.invalid_workflow_helper = Workflow config file is invalid. Please check your config file: %s
|
||||||
runs.no_matching_runner_helper = No matching runner: %s
|
runs.no_matching_runner_helper = No matching runner: %s
|
||||||
|
|
|
@ -202,8 +202,14 @@ func (s *Service) UpdateTask(
|
||||||
if err := task.LoadJob(ctx); err != nil {
|
if err := task.LoadJob(ctx); err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "load job: %v", err)
|
return nil, status.Errorf(codes.Internal, "load job: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := task.Job.LoadRun(ctx); err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "load run: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't create commit status for cron job
|
||||||
|
if task.Job.Run.ScheduleID == 0 {
|
||||||
actions_service.CreateCommitStatus(ctx, task.Job)
|
actions_service.CreateCommitStatus(ctx, task.Job)
|
||||||
|
}
|
||||||
|
|
||||||
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
|
if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED {
|
||||||
if err := actions_service.EmitJobsIfReady(task.Job.RunID); err != nil {
|
if err := actions_service.EmitJobsIfReady(task.Job.RunID); err != nil {
|
||||||
|
|
|
@ -113,6 +113,7 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
|
||||||
CommitSHA: cron.CommitSHA,
|
CommitSHA: cron.CommitSHA,
|
||||||
Event: cron.Event,
|
Event: cron.Event,
|
||||||
EventPayload: cron.EventPayload,
|
EventPayload: cron.EventPayload,
|
||||||
|
ScheduleID: cron.ID,
|
||||||
Status: actions_model.StatusWaiting,
|
Status: actions_model.StatusWaiting,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,19 +128,6 @@ func CreateScheduleTask(ctx context.Context, cron *actions_model.ActionSchedule)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the jobs for the newly created action run
|
|
||||||
jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{RunID: run.ID})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create commit statuses for each job
|
|
||||||
for _, job := range jobs {
|
|
||||||
if err := createCommitStatus(ctx, job); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return nil if no errors occurred
|
// Return nil if no errors occurred
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,15 @@
|
||||||
{{- .Title -}}
|
{{- .Title -}}
|
||||||
</a>
|
</a>
|
||||||
<div class="flex-item-body">
|
<div class="flex-item-body">
|
||||||
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>
|
<b>{{if not $.CurWorkflow}}{{.WorkflowID}} {{end}}#{{.Index}}</b>:
|
||||||
: {{$.locale.Tr "actions.runs.commit"}}
|
{{- if .ScheduleID -}}
|
||||||
|
{{$.locale.Tr "actions.runs.scheduled"}}
|
||||||
|
{{- else -}}
|
||||||
|
{{$.locale.Tr "actions.runs.commit"}}
|
||||||
<a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{ShortSha .CommitSHA}}</a>
|
<a href="{{$.RepoLink}}/commit/{{.CommitSHA}}">{{ShortSha .CommitSHA}}</a>
|
||||||
{{$.locale.Tr "actions.runs.pushed_by"}}
|
{{$.locale.Tr "actions.runs.pushed_by"}}
|
||||||
<a href="{{.TriggerUser.HomeLink}}">{{.TriggerUser.GetDisplayName}}</a>
|
<a href="{{.TriggerUser.HomeLink}}">{{.TriggerUser.GetDisplayName}}</a>
|
||||||
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-item-trailing">
|
<div class="flex-item-trailing">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user