mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
Make envs available in if conditionals (#225)
* Ignore .idea * Add Env to the RunContext vm so we can Evaluate and Interpolate `env.xx` * Make EvalBool support expressions more in line with the github runner * Turns out Boolean(value) is what github is doing after all * Add test for github context as well
This commit is contained in:
parent
18bc8ff929
commit
09c4c76744
4 changed files with 154 additions and 18 deletions
|
@ -4,15 +4,18 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nektos/act/pkg/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
a "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEvaluate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert := a.New(t)
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
Workdir: ".",
|
||||
},
|
||||
Env: map[string]string{
|
||||
"key": "value",
|
||||
},
|
||||
Run: &model.Run{
|
||||
JobID: "job1",
|
||||
Workflow: &model.Workflow{
|
||||
|
@ -79,6 +82,8 @@ func TestEvaluate(t *testing.T) {
|
|||
{"runner.os", "Linux", ""},
|
||||
{"matrix.os", "Linux", ""},
|
||||
{"matrix.foo", "bar", ""},
|
||||
{"env.key", "value", ""},
|
||||
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
|
@ -97,11 +102,14 @@ func TestEvaluate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInterpolate(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert := a.New(t)
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
Workdir: ".",
|
||||
},
|
||||
Env: map[string]string{
|
||||
"key": "value",
|
||||
},
|
||||
Run: &model.Run{
|
||||
JobID: "job1",
|
||||
Workflow: &model.Workflow{
|
||||
|
@ -113,8 +121,20 @@ func TestInterpolate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
ee := rc.NewExpressionEvaluator()
|
||||
tables := []struct{
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{" ${{1}} to ${{2}} ", " 1 to 2 "},
|
||||
{" ${{ env.key }} ", " value "},
|
||||
{"${{ env.unknown }}", ""},
|
||||
}
|
||||
|
||||
out := ee.Interpolate(" ${{1}} to ${{2}} ")
|
||||
|
||||
assert.Equal(" 1 to 2 ", out)
|
||||
for _, table := range tables {
|
||||
table := table
|
||||
t.Run(table.in, func(t *testing.T) {
|
||||
out := ee.Interpolate(table.in)
|
||||
assert.Equal(table.out, out, table.in)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue