From 8913375af89792be37603c3c6429372964bf86b1 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Wed, 3 May 2023 20:08:11 +0200 Subject: [PATCH] feat: implement steps.timeout-minutes (#1776) * feat: implement steps.timeout-minutes * Add imports * refactor code --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/runner/step.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/runner/step.go b/pkg/runner/step.go index cff48b1..9cc6aea 100644 --- a/pkg/runner/step.go +++ b/pkg/runner/step.go @@ -4,7 +4,9 @@ import ( "context" "fmt" "path" + "strconv" "strings" + "time" "github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/container" @@ -134,7 +136,9 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo Mode: 0o666, })(ctx) - err = executor(ctx) + timeoutctx, cancelTimeOut := evaluateStepTimeout(ctx, rc.ExprEval, stepModel) + defer cancelTimeOut() + err = executor(timeoutctx) if err == nil { logger.WithField("stepResult", stepResult.Outcome).Infof(" \u2705 Success - %s %s", stage, stepString) @@ -182,6 +186,16 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo } } +func evaluateStepTimeout(ctx context.Context, exprEval ExpressionEvaluator, stepModel *model.Step) (context.Context, context.CancelFunc) { + timeout := exprEval.Interpolate(ctx, stepModel.TimeoutMinutes) + if timeout != "" { + if timeOutMinutes, err := strconv.ParseInt(timeout, 10, 64); err == nil { + return context.WithTimeout(ctx, time.Duration(timeOutMinutes)*time.Minute) + } + } + return ctx, func() {} +} + func setupEnv(ctx context.Context, step step) error { rc := step.getRunContext()