fix: report job failure on error return (#14)

act_runner only returns the error to the runner, but doesn't update the job result to failure.

Co-authored-by: Christopher Homberger <christopher.homberger@web.de>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/14
Reviewed-by: Jason Song <i@wolfogre.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: ChristopherHX <christopherhx@noreply.gitea.io>
Co-committed-by: ChristopherHX <christopherhx@noreply.gitea.io>
This commit is contained in:
ChristopherHX 2023-01-27 20:18:12 +08:00 committed by Lunny Xiao
parent cf27d3f300
commit f7a52789d9

View File

@ -112,7 +112,7 @@ func getToken(task *runnerv1.Task) string {
return token
}
func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
func (t *Task) Run(ctx context.Context, task *runnerv1.Task) (lastErr error) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
_, exist := globalTaskMap.Load(task.Id)
@ -128,6 +128,14 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
lastWords := ""
reporter := NewReporter(ctx, cancel, t.client, task)
defer func() {
// set the job to failed on an error return value
if lastErr != nil {
reporter.Fire(&log.Entry{
Data: log.Fields{
"jobResult": "failure",
},
})
}
_ = reporter.Close(lastWords)
}()
reporter.RunDaemon()