mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-10 05:21:54 +02:00
Backport #37592 by @bircni When a workflow job failed, the API response reported all steps as failed — even steps that had completed successfully before the failing step. `ToActionWorkflowJob` was calling `ToActionsStatus(job.Status)` for every step instead of `ToActionsStatus(step.Status)`, so the job's overall conclusion was propagated to each step. Each `ActionTaskStep` has its own `Status` field that tracks the actual outcome of that step independently of the job result. Co-authored-by: Nicolas <bircni@icloud.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
3004c45607
commit
e10da87ebe
@ -9,6 +9,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
|
db "code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
@ -124,3 +125,55 @@ func TestToActionWorkflowRun_UsesTriggerEvent(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "schedule", apiRun.Event)
|
assert.Equal(t, "schedule", apiRun.Event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestToActionWorkflowJob_StepStatusIsIndependentOfJobStatus(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
|
run := &actions_model.ActionRun{
|
||||||
|
ID: 9001,
|
||||||
|
RepoID: 2,
|
||||||
|
TriggerUserID: 1,
|
||||||
|
WorkflowID: "test.yaml",
|
||||||
|
Index: 12345,
|
||||||
|
Ref: "refs/heads/main",
|
||||||
|
Status: actions_model.StatusFailure,
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Insert(ctx, run))
|
||||||
|
|
||||||
|
task := &actions_model.ActionTask{
|
||||||
|
ID: 900102,
|
||||||
|
JobID: 9001,
|
||||||
|
RepoID: 2,
|
||||||
|
Status: actions_model.StatusFailure,
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Insert(ctx, task))
|
||||||
|
|
||||||
|
job := &actions_model.ActionRunJob{
|
||||||
|
ID: 90010203,
|
||||||
|
RunID: 9001,
|
||||||
|
TaskID: 900102,
|
||||||
|
RepoID: 2,
|
||||||
|
Name: "test-job-name",
|
||||||
|
Attempt: 1,
|
||||||
|
JobID: "test-job-id",
|
||||||
|
Status: actions_model.StatusFailure,
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Insert(ctx, job))
|
||||||
|
|
||||||
|
require.NoError(t, db.Insert(ctx,
|
||||||
|
&actions_model.ActionTaskStep{TaskID: task.ID, RepoID: 2, Index: 0, Name: "step-success", Status: actions_model.StatusSuccess},
|
||||||
|
&actions_model.ActionTaskStep{TaskID: task.ID, RepoID: 2, Index: 1, Name: "step-failure", Status: actions_model.StatusFailure},
|
||||||
|
))
|
||||||
|
|
||||||
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
|
||||||
|
|
||||||
|
apiJob, err := ToActionWorkflowJob(ctx, repo, task, job)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, apiJob.Steps, 2)
|
||||||
|
|
||||||
|
assert.Equal(t, "completed", apiJob.Steps[0].Status, "step 0 status")
|
||||||
|
assert.Equal(t, "success", apiJob.Steps[0].Conclusion, "step 0 conclusion (succeeded before the failure)")
|
||||||
|
assert.Equal(t, "completed", apiJob.Steps[1].Status, "step 1 status")
|
||||||
|
assert.Equal(t, "failure", apiJob.Steps[1].Conclusion, "step 1 conclusion")
|
||||||
|
}
|
||||||
|
|||||||
@ -274,33 +274,31 @@ func ToActionWorkflowRun(ctx context.Context, repo *repo_model.Repository, run *
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToWorkflowRunAction(status actions_model.Status) string {
|
func ToWorkflowRunAction(status actions_model.Status) (action string) {
|
||||||
var action string
|
|
||||||
switch status {
|
switch status {
|
||||||
case actions_model.StatusWaiting, actions_model.StatusBlocked:
|
case actions_model.StatusWaiting, actions_model.StatusBlocked:
|
||||||
action = "requested"
|
action = "requested"
|
||||||
case actions_model.StatusRunning:
|
case actions_model.StatusRunning:
|
||||||
action = "in_progress"
|
action = "in_progress"
|
||||||
}
|
default:
|
||||||
if status.IsDone() {
|
if status.IsDone() {
|
||||||
action = "completed"
|
action = "completed"
|
||||||
|
} else {
|
||||||
|
setting.PanicInDevOrTesting("unknown action status: %v", status)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return action
|
return action
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToActionsStatus(status actions_model.Status) (string, string) {
|
func ToActionsStatus(status actions_model.Status) (action, conclusion string) {
|
||||||
var action string
|
|
||||||
var conclusion string
|
|
||||||
switch status {
|
switch status {
|
||||||
// This is a naming conflict of the webhook between Gitea and GitHub Actions
|
|
||||||
case actions_model.StatusWaiting:
|
case actions_model.StatusWaiting:
|
||||||
action = "queued"
|
action = "queued" // "waiting" is a naming conflict of the webhook between Gitea and GitHub Actions
|
||||||
case actions_model.StatusBlocked:
|
case actions_model.StatusBlocked:
|
||||||
action = "waiting"
|
action = "waiting" // naming conflict (as above)
|
||||||
case actions_model.StatusRunning:
|
case actions_model.StatusRunning:
|
||||||
action = "in_progress"
|
action = "in_progress"
|
||||||
}
|
default:
|
||||||
if status.IsDone() {
|
|
||||||
action = "completed"
|
action = "completed"
|
||||||
switch status {
|
switch status {
|
||||||
case actions_model.StatusSuccess:
|
case actions_model.StatusSuccess:
|
||||||
@ -311,6 +309,8 @@ func ToActionsStatus(status actions_model.Status) (string, string) {
|
|||||||
conclusion = "failure"
|
conclusion = "failure"
|
||||||
case actions_model.StatusSkipped:
|
case actions_model.StatusSkipped:
|
||||||
conclusion = "skipped"
|
conclusion = "skipped"
|
||||||
|
default:
|
||||||
|
setting.PanicInDevOrTesting("unknown action status: %v", status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return action, conclusion
|
return action, conclusion
|
||||||
@ -350,7 +350,7 @@ func ToActionWorkflowJob(ctx context.Context, repo *repo_model.Repository, task
|
|||||||
runnerName = runner.Name
|
runnerName = runner.Name
|
||||||
}
|
}
|
||||||
for i, step := range task.Steps {
|
for i, step := range task.Steps {
|
||||||
stepStatus, stepConclusion := ToActionsStatus(job.Status)
|
stepStatus, stepConclusion := ToActionsStatus(step.Status)
|
||||||
steps = append(steps, &api.ActionWorkflowStep{
|
steps = append(steps, &api.ActionWorkflowStep{
|
||||||
Name: step.Name,
|
Name: step.Name,
|
||||||
Number: int64(i),
|
Number: int64(i),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user