mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-13 22:41:54 +02:00
refactor: move act/model and act/exprparser to actionslib (#1143)
Gitea needs the workflow model and the expression evaluator to parse workflows and to build the task payload this runner consumes, so today it depends on `gitea.com/gitea/runner` just for `act/model` and `act/exprparser`. Both packages now live in `gitea.dev/actionslib` (`pkg/model`, `pkg/exprparser`), the module both sides already share, and this repository consumes them from there. ### Changes - `act/model` and `act/exprparser` are deleted, all imports point at `gitea.dev/actionslib/pkg/...`. - New `act/ghcontext` package: the `GithubContext` helpers that need a git checkout on disk (`SetRef`, `SetSha`, `SetRepositoryAndOwner`) are runner only and would drag a git client plus the act context logger into the shared module, so they stay here as functions, with their tests. Only caller is `RunContext.getGithubContext`. - `act/common.CartesianProduct` moved to the shared model package, `act/model` was its only user. - `act/model/testdata/container-volumes` moved to `act/runner/testdata/container-volumes`, its only user is `runner_test.go`. - `internal/pkg/client.UUIDHeader` / `TokenHeader` now alias `pkg/protocol`, so the header names cannot drift apart from Gitea. ### Notes - No behaviour change intended: the moved files are unchanged apart from the import paths and the split described above. - `go.mod` depends on the released `gitea.dev/actionslib v0.7.0`, which carries both https://gitea.com/gitea/actionslib/pulls/11 and the `model.UsesHash` port in https://gitea.com/gitea/actionslib/pulls/14 that `main` needs after https://gitea.com/gitea/runner/pulls/1150. - Verified with `go build ./...`, `go vet ./...` and `go test ./act/... ./internal/...`; the docker based `act/runner` integration tests (`TestRunEvent`, `TestRunMatrixWithUserDefinedInclusions`) fail identically with and without this change in my environment. Assisted-by: Codet:GPT-5.1-Codex Reviewed-on: https://gitea.com/gitea/runner/pulls/1143 Reviewed-by: silverwind <[email protected]>
This commit is contained in:
@@ -9,9 +9,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.com/gitea/runner/act/exprparser"
|
||||
"gitea.com/gitea/runner/act/model"
|
||||
|
||||
"gitea.dev/actionslib/pkg/exprparser"
|
||||
"gitea.dev/actionslib/pkg/model"
|
||||
assert "github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
yaml "go.yaml.in/yaml/v4"
|
||||
@@ -279,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