mirror of https://github.com/go-gitea/gitea.git
parent
894821d522
commit
321cbcb45a
|
@ -22,7 +22,7 @@ func DownloadActionsRunJobLogsWithIndex(ctx *context.Base, ctxRepo *repo_model.R
|
||||||
if err = runJobs.LoadRepos(ctx); err != nil {
|
if err = runJobs.LoadRepos(ctx); err != nil {
|
||||||
return fmt.Errorf("LoadRepos: %w", err)
|
return fmt.Errorf("LoadRepos: %w", err)
|
||||||
}
|
}
|
||||||
if 0 < jobIndex || jobIndex >= int64(len(runJobs)) {
|
if jobIndex < 0 || jobIndex >= int64(len(runJobs)) {
|
||||||
return util.NewNotExistErrorf("job index is out of range: %d", jobIndex)
|
return util.NewNotExistErrorf("job index is out of range: %d", jobIndex)
|
||||||
}
|
}
|
||||||
return DownloadActionsRunJobLogs(ctx, ctxRepo, runJobs[jobIndex])
|
return DownloadActionsRunJobLogs(ctx, ctxRepo, runJobs[jobIndex])
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestDownloadTaskLogs(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
treePath string
|
treePath string
|
||||||
fileContent string
|
fileContent string
|
||||||
outcome *mockTaskOutcome
|
outcome []*mockTaskOutcome
|
||||||
zstdEnabled bool
|
zstdEnabled bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,13 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo job1 with zstd enabled
|
- run: echo job1 with zstd enabled
|
||||||
|
job2:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo job2 with zstd enabled
|
||||||
`,
|
`,
|
||||||
outcome: &mockTaskOutcome{
|
outcome: []*mockTaskOutcome{
|
||||||
|
{
|
||||||
result: runnerv1.Result_RESULT_SUCCESS,
|
result: runnerv1.Result_RESULT_SUCCESS,
|
||||||
logRows: []*runnerv1.LogRow{
|
logRows: []*runnerv1.LogRow{
|
||||||
{
|
{
|
||||||
|
@ -64,6 +69,24 @@ jobs:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
result: runnerv1.Result_RESULT_SUCCESS,
|
||||||
|
logRows: []*runnerv1.LogRow{
|
||||||
|
{
|
||||||
|
Time: timestamppb.New(now.Add(1 * time.Second)),
|
||||||
|
Content: " \U0001F433 docker create image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Time: timestamppb.New(now.Add(2 * time.Second)),
|
||||||
|
Content: "job2 zstd enabled",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Time: timestamppb.New(now.Add(3 * time.Second)),
|
||||||
|
Content: "\U0001F3C1 Job succeeded",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
zstdEnabled: true,
|
zstdEnabled: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -78,8 +101,13 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo job1 with zstd disabled
|
- run: echo job1 with zstd disabled
|
||||||
|
job2:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo job2 with zstd disabled
|
||||||
`,
|
`,
|
||||||
outcome: &mockTaskOutcome{
|
outcome: []*mockTaskOutcome{
|
||||||
|
{
|
||||||
result: runnerv1.Result_RESULT_SUCCESS,
|
result: runnerv1.Result_RESULT_SUCCESS,
|
||||||
logRows: []*runnerv1.LogRow{
|
logRows: []*runnerv1.LogRow{
|
||||||
{
|
{
|
||||||
|
@ -96,6 +124,24 @@ jobs:
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
result: runnerv1.Result_RESULT_SUCCESS,
|
||||||
|
logRows: []*runnerv1.LogRow{
|
||||||
|
{
|
||||||
|
Time: timestamppb.New(now.Add(4 * time.Second)),
|
||||||
|
Content: " \U0001F433 docker create image",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Time: timestamppb.New(now.Add(5 * time.Second)),
|
||||||
|
Content: "job2 zstd disabled",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Time: timestamppb.New(now.Add(6 * time.Second)),
|
||||||
|
Content: "\U0001F3C1 Job succeeded",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
zstdEnabled: false,
|
zstdEnabled: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -124,9 +170,10 @@ jobs:
|
||||||
opts := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, fmt.Sprintf("create %s", tc.treePath), tc.fileContent)
|
opts := getWorkflowCreateFileOptions(user2, repo.DefaultBranch, fmt.Sprintf("create %s", tc.treePath), tc.fileContent)
|
||||||
createWorkflowFile(t, token, user2.Name, repo.Name, tc.treePath, opts)
|
createWorkflowFile(t, token, user2.Name, repo.Name, tc.treePath, opts)
|
||||||
|
|
||||||
// fetch and execute task
|
// fetch and execute tasks
|
||||||
|
for jobIndex, outcome := range tc.outcome {
|
||||||
task := runner.fetchTask(t)
|
task := runner.fetchTask(t)
|
||||||
runner.execTask(t, task, tc.outcome)
|
runner.execTask(t, task, outcome)
|
||||||
|
|
||||||
// check whether the log file exists
|
// check whether the log file exists
|
||||||
logFileName := fmt.Sprintf("%s/%02x/%d.log", repo.FullName(), task.Id%256, task.Id)
|
logFileName := fmt.Sprintf("%s/%02x/%d.log", repo.FullName(), task.Id%256, task.Id)
|
||||||
|
@ -138,12 +185,12 @@ jobs:
|
||||||
|
|
||||||
// download task logs and check content
|
// download task logs and check content
|
||||||
runIndex := task.Context.GetFields()["run_number"].GetStringValue()
|
runIndex := task.Context.GetFields()["run_number"].GetStringValue()
|
||||||
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/actions/runs/%s/jobs/0/logs", user2.Name, repo.Name, runIndex)).
|
req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s/actions/runs/%s/jobs/%d/logs", user2.Name, repo.Name, runIndex, jobIndex)).
|
||||||
AddTokenAuth(token)
|
AddTokenAuth(token)
|
||||||
resp := MakeRequest(t, req, http.StatusOK)
|
resp := MakeRequest(t, req, http.StatusOK)
|
||||||
logTextLines := strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
|
logTextLines := strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
|
||||||
assert.Len(t, logTextLines, len(tc.outcome.logRows))
|
assert.Len(t, logTextLines, len(outcome.logRows))
|
||||||
for idx, lr := range tc.outcome.logRows {
|
for idx, lr := range outcome.logRows {
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
t,
|
t,
|
||||||
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
|
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
|
||||||
|
@ -155,23 +202,23 @@ jobs:
|
||||||
|
|
||||||
jobs, err := actions_model.GetRunJobsByRunID(t.Context(), runID)
|
jobs, err := actions_model.GetRunJobsByRunID(t.Context(), runID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, jobs, 1)
|
assert.Len(t, jobs, len(tc.outcome))
|
||||||
jobID := jobs[0].ID
|
jobID := jobs[jobIndex].ID
|
||||||
|
|
||||||
// download task logs from API and check content
|
// download task logs from API and check content
|
||||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/jobs/%d/logs", user2.Name, repo.Name, jobID)).
|
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/jobs/%d/logs", user2.Name, repo.Name, jobID)).
|
||||||
AddTokenAuth(token)
|
AddTokenAuth(token)
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
|
logTextLines = strings.Split(strings.TrimSpace(resp.Body.String()), "\n")
|
||||||
assert.Len(t, logTextLines, len(tc.outcome.logRows))
|
assert.Len(t, logTextLines, len(outcome.logRows))
|
||||||
for idx, lr := range tc.outcome.logRows {
|
for idx, lr := range outcome.logRows {
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
t,
|
t,
|
||||||
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
|
fmt.Sprintf("%s %s", lr.Time.AsTime().Format("2006-01-02T15:04:05.0000000Z07:00"), lr.Content),
|
||||||
logTextLines[idx],
|
logTextLines[idx],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
resetFunc()
|
resetFunc()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue