mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-07 17:34:22 +02:00
refactor: use the shared expression evaluation layer
Gitea carries a copy of this evaluation layer, as modules/actions/jobparser/evaluator.go says itself: "copied from runner.expressionEvaluator, to avoid unnecessary dependencies". It now lives in gitea.dev/actionslib/pkg/expreval, so both sides split sub-expressions, interpolate, keep the type of a lone expression and apply the default status check the same way. expressionEvaluator keeps the logging and the mask of every single evaluation, which is what the shared Evaluator takes a function for. Signed-off-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -278,41 +278,6 @@ func TestInterpolate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitSubExpressions(t *testing.T) {
|
||||
expr := func(text string) exprPart { return exprPart{text: text, isExpr: true} }
|
||||
literal := func(text string) exprPart { return exprPart{text: text} }
|
||||
|
||||
for _, tt := range []struct {
|
||||
in string
|
||||
want []exprPart
|
||||
}{
|
||||
{"Hello World", []exprPart{literal("Hello World")}},
|
||||
{"${{ true }}", []exprPart{expr("true")}},
|
||||
{"${{ true }} ${{ false }}", []exprPart{expr("true"), literal(" "), expr("false")}},
|
||||
{"Hello ${{ 'World' }}", []exprPart{literal("Hello "), expr("'World'")}},
|
||||
// a quote toggles string state, so a `}}` inside a string does not end the expression
|
||||
{"${{ '}}' }}", []exprPart{expr("'}}'")}},
|
||||
{"${{ '''}}''' }}", []exprPart{expr("'''}}'''")}},
|
||||
{"${{ '''' }}", []exprPart{expr("''''")}},
|
||||
{`${{ fromJSON('"}}"') }}`, []exprPart{expr(`fromJSON('"}}"')`)}},
|
||||
{`${{ fromJSON('"\"}}\""') }}`, []exprPart{expr(`fromJSON('"\"}}\""')`)}},
|
||||
{`${{ fromJSON('"''}}"') }}`, []exprPart{expr(`fromJSON('"''}}"')`)}},
|
||||
// without a complete literal the value stays text, as GitHub's template reader leaves it
|
||||
{"${{ 1", []exprPart{literal("${{ 1")}},
|
||||
// a malformed part stays one part, so it cannot restructure its neighbours
|
||||
{"${{ 1) && (2 }}", []exprPart{expr("1) && (2")}},
|
||||
} {
|
||||
got, err := splitSubExpressions(tt.in)
|
||||
require.NoError(t, err, tt.in)
|
||||
assert.Equal(t, tt.want, got, tt.in)
|
||||
}
|
||||
|
||||
for _, in := range []string{"${{ 'a' }} ${{ b", "${{ 'a }}"} {
|
||||
_, err := splitSubExpressions(in)
|
||||
assert.ErrorContains(t, err, "unclosed expression", in)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEvaluatorInputsBoolean(t *testing.T) {
|
||||
workflows := map[string]string{
|
||||
"workflow_call": `
|
||||
|
||||
Reference in New Issue
Block a user