From e12252a43a3f917b21fe4adff1ebe830b1ed3634 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Thu, 20 Apr 2023 16:24:31 +0800 Subject: [PATCH] Support intepolation for `env` of `services` (#47) Reviewed-on: https://gitea.com/gitea/act/pulls/47 Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- pkg/runner/run_context.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index ffd98d0..e7f9e2b 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -246,9 +246,13 @@ func (rc *RunContext) startJobContainer() common.Executor { // add service containers for name, spec := range rc.Run.Job().Services { - mergedEnv := envList + interpolatedEnvs := make(map[string]string, len(spec.Env)) for k, v := range spec.Env { - mergedEnv = append(mergedEnv, fmt.Sprintf("%s=%s", k, v)) + interpolatedEnvs[k] = rc.ExprEval.Interpolate(ctx, v) + } + envs := make([]string, 0, len(interpolatedEnvs)) + for k, v := range interpolatedEnvs { + envs = append(envs, fmt.Sprintf("%s=%s", k, v)) } serviceContainerName := createSimpleContainerName(rc.jobContainerName(), name) c := container.NewContainer(&container.NewContainerInput{ @@ -257,7 +261,7 @@ func (rc *RunContext) startJobContainer() common.Executor { Image: spec.Image, Username: username, Password: password, - Env: mergedEnv, + Env: envs, Mounts: map[string]string{ // TODO merge volumes name: ext.ToContainerPath(rc.Config.Workdir),