Expression evaluator fixes (#1009)
* refactor: remove debug error output Errors should always be logged with an error level and not debug level. Since the error is returned here, it will be logged later as an error. Presumably this was a leftover from debugging the executor chain in: PR: #971 * refactor: debug log wich expression is going to be evaluated * fix: handle nil in EvalBool We've seen this issue when the env map is not set-up properly, i.e. when the env map is nil, EvalBool might return nil, which should be handled as a falsy value. * fix: fail on error in if expression and return the evaluation error Stop running the workflow in case an expression cannot be evaluated. Fixes: #1008 * fix: remove quotes from inside expression syntax in test It looks like having an expression inside double quotes inside the expression syntax is not valid: https://github.com/ZauberNerd/act-test/actions/runs/1881986429 The workflow is not valid. .github/workflows/test.yml (Line: 10, Col: 13): Unexpected symbol: '"endsWith'. Located at position 1 within expression: "endsWith('Hello world', 'ld')" * refactor: export IsTruthy function from exprparser package * refactor: use IsTruthy function in EvalBool * refactor: move debug log for expression rewrite to rewrite function Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
@@ -275,7 +275,18 @@ func (rc *RunContext) steps() []*model.Step {
|
||||
|
||||
// Executor returns a pipeline executor for all the steps in the job
|
||||
func (rc *RunContext) Executor() common.Executor {
|
||||
return newJobExecutor(rc).If(rc.isEnabled)
|
||||
return func(ctx context.Context) error {
|
||||
isEnabled, err := rc.isEnabled(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if isEnabled {
|
||||
return newJobExecutor(rc)(ctx)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Executor returns a pipeline executor for all the steps in the job
|
||||
@@ -405,17 +416,16 @@ func (rc *RunContext) hostname() string {
|
||||
return *hostname
|
||||
}
|
||||
|
||||
func (rc *RunContext) isEnabled(ctx context.Context) bool {
|
||||
func (rc *RunContext) isEnabled(ctx context.Context) (bool, error) {
|
||||
job := rc.Run.Job()
|
||||
l := common.Logger(ctx)
|
||||
runJob, err := EvalBool(rc.ExprEval, job.If.Value)
|
||||
if err != nil {
|
||||
common.Logger(ctx).Errorf(" \u274C Error in if: expression - %s", job.Name)
|
||||
return false
|
||||
return false, fmt.Errorf(" \u274C Error in if-expression: \"if: %s\" (%s)", job.If.Value, err)
|
||||
}
|
||||
if !runJob {
|
||||
l.Debugf("Skipping job '%s' due to '%s'", job.Name, job.If.Value)
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
|
||||
img := rc.platformImage()
|
||||
@@ -428,9 +438,9 @@ func (rc *RunContext) isEnabled(ctx context.Context) bool {
|
||||
platformName := rc.ExprEval.Interpolate(runnerLabel)
|
||||
l.Infof("\U0001F6A7 Skipping unsupported platform -- Try running with `-P %+v=...`", platformName)
|
||||
}
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func mergeMaps(maps ...map[string]string) map[string]string {
|
||||
|
Reference in New Issue
Block a user