Report error when if
expression is invalid (#485)
Co-authored-by: Ed Tan <edtan@users.noreply.github.com> Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
9bbf35e88e
commit
c7b3869b2f
2 changed files with 6 additions and 3 deletions
|
@ -314,7 +314,7 @@ func (rc *RunContext) EvalBool(expr string) (bool, error) {
|
||||||
joined := strings.Join(evaluatedParts, " ")
|
joined := strings.Join(evaluatedParts, " ")
|
||||||
v, _, err := rc.ExprEval.Evaluate(fmt.Sprintf("Boolean(%s)", joined))
|
v, _, err := rc.ExprEval.Evaluate(fmt.Sprintf("Boolean(%s)", joined))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil
|
return false, err
|
||||||
}
|
}
|
||||||
log.Debugf("expression '%s' evaluated to '%s'", expr, v)
|
log.Debugf("expression '%s' evaluated to '%s'", expr, v)
|
||||||
return v == "true", nil
|
return v == "true", nil
|
||||||
|
|
|
@ -2,13 +2,14 @@ package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/nektos/act/pkg/model"
|
|
||||||
a "github.com/stretchr/testify/assert"
|
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nektos/act/pkg/model"
|
||||||
|
a "github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus/hooks/test"
|
"github.com/sirupsen/logrus/hooks/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -129,6 +130,8 @@ func TestRunContext_EvalBool(t *testing.T) {
|
||||||
// The special ACT flag
|
// The special ACT flag
|
||||||
{in: "${{ env.ACT }}", out: true},
|
{in: "${{ env.ACT }}", out: true},
|
||||||
{in: "${{ !env.ACT }}", out: false},
|
{in: "${{ !env.ACT }}", out: false},
|
||||||
|
// Invalid expressions should be reported
|
||||||
|
{in: "INVALID_EXPRESSION", wantErr: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTestIfWorkflow(t, tables, rc)
|
updateTestIfWorkflow(t, tables, rc)
|
||||||
|
|
Loading…
Reference in a new issue