From f7a52789d950a57cf0c985d02715714740426e5c Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Fri, 27 Jan 2023 20:18:12 +0800 Subject: [PATCH] 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 Reviewed-on: https://gitea.com/gitea/act_runner/pulls/14 Reviewed-by: Jason Song Reviewed-by: Lunny Xiao Co-authored-by: ChristopherHX Co-committed-by: ChristopherHX --- runtime/task.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/runtime/task.go b/runtime/task.go index 01d6420..b899c5b 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -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()