|
9 | 9 | "testing" |
10 | 10 |
|
11 | 11 | actions_model "code.gitea.io/gitea/models/actions" |
| 12 | + db "code.gitea.io/gitea/models/db" |
12 | 13 | repo_model "code.gitea.io/gitea/models/repo" |
13 | 14 | "code.gitea.io/gitea/models/unit" |
14 | 15 | "code.gitea.io/gitea/models/unittest" |
@@ -124,3 +125,61 @@ func TestToActionWorkflowRun_UsesTriggerEvent(t *testing.T) { |
124 | 125 | require.NoError(t, err) |
125 | 126 | assert.Equal(t, "schedule", apiRun.Event) |
126 | 127 | } |
| 128 | + |
| 129 | +func TestToActionWorkflowJob_StepStatusIsIndependentOfJobStatus(t *testing.T) { |
| 130 | + assert.NoError(t, unittest.PrepareTestDatabase()) |
| 131 | + ctx := t.Context() |
| 132 | + |
| 133 | + run := &actions_model.ActionRun{ |
| 134 | + ID: 9001, |
| 135 | + RepoID: 2, |
| 136 | + TriggerUserID: 1, |
| 137 | + WorkflowID: "test.yaml", |
| 138 | + Index: 9001, |
| 139 | + Ref: "refs/heads/main", |
| 140 | + CommitSHA: "c2d72f548424103f01ee1dc02889c1e2bff816b0", |
| 141 | + Event: "push", |
| 142 | + TriggerEvent: "push", |
| 143 | + Status: actions_model.StatusFailure, |
| 144 | + } |
| 145 | + require.NoError(t, db.Insert(ctx, run)) |
| 146 | + |
| 147 | + task := &actions_model.ActionTask{ |
| 148 | + ID: 9001, |
| 149 | + JobID: 9001, |
| 150 | + RepoID: 2, |
| 151 | + Status: actions_model.StatusFailure, |
| 152 | + TokenHash: "test_token_hash_9001_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 153 | + TokenSalt: "testsalt", |
| 154 | + TokenLastEight: "testlst1", |
| 155 | + } |
| 156 | + require.NoError(t, db.Insert(ctx, task)) |
| 157 | + |
| 158 | + job := &actions_model.ActionRunJob{ |
| 159 | + ID: 9001, |
| 160 | + RunID: 9001, |
| 161 | + RepoID: 2, |
| 162 | + Name: "test-job", |
| 163 | + Attempt: 1, |
| 164 | + JobID: "test-job", |
| 165 | + TaskID: 9001, |
| 166 | + Status: actions_model.StatusFailure, |
| 167 | + } |
| 168 | + require.NoError(t, db.Insert(ctx, job)) |
| 169 | + |
| 170 | + require.NoError(t, db.Insert(ctx, |
| 171 | + &actions_model.ActionTaskStep{TaskID: 9001, RepoID: 2, Index: 0, Name: "step-success", Status: actions_model.StatusSuccess}, |
| 172 | + &actions_model.ActionTaskStep{TaskID: 9001, RepoID: 2, Index: 1, Name: "step-failure", Status: actions_model.StatusFailure}, |
| 173 | + )) |
| 174 | + |
| 175 | + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}) |
| 176 | + |
| 177 | + apiJob, err := ToActionWorkflowJob(ctx, repo, task, job) |
| 178 | + require.NoError(t, err) |
| 179 | + require.Len(t, apiJob.Steps, 2) |
| 180 | + |
| 181 | + assert.Equal(t, "completed", apiJob.Steps[0].Status, "step 0 status") |
| 182 | + assert.Equal(t, "success", apiJob.Steps[0].Conclusion, "step 0 conclusion (succeeded before the failure)") |
| 183 | + assert.Equal(t, "completed", apiJob.Steps[1].Status, "step 1 status") |
| 184 | + assert.Equal(t, "failure", apiJob.Steps[1].Conclusion, "step 1 conclusion") |
| 185 | +} |
0 commit comments