From 6ab71ecebbc0d01a0e72aecd06a15277723b6031 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Mon, 19 Dec 2022 15:58:55 +0100 Subject: [PATCH] fix: align runner.os / runner.arch to known values (#1510) * fix: align runner.os / runner.arch to known values * . * . Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/container/host_environment.go | 26 ++++++++++++++++++++++++-- pkg/runner/run_context.go | 9 +++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/pkg/container/host_environment.go b/pkg/container/host_environment.go index 30cd500..ff21b0a 100644 --- a/pkg/container/host_environment.go +++ b/pkg/container/host_environment.go @@ -410,10 +410,32 @@ func (*HostEnvironment) JoinPathVariable(paths ...string) string { return strings.Join(paths, string(filepath.ListSeparator)) } +func goArchToActionArch(arch string) string { + archMapper := map[string]string{ + "x86_64": "X64", + "386": "x86", + "aarch64": "arm64", + } + if arch, ok := archMapper[arch]; ok { + return arch + } + return arch +} + +func goOsToActionOs(os string) string { + osMapper := map[string]string{ + "darwin": "macOS", + } + if os, ok := osMapper[os]; ok { + return os + } + return os +} + func (e *HostEnvironment) GetRunnerContext(ctx context.Context) map[string]interface{} { return map[string]interface{}{ - "os": runtime.GOOS, - "arch": runtime.GOARCH, + "os": goOsToActionOs(runtime.GOOS), + "arch": goArchToActionArch(runtime.GOARCH), "temp": e.TmpDir, "tool_cache": e.ToolCache, } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 538e75c..c9c8ea1 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -179,10 +179,11 @@ func (rc *RunContext) startHostEnvironment() common.Executor { StdOut: logWriter, } rc.cleanUpJobContainer = rc.JobContainer.Remove() - rc.Env["RUNNER_TOOL_CACHE"] = toolCache - rc.Env["RUNNER_OS"] = runtime.GOOS - rc.Env["RUNNER_ARCH"] = runtime.GOARCH - rc.Env["RUNNER_TEMP"] = runnerTmp + for k, v := range rc.JobContainer.GetRunnerContext(ctx) { + if v, ok := v.(string); ok { + rc.Env[fmt.Sprintf("RUNNER_%s", strings.ToUpper(k))] = v + } + } for _, env := range os.Environ() { i := strings.Index(env, "=") if i > 0 {