auto adjust code

This commit is contained in:
Christopher Homberger
2026-02-22 20:58:46 +01:00
parent 949a40c7a5
commit d187ac2fc1
86 changed files with 617 additions and 617 deletions

View File

@@ -13,11 +13,11 @@ func (impl *interperterImpl) getNeedsTransitive(job *model.Job) []string {
return needs
}
func (impl *interperterImpl) always() (interface{}, error) {
func (impl *interperterImpl) always() (any, error) {
return true, nil
}
func (impl *interperterImpl) jobSuccess() (interface{}, error) {
func (impl *interperterImpl) jobSuccess() (any, error) {
jobs := impl.config.Run.Workflow.Jobs
jobNeeds := impl.getNeedsTransitive(impl.config.Run.Job())
@@ -30,11 +30,11 @@ func (impl *interperterImpl) jobSuccess() (interface{}, error) {
return true, nil
}
func (impl *interperterImpl) stepSuccess() (interface{}, error) {
func (impl *interperterImpl) stepSuccess() (any, error) {
return impl.env.Job.Status == "success", nil
}
func (impl *interperterImpl) jobFailure() (interface{}, error) {
func (impl *interperterImpl) jobFailure() (any, error) {
jobs := impl.config.Run.Workflow.Jobs
jobNeeds := impl.getNeedsTransitive(impl.config.Run.Job())
@@ -47,10 +47,10 @@ func (impl *interperterImpl) jobFailure() (interface{}, error) {
return false, nil
}
func (impl *interperterImpl) stepFailure() (interface{}, error) {
func (impl *interperterImpl) stepFailure() (any, error) {
return impl.env.Job.Status == "failure", nil
}
func (impl *interperterImpl) cancelled() (interface{}, error) {
func (impl *interperterImpl) cancelled() (any, error) {
return impl.env.Job.Status == "cancelled", nil
}

View File

@@ -18,16 +18,16 @@ type EvaluationEnvironment struct {
Job *model.JobContext
Jobs *map[string]*model.WorkflowCallResult
Steps map[string]*model.StepResult
Runner map[string]interface{}
Runner map[string]any
Secrets map[string]string
Vars map[string]string
Strategy map[string]interface{}
Matrix map[string]interface{}
Strategy map[string]any
Matrix map[string]any
Needs map[string]Needs
Inputs map[string]interface{}
HashFiles func([]reflect.Value) (interface{}, error)
Inputs map[string]any
HashFiles func([]reflect.Value) (any, error)
EnvCS bool
CtxData map[string]interface{}
CtxData map[string]any
}
type CaseSensitiveDict map[string]string
@@ -69,7 +69,7 @@ func (dsc DefaultStatusCheck) String() string {
}
type Interpreter interface {
Evaluate(input string, defaultStatusCheck DefaultStatusCheck) (interface{}, error)
Evaluate(input string, defaultStatusCheck DefaultStatusCheck) (any, error)
}
type interperterImpl struct {
@@ -151,7 +151,7 @@ func toRaw(left reflect.Value) any {
// All values are evaluated as string, funcs that takes objects are implemented elsewhere
type externalFunc struct {
f func([]reflect.Value) (interface{}, error)
f func([]reflect.Value) (any, error)
}
func (e externalFunc) Evaluate(ev *eval.Evaluator, args []exprparser.Node) (*eval.EvaluationResult, error) {
@@ -170,7 +170,7 @@ func (e externalFunc) Evaluate(ev *eval.Evaluator, args []exprparser.Node) (*eva
return eval.CreateIntermediateResult(ev.Context(), res), nil
}
func (impl *interperterImpl) Evaluate(input string, defaultStatusCheck DefaultStatusCheck) (interface{}, error) {
func (impl *interperterImpl) Evaluate(input string, defaultStatusCheck DefaultStatusCheck) (any, error) {
input = strings.TrimPrefix(input, "${{")
input = strings.TrimSuffix(input, "}}")
if defaultStatusCheck != DefaultStatusCheckNone && input == "" {
@@ -226,10 +226,10 @@ func (impl *interperterImpl) GetFunctions() eval.CaseInsensitiveObject[eval.Func
if impl.env.HashFiles != nil {
functions["hashfiles"] = &externalFunc{impl.env.HashFiles}
}
functions["always"] = &externalFunc{func(_ []reflect.Value) (interface{}, error) {
functions["always"] = &externalFunc{func(_ []reflect.Value) (any, error) {
return impl.always()
}}
functions["success"] = &externalFunc{func(_ []reflect.Value) (interface{}, error) {
functions["success"] = &externalFunc{func(_ []reflect.Value) (any, error) {
if impl.config.Context == "job" {
return impl.jobSuccess()
}
@@ -238,7 +238,7 @@ func (impl *interperterImpl) GetFunctions() eval.CaseInsensitiveObject[eval.Func
}
return nil, fmt.Errorf("context '%s' must be one of 'job' or 'step'", impl.config.Context)
}}
functions["failure"] = &externalFunc{func(_ []reflect.Value) (interface{}, error) {
functions["failure"] = &externalFunc{func(_ []reflect.Value) (any, error) {
if impl.config.Context == "job" {
return impl.jobFailure()
}
@@ -247,7 +247,7 @@ func (impl *interperterImpl) GetFunctions() eval.CaseInsensitiveObject[eval.Func
}
return nil, fmt.Errorf("context '%s' must be one of 'job' or 'step'", impl.config.Context)
}}
functions["cancelled"] = &externalFunc{func(_ []reflect.Value) (interface{}, error) {
functions["cancelled"] = &externalFunc{func(_ []reflect.Value) (any, error) {
return impl.cancelled()
}}
return functions
@@ -287,7 +287,7 @@ func (impl *interperterImpl) GetVariables() eval.ReadOnlyObject[any] {
res := eval.CreateIntermediateResult(eval.NewEvaluationContext(), rawOtherCtx)
if rOtherCd, ok := res.TryGetCollectionInterface(); ok {
if otherCd, ok := rOtherCd.(eval.ReadOnlyObject[any]); ok {
if rawPayload, ok := cd.(map[string]interface{}); ok {
if rawPayload, ok := cd.(map[string]any); ok {
for k, v := range rawPayload {
// skip empty values, because github.workspace was set by Gitea Actions to an empty string
if mk, _ := otherCd.GetKv(k); v != "" && v != nil {
@@ -304,7 +304,7 @@ func (impl *interperterImpl) GetVariables() eval.ReadOnlyObject[any] {
return vars
}
func IsTruthy(input interface{}) bool {
func IsTruthy(input any) bool {
value := reflect.ValueOf(input)
switch value.Kind() {
case reflect.Bool:

View File

@@ -11,7 +11,7 @@ import (
func TestLiterals(t *testing.T) {
table := []struct {
input string
expected interface{}
expected any
name string
}{
{"true", true, "true"},
@@ -30,7 +30,7 @@ func TestLiterals(t *testing.T) {
for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
output, err := NewInterpeter(env, Config{}).Evaluate(tt.input, DefaultStatusCheckNone)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, tt.expected, output)
})
@@ -40,7 +40,7 @@ func TestLiterals(t *testing.T) {
func TestOperators(t *testing.T) {
table := []struct {
input string
expected interface{}
expected any
name string
error string
}{
@@ -69,7 +69,7 @@ func TestOperators(t *testing.T) {
{`true && false`, false, "and", ""},
{`true || false`, true, "or", ""},
{`fromJSON('{}') && true`, true, "and-boolean-object", ""},
{`fromJSON('{}') || false`, make(map[string]interface{}), "or-boolean-object", ""},
{`fromJSON('{}') || false`, make(map[string]any), "or-boolean-object", ""},
{"github.event.commits[0].author.username != github.event.commits[1].author.username", true, "property-comparison1", ""},
{"github.event.commits[0].author.username1 != github.event.commits[1].author.username", true, "property-comparison2", ""},
{"github.event.commits[0].author.username != github.event.commits[1].author.username1", true, "property-comparison3", ""},
@@ -81,15 +81,15 @@ func TestOperators(t *testing.T) {
env := &EvaluationEnvironment{
Github: &model.GithubContext{
Action: "push",
Event: map[string]interface{}{
"commits": []interface{}{
map[string]interface{}{
"author": map[string]interface{}{
Event: map[string]any{
"commits": []any{
map[string]any{
"author": map[string]any{
"username": "someone",
},
},
map[string]interface{}{
"author": map[string]interface{}{
map[string]any{
"author": map[string]any{
"username": "someone-else",
},
},
@@ -102,10 +102,10 @@ func TestOperators(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
output, err := NewInterpeter(env, Config{}).Evaluate(tt.input, DefaultStatusCheckNone)
if tt.error != "" {
assert.NotNil(t, err)
assert.Error(t, err)
assert.Equal(t, tt.error, err.Error())
} else {
assert.Nil(t, err)
assert.NoError(t, err)
}
assert.Equal(t, tt.expected, output)
@@ -116,7 +116,7 @@ func TestOperators(t *testing.T) {
func TestOperatorsCompare(t *testing.T) {
table := []struct {
input string
expected interface{}
expected any
name string
}{
{"!null", true, "not-null"},
@@ -154,7 +154,7 @@ func TestOperatorsCompare(t *testing.T) {
for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
output, err := NewInterpeter(env, Config{}).Evaluate(tt.input, DefaultStatusCheckNone)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, tt.expected, output)
})
@@ -164,7 +164,7 @@ func TestOperatorsCompare(t *testing.T) {
func TestOperatorsBooleanEvaluation(t *testing.T) {
table := []struct {
input string
expected interface{}
expected any
name string
}{
// true &&
@@ -517,7 +517,7 @@ func TestOperatorsBooleanEvaluation(t *testing.T) {
for _, tt := range table {
t.Run(tt.name, func(t *testing.T) {
output, err := NewInterpeter(env, Config{}).Evaluate(tt.input, DefaultStatusCheckNone)
assert.Nil(t, err)
assert.NoError(t, err)
// Normalize int => float64
if i, ok := tt.expected.(int); ok {
@@ -536,15 +536,15 @@ func TestOperatorsBooleanEvaluation(t *testing.T) {
func TestContexts(t *testing.T) {
table := []struct {
input string
expected interface{}
expected any
name string
caseSensitiveEnv bool
ctxdata map[string]interface{}
ctxdata map[string]any
}{
{input: "github.action", expected: "push", name: "github-context"},
{input: "github.action", expected: "push", name: "github-context", ctxdata: map[string]interface{}{"github": map[string]interface{}{"ref": "refs/heads/test-data"}}},
{input: "github.ref", expected: "refs/heads/test-data", name: "github-context", ctxdata: map[string]interface{}{"github": map[string]interface{}{"ref": "refs/heads/test-data"}}},
{input: "github.custom-field", expected: "custom-value", name: "github-context", ctxdata: map[string]interface{}{"github": map[string]interface{}{"custom-field": "custom-value"}}},
{input: "github.action", expected: "push", name: "github-context", ctxdata: map[string]any{"github": map[string]any{"ref": "refs/heads/test-data"}}},
{input: "github.ref", expected: "refs/heads/test-data", name: "github-context", ctxdata: map[string]any{"github": map[string]any{"ref": "refs/heads/test-data"}}},
{input: "github.custom-field", expected: "custom-value", name: "github-context", ctxdata: map[string]any{"github": map[string]any{"custom-field": "custom-value"}}},
{input: "github.event.commits[0].message", expected: nil, name: "github-context-noexist-prop"},
{input: "fromjson('{\"commits\":[]}').commits[0].message", expected: nil, name: "github-context-noexist-prop"},
{input: "github.event.pull_request.labels.*.name", expected: nil, name: "github-context-noexist-prop"},
@@ -581,8 +581,8 @@ func TestContexts(t *testing.T) {
{input: "contains(needs.*.result, 'success')", expected: true, name: "needs-wildcard-context-contains-success"},
{input: "contains(needs.*.result, 'failure')", expected: false, name: "needs-wildcard-context-contains-failure"},
{input: "inputs.name", expected: "value", name: "inputs-context"},
{input: "vars.MY_VAR", expected: "refs/heads/test-data", name: "vars-context", ctxdata: map[string]interface{}{"vars": map[string]interface{}{"MY_VAR": "refs/heads/test-data"}}},
{input: "vars.MY_VAR", expected: "refs/heads/test-data", name: "vars-context", ctxdata: map[string]interface{}{"vars": map[string]interface{}{"my_var": "refs/heads/test-data"}}},
{input: "vars.MY_VAR", expected: "refs/heads/test-data", name: "vars-context", ctxdata: map[string]any{"vars": map[string]any{"MY_VAR": "refs/heads/test-data"}}},
{input: "vars.MY_VAR", expected: "refs/heads/test-data", name: "vars-context", ctxdata: map[string]any{"vars": map[string]any{"my_var": "refs/heads/test-data"}}},
}
env := EvaluationEnvironment{
@@ -606,7 +606,7 @@ func TestContexts(t *testing.T) {
Conclusion: model.StepStatusSkipped,
},
},
Runner: map[string]interface{}{
Runner: map[string]any{
"os": "Linux",
"temp": "/tmp",
"tool_cache": "/opt/hostedtoolcache",
@@ -617,10 +617,10 @@ func TestContexts(t *testing.T) {
Vars: map[string]string{
"name": "value",
},
Strategy: map[string]interface{}{
Strategy: map[string]any{
"fail-fast": true,
},
Matrix: map[string]interface{}{
Matrix: map[string]any{
"os": "Linux",
},
Needs: map[string]Needs{
@@ -637,7 +637,7 @@ func TestContexts(t *testing.T) {
Result: "success",
},
},
Inputs: map[string]interface{}{
Inputs: map[string]any{
"name": "value",
},
}
@@ -648,7 +648,7 @@ func TestContexts(t *testing.T) {
tenv.EnvCS = tt.caseSensitiveEnv
tenv.CtxData = tt.ctxdata
output, err := NewInterpeter(&tenv, Config{}).Evaluate(tt.input, DefaultStatusCheckNone)
assert.Nil(t, err)
assert.NoError(t, err)
assert.Equal(t, tt.expected, output)
})