mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-01 00:10:31 +08:00
Compare commits
2 Commits
v0.6.0
...
fix/job-en
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e23fda0aca | ||
|
|
66a723f9a6 |
@@ -78,13 +78,20 @@ func (rc *RunContext) String() string {
|
||||
|
||||
// GetEnv returns the env for the context
|
||||
func (rc *RunContext) GetEnv() map[string]string {
|
||||
baseEnv := map[string]string{}
|
||||
if rc.Run != nil && rc.Run.Workflow != nil && rc.Config != nil {
|
||||
job := rc.Run.Job()
|
||||
if job != nil {
|
||||
baseEnv = mergeMaps(rc.Run.Workflow.Env, job.Environment(), rc.Config.Env)
|
||||
}
|
||||
}
|
||||
|
||||
if rc.Env == nil {
|
||||
rc.Env = map[string]string{}
|
||||
if rc.Run != nil && rc.Run.Workflow != nil && rc.Config != nil {
|
||||
job := rc.Run.Job()
|
||||
if job != nil {
|
||||
rc.Env = mergeMaps(rc.Run.Workflow.Env, job.Environment(), rc.Config.Env)
|
||||
}
|
||||
}
|
||||
for k, v := range baseEnv {
|
||||
if _, ok := rc.Env[k]; !ok {
|
||||
rc.Env[k] = v
|
||||
}
|
||||
}
|
||||
rc.Env["ACT"] = "true"
|
||||
|
||||
@@ -572,6 +572,10 @@ if: false`, ""),
|
||||
}
|
||||
|
||||
func TestRunContextGetEnv(t *testing.T) {
|
||||
var jobEnv yaml.Node
|
||||
err := jobEnv.Encode(map[string]string{"JOB_ONLY": "job-value"})
|
||||
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
||||
|
||||
tests := []struct {
|
||||
description string
|
||||
rc *RunContext
|
||||
@@ -612,6 +616,26 @@ func TestRunContextGetEnv(t *testing.T) {
|
||||
targetEnv: "OVERWRITTEN",
|
||||
want: "false",
|
||||
},
|
||||
{
|
||||
description: "Pre-populated run context env should still include job env",
|
||||
rc: &RunContext{
|
||||
Config: &Config{},
|
||||
Env: map[string]string{
|
||||
"RUNTIME_ONLY": "true",
|
||||
},
|
||||
Run: &model.Run{
|
||||
JobID: "test",
|
||||
Workflow: &model.Workflow{
|
||||
Jobs: map[string]*model.Job{"test": {
|
||||
Name: "test",
|
||||
Env: jobEnv,
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
targetEnv: "JOB_ONLY",
|
||||
want: "job-value",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -622,6 +646,37 @@ func TestRunContextGetEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunContextGetEnvKeepsExpressionEvaluatorEnvCurrent(t *testing.T) {
|
||||
var jobEnv yaml.Node
|
||||
err := jobEnv.Encode(map[string]string{"JOB_ONLY": "job-value"})
|
||||
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
||||
|
||||
rc := &RunContext{
|
||||
Config: &Config{},
|
||||
Env: map[string]string{
|
||||
"RUNTIME_ONLY": "true",
|
||||
},
|
||||
Run: &model.Run{
|
||||
JobID: "test",
|
||||
Workflow: &model.Workflow{
|
||||
Jobs: map[string]*model.Job{"test": {
|
||||
Name: "test",
|
||||
Env: jobEnv,
|
||||
}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
rc.ExprEval = rc.NewExpressionEvaluator(context.Background())
|
||||
rc.GetEnv()
|
||||
rc.setEnv(context.Background(), map[string]string{"name": "STEP_TIMEOUT"}, "0")
|
||||
|
||||
got, evalErr := rc.ExprEval.evaluate(context.Background(), "env.STEP_TIMEOUT", exprparser.DefaultStatusCheckNone)
|
||||
assert.NoError(t, evalErr) //nolint:testifylint // pre-existing issue from nektos/act
|
||||
assert.EqualValues(t, "0", got)
|
||||
assert.EqualValues(t, "job-value", rc.Env["JOB_ONLY"]) //nolint:testifylint // pre-existing issue from nektos/act
|
||||
}
|
||||
|
||||
func Test_createSimpleContainerName(t *testing.T) {
|
||||
tests := []struct {
|
||||
parts []string
|
||||
|
||||
@@ -120,6 +120,10 @@ func TestSetupEnv(t *testing.T) {
|
||||
cm := &containerMock{}
|
||||
sm := &stepMock{}
|
||||
|
||||
var jobEnv yaml.Node
|
||||
err := jobEnv.Encode(map[string]string{"JOB_KEY": "jobvalue"})
|
||||
assert.NoError(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
||||
|
||||
rc := &RunContext{
|
||||
Config: &Config{
|
||||
Env: map[string]string{
|
||||
@@ -131,9 +135,7 @@ func TestSetupEnv(t *testing.T) {
|
||||
Workflow: &model.Workflow{
|
||||
Jobs: map[string]*model.Job{
|
||||
"1": {
|
||||
Env: yaml.Node{
|
||||
Value: "JOB_KEY: jobvalue",
|
||||
},
|
||||
Env: jobEnv,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -155,7 +157,7 @@ func TestSetupEnv(t *testing.T) {
|
||||
sm.On("getStepModel").Return(step)
|
||||
sm.On("getEnv").Return(&env)
|
||||
|
||||
err := setupEnv(context.Background(), sm)
|
||||
err = setupEnv(context.Background(), sm)
|
||||
assert.Nil(t, err) //nolint:testifylint // pre-existing issue from nektos/act
|
||||
|
||||
// These are commit or system specific
|
||||
@@ -191,6 +193,7 @@ func TestSetupEnv(t *testing.T) {
|
||||
"GITHUB_SERVER_URL": "https://",
|
||||
"GITHUB_WORKFLOW": "",
|
||||
"INPUT_STEP_WITH": "with-value",
|
||||
"JOB_KEY": "jobvalue",
|
||||
"RC_KEY": "rcvalue",
|
||||
"RUNNER_PERFLOG": "/dev/null",
|
||||
"RUNNER_TRACKING_ID": "",
|
||||
|
||||
Reference in New Issue
Block a user