From ac1ba34518bcbddcc27356b5923971fbdc5e4397 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Fri, 14 Apr 2023 15:42:03 +0800 Subject: [PATCH] Fix incorrect job result status (#40) Fix [#24039(GitHub)](https://github.com/go-gitea/gitea/issues/24039) At present, if a job fails in the `Set up job`, the result status of the job will still be `success`. The reason is that the `pre` steps don't call `SetJobError`, so the `jobError` will be nil when `post` steps setting the job result. See https://gitea.com/gitea/act/src/commit/5c4a96bcb797c7d013b878f1a3ceb74f9a834c64/pkg/runner/job_executor.go#L99 Reviewed-on: https://gitea.com/gitea/act/pulls/40 Reviewed-by: Jason Song Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- pkg/runner/job_executor.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/runner/job_executor.go b/pkg/runner/job_executor.go index 1fcb00b..e20bf59 100644 --- a/pkg/runner/job_executor.go +++ b/pkg/runner/job_executor.go @@ -70,7 +70,19 @@ func newJobExecutor(info jobInfo, sf stepFactory, rc *RunContext) common.Executo return common.NewErrorExecutor(err) } - preSteps = append(preSteps, useStepLogger(rc, stepModel, stepStagePre, step.pre())) + preExec := step.pre() + preSteps = append(preSteps, useStepLogger(rc, stepModel, stepStagePre, func(ctx context.Context) error { + logger := common.Logger(ctx) + preErr := preExec(ctx) + if preErr != nil { + logger.Errorf("%v", preErr) + common.SetJobError(ctx, preErr) + } else if ctx.Err() != nil { + logger.Errorf("%v", ctx.Err()) + common.SetJobError(ctx, ctx.Err()) + } + return preErr + })) stepExec := step.main() steps = append(steps, useStepLogger(rc, stepModel, stepStageMain, func(ctx context.Context) error {