|
|
@ -8,6 +8,7 @@ import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
actions_model "code.gitea.io/gitea/models/actions"
|
|
|
|
actions_model "code.gitea.io/gitea/models/actions"
|
|
|
@ -310,6 +311,55 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob) erro
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Logs(ctx *context_module.Context) {
|
|
|
|
|
|
|
|
runIndex := ctx.ParamsInt64("run")
|
|
|
|
|
|
|
|
jobIndex := ctx.ParamsInt64("job")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
job, _ := getRunJobs(ctx, runIndex, jobIndex)
|
|
|
|
|
|
|
|
if ctx.Written() {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if job.TaskID == 0 {
|
|
|
|
|
|
|
|
ctx.Error(http.StatusNotFound, "job is not started")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := job.LoadRun(ctx)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
task, err := actions_model.GetTaskByID(ctx, job.TaskID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if task.LogExpired {
|
|
|
|
|
|
|
|
ctx.Error(http.StatusNotFound, "logs have been cleaned up")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reader, err := actions.OpenLogs(ctx, task.LogInStorage, task.LogFilename)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
ctx.Error(http.StatusInternalServerError, err.Error())
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer reader.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
workflowName := job.Run.WorkflowID
|
|
|
|
|
|
|
|
if p := strings.Index(workflowName, "."); p > 0 {
|
|
|
|
|
|
|
|
workflowName = workflowName[0:p]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.ServeContent(reader, &context_module.ServeHeaderOptions{
|
|
|
|
|
|
|
|
Filename: fmt.Sprintf("%v-%v-%v.log", workflowName, job.Name, task.ID),
|
|
|
|
|
|
|
|
ContentLength: &task.LogSize,
|
|
|
|
|
|
|
|
ContentType: "text/plain",
|
|
|
|
|
|
|
|
ContentTypeCharset: "utf-8",
|
|
|
|
|
|
|
|
Disposition: "attachment",
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Cancel(ctx *context_module.Context) {
|
|
|
|
func Cancel(ctx *context_module.Context) {
|
|
|
|
runIndex := ctx.ParamsInt64("run")
|
|
|
|
runIndex := ctx.ParamsInt64("run")
|
|
|
|
|
|
|
|
|
|
|
|