mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-07 20:25:21 +02:00
feat: inner build view UI
This commit is contained in:
parent
d6e100f6be
commit
dee4f2470b
@ -84,11 +84,15 @@ func (run *Run) LoadAttributes(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (run *Run) TakeTime() time.Duration {
|
||||
if run.Started == 0 {
|
||||
return 0
|
||||
}
|
||||
started := run.Started.AsTime()
|
||||
if run.Status.IsDone() {
|
||||
return run.Stopped.AsTime().Sub(started)
|
||||
}
|
||||
return time.Since(started)
|
||||
run.Stopped.AsTime().Sub(started)
|
||||
return time.Since(started).Truncate(time.Second)
|
||||
}
|
||||
|
||||
func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
|
||||
|
@ -259,6 +259,14 @@ func CreateTaskForRunner(runner *Runner) (*Task, bool, error) {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if job.Run.Status.IsWaiting() {
|
||||
job.Run.Status = StatusRunning
|
||||
job.Run.Started = now
|
||||
if err := UpdateRun(ctx, job.Run, "status", "started"); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
task.Job = job
|
||||
|
||||
if err := commiter.Commit(); err != nil {
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/nektos/act/pkg/jobparser"
|
||||
)
|
||||
@ -95,7 +94,6 @@ func notify(repo *repo_model.Repository, doer *user_model.User, payload, ref str
|
||||
Event: evt,
|
||||
EventPayload: payload,
|
||||
Status: bots_model.StatusWaiting,
|
||||
Started: timeutil.TimeStampNow(),
|
||||
}
|
||||
if len(run.Title) > 255 {
|
||||
run.Title = run.Title[:255]
|
||||
|
@ -1,4 +1,4 @@
|
||||
package dev
|
||||
package builds
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -12,14 +12,23 @@ import (
|
||||
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
||||
)
|
||||
|
||||
func BuildView(ctx *context.Context) {
|
||||
ctx.Data["RunIndex"] = ctx.ParamsInt64("run")
|
||||
ctx.Data["JobIndex"] = ctx.ParamsInt64("job")
|
||||
func View(ctx *context.Context) {
|
||||
runIndex := ctx.ParamsInt64("run")
|
||||
jobIndex := ctx.ParamsInt64("job")
|
||||
ctx.Data["RunIndex"] = runIndex
|
||||
ctx.Data["JobIndex"] = jobIndex
|
||||
|
||||
ctx.HTML(http.StatusOK, "dev/buildview")
|
||||
job, _ := getRunJobs(ctx, runIndex, jobIndex)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
run := job.Run
|
||||
ctx.Data["Build"] = run
|
||||
|
||||
ctx.HTML(http.StatusOK, tplViewBuild)
|
||||
}
|
||||
|
||||
type BuildViewRequest struct {
|
||||
type ViewRequest struct {
|
||||
StepLogCursors []struct {
|
||||
StepIndex int `json:"stepIndex"`
|
||||
Cursor int64 `json:"cursor"`
|
||||
@ -27,130 +36,112 @@ type BuildViewRequest struct {
|
||||
} `json:"stepLogCursors"`
|
||||
}
|
||||
|
||||
type BuildViewResponse struct {
|
||||
type ViewResponse struct {
|
||||
StateData struct {
|
||||
BuildInfo struct {
|
||||
HTMLURL string `json:"htmlurl"`
|
||||
Title string `json:"title"`
|
||||
} `json:"buildInfo"`
|
||||
AllJobGroups []BuildViewGroup `json:"allJobGroups"`
|
||||
AllJobGroups []ViewGroup `json:"allJobGroups"`
|
||||
CurrentJobInfo struct {
|
||||
Title string `json:"title"`
|
||||
Detail string `json:"detail"`
|
||||
} `json:"currentJobInfo"`
|
||||
CurrentJobSteps []BuildViewJobStep `json:"currentJobSteps"`
|
||||
CurrentJobSteps []ViewJobStep `json:"currentJobSteps"`
|
||||
} `json:"stateData"`
|
||||
LogsData struct {
|
||||
StreamingLogs []BuildViewStepLog `json:"streamingLogs"`
|
||||
StreamingLogs []ViewStepLog `json:"streamingLogs"`
|
||||
} `json:"logsData"`
|
||||
}
|
||||
|
||||
type BuildViewGroup struct {
|
||||
Summary string `json:"summary"`
|
||||
Jobs []*BuildViewJob `json:"jobs"`
|
||||
type ViewGroup struct {
|
||||
Summary string `json:"summary"`
|
||||
Jobs []*ViewJob `json:"jobs"`
|
||||
}
|
||||
|
||||
type BuildViewJob struct {
|
||||
type ViewJob struct {
|
||||
Id int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type BuildViewJobStep struct {
|
||||
type ViewJobStep struct {
|
||||
Summary string `json:"summary"`
|
||||
Duration float64 `json:"duration"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type BuildViewStepLog struct {
|
||||
StepIndex int `json:"stepIndex"`
|
||||
Cursor int64 `json:"cursor"`
|
||||
Lines []BuildViewStepLogLine `json:"lines"`
|
||||
type ViewStepLog struct {
|
||||
StepIndex int `json:"stepIndex"`
|
||||
Cursor int64 `json:"cursor"`
|
||||
Lines []ViewStepLogLine `json:"lines"`
|
||||
}
|
||||
|
||||
type BuildViewStepLogLine struct {
|
||||
type ViewStepLogLine struct {
|
||||
Ln int64 `json:"ln"`
|
||||
M string `json:"m"`
|
||||
T float64 `json:"t"`
|
||||
}
|
||||
|
||||
func BuildViewPost(ctx *context.Context) {
|
||||
req := web.GetForm(ctx).(*BuildViewRequest)
|
||||
func ViewPost(ctx *context.Context) {
|
||||
req := web.GetForm(ctx).(*ViewRequest)
|
||||
runIndex := ctx.ParamsInt64("run")
|
||||
jobIndex := ctx.ParamsInt64("job")
|
||||
|
||||
run, err := bots_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
|
||||
if err != nil {
|
||||
if _, ok := err.(bots_model.ErrRunNotExist); ok {
|
||||
ctx.Error(http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
current, jobs := getRunJobs(ctx, runIndex, jobIndex)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
run.Repo = ctx.Repo.Repository
|
||||
run := current.Run
|
||||
|
||||
jobs, err := bots_model.GetRunJobsByRunID(ctx, run.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if jobIndex < 0 || jobIndex >= int64(len(jobs)) {
|
||||
if len(jobs) == 0 {
|
||||
ctx.Error(http.StatusNotFound, fmt.Sprintf("run %v has no job %v", runIndex, jobIndex))
|
||||
return
|
||||
}
|
||||
}
|
||||
job := jobs[jobIndex]
|
||||
|
||||
resp := &BuildViewResponse{}
|
||||
resp := &ViewResponse{}
|
||||
resp.StateData.BuildInfo.Title = run.Title
|
||||
resp.StateData.BuildInfo.HTMLURL = run.HTMLURL()
|
||||
|
||||
respJobs := make([]*BuildViewJob, len(jobs))
|
||||
respJobs := make([]*ViewJob, len(jobs))
|
||||
for i, v := range jobs {
|
||||
respJobs[i] = &BuildViewJob{
|
||||
respJobs[i] = &ViewJob{
|
||||
Id: v.ID,
|
||||
Name: v.Name,
|
||||
Status: v.Status.String(),
|
||||
}
|
||||
}
|
||||
|
||||
resp.StateData.AllJobGroups = []BuildViewGroup{
|
||||
resp.StateData.AllJobGroups = []ViewGroup{
|
||||
{
|
||||
Summary: "Only One Group", // TODO: maybe we don't need job group
|
||||
Jobs: respJobs,
|
||||
},
|
||||
}
|
||||
|
||||
if job != nil {
|
||||
if current != nil {
|
||||
var task *bots_model.Task
|
||||
if job.TaskID > 0 {
|
||||
task, err = bots_model.GetTaskByID(ctx, job.TaskID)
|
||||
if current.TaskID > 0 {
|
||||
var err error
|
||||
task, err = bots_model.GetTaskByID(ctx, current.TaskID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
task.Job = job
|
||||
task.Job = current
|
||||
if err := task.LoadAttributes(ctx); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
resp.StateData.CurrentJobInfo.Title = job.Name
|
||||
resp.LogsData.StreamingLogs = make([]BuildViewStepLog, 0, len(req.StepLogCursors))
|
||||
if job.TaskID == 0 {
|
||||
resp.StateData.CurrentJobInfo.Title = current.Name
|
||||
resp.LogsData.StreamingLogs = make([]ViewStepLog, 0, len(req.StepLogCursors))
|
||||
if current.TaskID == 0 {
|
||||
resp.StateData.CurrentJobInfo.Detail = "wait to be pick up by a runner"
|
||||
} else {
|
||||
resp.StateData.CurrentJobInfo.Detail = "TODO: more detail info" // TODO: more detail info
|
||||
|
||||
steps := task.FullSteps()
|
||||
|
||||
resp.StateData.CurrentJobSteps = make([]BuildViewJobStep, len(steps))
|
||||
resp.StateData.CurrentJobSteps = make([]ViewJobStep, len(steps))
|
||||
for i, v := range steps {
|
||||
resp.StateData.CurrentJobSteps[i] = BuildViewJobStep{
|
||||
resp.StateData.CurrentJobSteps[i] = ViewJobStep{
|
||||
Summary: v.Name,
|
||||
Duration: float64(v.Stopped - v.Started),
|
||||
Status: v.Status.String(),
|
||||
@ -165,21 +156,22 @@ func BuildViewPost(ctx *context.Context) {
|
||||
index := step.LogIndex + cursor.Cursor
|
||||
length := step.LogLength - cursor.Cursor
|
||||
offset := (*task.LogIndexes)[index]
|
||||
var err error
|
||||
logRows, err = bots.ReadLogs(ctx, task.LogInStorage, task.LogFilename, offset, length)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
logLines := make([]BuildViewStepLogLine, len(logRows))
|
||||
logLines := make([]ViewStepLogLine, len(logRows))
|
||||
for i, row := range logRows {
|
||||
logLines[i] = BuildViewStepLogLine{
|
||||
logLines[i] = ViewStepLogLine{
|
||||
Ln: cursor.Cursor + int64(i),
|
||||
M: row.Content,
|
||||
T: float64(row.Time.AsTime().UnixNano()) / float64(time.Second),
|
||||
}
|
||||
}
|
||||
resp.LogsData.StreamingLogs = append(resp.LogsData.StreamingLogs, BuildViewStepLog{
|
||||
resp.LogsData.StreamingLogs = append(resp.LogsData.StreamingLogs, ViewStepLog{
|
||||
StepIndex: cursor.StepIndex,
|
||||
Cursor: cursor.Cursor + int64(len(logLines)),
|
||||
Lines: logLines,
|
||||
@ -191,3 +183,34 @@ func BuildViewPost(ctx *context.Context) {
|
||||
|
||||
ctx.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func getRunJobs(ctx *context.Context, runIndex, jobIndex int64) (current *bots_model.RunJob, jobs []*bots_model.RunJob) {
|
||||
run, err := bots_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
|
||||
if err != nil {
|
||||
if _, ok := err.(bots_model.ErrRunNotExist); ok {
|
||||
ctx.Error(http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
run.Repo = ctx.Repo.Repository
|
||||
|
||||
jobs, err = bots_model.GetRunJobsByRunID(ctx, run.ID)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, err.Error())
|
||||
return nil, nil
|
||||
}
|
||||
for _, v := range jobs {
|
||||
v.Run = run
|
||||
}
|
||||
|
||||
if jobIndex < 0 || jobIndex >= int64(len(jobs)) {
|
||||
if len(jobs) == 0 {
|
||||
ctx.Error(http.StatusNotFound, fmt.Sprintf("run %v has no job %v", runIndex, jobIndex))
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
current = jobs[jobIndex]
|
||||
return
|
||||
}
|
@ -661,12 +661,6 @@ func RegisterRoutes(m *web.Route) {
|
||||
|
||||
if !setting.IsProd {
|
||||
m.Any("/dev/termdemo", dev.TermDemo)
|
||||
m.Combo("/dev/buildview/runs/{runid}").
|
||||
Get(dev.BuildView).
|
||||
Post(bindIgnErr(dev.BuildViewRequest{}), dev.BuildViewPost)
|
||||
m.Combo("/dev/buildview/runs/{runid}/jobs/{jobid}").
|
||||
Get(dev.BuildView).
|
||||
Post(bindIgnErr(dev.BuildViewRequest{}), dev.BuildViewPost)
|
||||
}
|
||||
|
||||
reqRepoAdmin := context.RequireRepoAdmin()
|
||||
@ -1203,11 +1197,11 @@ func RegisterRoutes(m *web.Route) {
|
||||
|
||||
m.Group("/runs/{run}", func() {
|
||||
m.Combo("").
|
||||
Get(dev.BuildView).
|
||||
Post(bindIgnErr(dev.BuildViewRequest{}), dev.BuildViewPost)
|
||||
Get(builds.View).
|
||||
Post(bindIgnErr(builds.ViewRequest{}), builds.ViewPost)
|
||||
m.Combo("/jobs/{job}").
|
||||
Get(dev.BuildView).
|
||||
Post(bindIgnErr(dev.BuildViewRequest{}), dev.BuildViewPost)
|
||||
Get(builds.View).
|
||||
Post(bindIgnErr(builds.ViewRequest{}), builds.ViewPost)
|
||||
})
|
||||
}, reqRepoBuildsReader, builds.MustEnableBuilds)
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
{{template "base/head" .}}
|
||||
|
||||
<div id="repo-build-view" run-index="{{.RunIndex}}" job-index="{{.JobIndex}}" class="h-100">
|
||||
|
||||
</div>
|
||||
|
||||
{{template "base/footer" .}}
|
@ -10,8 +10,8 @@
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
{{template "repo/builds/view_left" .}}
|
||||
{{template "repo/builds/view_content" .}}
|
||||
</div>
|
||||
<div id="repo-build-view" run-index="{{.RunIndex}}" job-index="{{.JobIndex}}" class="h-100">
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
||||
|
@ -1,22 +0,0 @@
|
||||
<div class="ui stackable grid" id="build_log">
|
||||
<div class="console_wrapper__3ow2p" style="height: 206px;">
|
||||
<header class="console_header__4K9_D">
|
||||
<div class="console_header-inner__29khj">
|
||||
<div class="console_info__1NL_l">
|
||||
<h3>Console Logs</h3>
|
||||
</div>
|
||||
<div class="console_controls__QeCq_">
|
||||
<button class="button button_theme-plain__2mkOw button_plain__1LweR size-md" type="button">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-download"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg></button></div></div></header><pre class="console_terminal__3DK3w"><code class="ansi-hook console_output__2qZpe">
|
||||
<div class="console_line__1ir27">
|
||||
<span class="console_line-number__3zolU">1</span>
|
||||
<span class="loc-html console_line-content__3xTWR">Initialized empty Git repository in /drone/src/.git/
|
||||
</span><span class="console_line-time__oQvWj">0s</span></div><div class="console_line__1ir27"><span class="console_line-number__3zolU">2</span><span class="loc-html console_line-content__3xTWR">+ git fetch origin +refs/heads/main:
|
||||
</span><span class="console_line-time__oQvWj">0s</span></div><div class="console_line__1ir27"><span class="console_line-number__3zolU">3</span><span class="loc-html console_line-content__3xTWR">From https://github.com/go-gitea/gitea
|
||||
</span><span class="console_line-time__oQvWj">20s</span></div><div class="console_line__1ir27"><span class="console_line-number__3zolU">4</span><span class="loc-html console_line-content__3xTWR"> * branch main -> FETCH_HEAD
|
||||
</span><span class="console_line-time__oQvWj">20s</span></div><div class="console_line__1ir27"><span class="console_line-number__3zolU">5</span><span class="loc-html console_line-content__3xTWR"> * [new branch] main -> origin/main
|
||||
</span><span class="console_line-time__oQvWj">20s</span></div><div class="console_line__1ir27"><span class="console_line-number__3zolU">6</span><span class="loc-html console_line-content__3xTWR">+ git checkout c8ec2261a99590f15699e9147a28e4b61c1c2ea5 -b main
|
||||
</span><span class="console_line-time__oQvWj">20s</span></div><div class="console_line__1ir27"><span class="console_line-number__3zolU">7</span><span class="loc-html console_line-content__3xTWR">Switched to a new branch 'main'
|
||||
</span><span class="console_line-time__oQvWj">20s</span></div><div></div></code></pre>
|
||||
<footer class="console_footer__3xmc8"><div class="console_summary__1762k"><div class="console_summary-info__3mKSP"><div class="status_status__1f9yu status_status-success__2WE4F console_summary-status__2Vetb" title="Status: success"><svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414"><path fill="none" d="M0 0h20v20H0z"></path><path d="M14.577 6.23a.887.887 0 0 1 1.17-.019.704.704 0 0 1 .021 1.063l-6.844 6.439-.025.023a1.11 1.11 0 0 1-1.463-.023l-3.204-3.015a.704.704 0 0 1 .021-1.063.887.887 0 0 1 1.17.019l2.757 2.594 6.397-6.018z" fill="currentColor" fill-rule="nonzero"></path></svg></div>Exit Code 0</div><div class="console_summary-controls__Siy-a"></div></div></footer></div>
|
||||
</div>
|
@ -1,18 +0,0 @@
|
||||
<div class="ui dividing left rail">
|
||||
<div class="ui sticky fixed top" style="width: 283px !important; height: 1002.03px !important; margin-top: 30px; left: 1101px; top: 0px;">
|
||||
<h4 class="ui header">Menu</h4>
|
||||
<div class="ui vertical following fluid accordion text menu">
|
||||
{{range $file, $jobs := .WorkflowsStatuses}}
|
||||
<div class="item">
|
||||
<a class="title"><i class="dropdown icon"></i> <b>{{ $file }}</b></a>
|
||||
<div class="content">
|
||||
{{range $jobname, $job := $jobs}}
|
||||
{{template "repo/builds/status" $job.Status}}
|
||||
<a class="item" href="#{{$file}}__{{$jobname}}">{{ $jobname }}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user