Skip to content

Commit 8913375

Browse files
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>
1 parent ca9b783 commit 8913375

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/runner/step.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55
"fmt"
66
"path"
7+
"strconv"
78
"strings"
9+
"time"
810

911
"github.com/nektos/act/pkg/common"
1012
"github.com/nektos/act/pkg/container"
@@ -134,7 +136,9 @@ func runStepExecutor(step step, stage stepStage, executor common.Executor) commo
134136
Mode: 0o666,
135137
})(ctx)
136138

137-
err = executor(ctx)
139+
timeoutctx, cancelTimeOut := evaluateStepTimeout(ctx, rc.ExprEval, stepModel)
140+
defer cancelTimeOut()
141+
err = executor(timeoutctx)
138142

139143
if err == nil {
140144
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
182186
}
183187
}
184188

189+
func evaluateStepTimeout(ctx context.Context, exprEval ExpressionEvaluator, stepModel *model.Step) (context.Context, context.CancelFunc) {
190+
timeout := exprEval.Interpolate(ctx, stepModel.TimeoutMinutes)
191+
if timeout != "" {
192+
if timeOutMinutes, err := strconv.ParseInt(timeout, 10, 64); err == nil {
193+
return context.WithTimeout(ctx, time.Duration(timeOutMinutes)*time.Minute)
194+
}
195+
}
196+
return ctx, func() {}
197+
}
198+
185199
func setupEnv(ctx context.Context, step step) error {
186200
rc := step.getRunContext()
187201

0 commit comments

Comments
 (0)