From e1b906813e9053c57ef1c9f7d535532cd7924602 Mon Sep 17 00:00:00 2001 From: Fabian Kammel Date: Mon, 29 Aug 2022 17:39:31 +0200 Subject: [PATCH] support runner.arch (#1290) * support runner.arch Signed-off-by: Fabian Kammel * add arch to runner definition Signed-off-by: Fabian Kammel * get architecture from docker Signed-off-by: Fabian Kammel * Update pkg/container/docker_run.go Co-authored-by: ChristopherHX * lint: goimport file Signed-off-by: Fabian Kammel Co-authored-by: Casey Lee Co-authored-by: ChristopherHX Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/container/docker_run.go | 20 ++++++++++++++++++++ pkg/runner/action.go | 1 + pkg/runner/expression.go | 3 +++ pkg/runner/run_context.go | 1 + pkg/runner/step_docker.go | 1 + 5 files changed, 26 insertions(+) diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index db46412..146560e 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -276,6 +276,26 @@ func GetHostInfo(ctx context.Context) (info types.Info, err error) { return info, nil } +// Arch fetches values from docker info and translates architecture to +// GitHub actions compatible runner.arch values +// https://github.com/github/docs/blob/main/data/reusables/actions/runner-arch-description.md +func RunnerArch(ctx context.Context) string { + info, err := GetHostInfo(ctx) + if err != nil { + return "" + } + + archMapper := map[string]string{ + "x86_64": "X64", + "386": "x86", + "aarch64": "arm64", + } + if arch, ok := archMapper[info.Architecture]; ok { + return arch + } + return info.Architecture +} + func (cr *containerReference) connect() common.Executor { return func(ctx context.Context) error { if cr.cli != nil { diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 72970f4..85e18e0 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -346,6 +346,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache")) envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_OS", "Linux")) + envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx))) envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp")) binds, mounts := rc.GetBindsAndMounts() diff --git a/pkg/runner/expression.go b/pkg/runner/expression.go index ab54e5e..d803446 100644 --- a/pkg/runner/expression.go +++ b/pkg/runner/expression.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/nektos/act/pkg/common" + "github.com/nektos/act/pkg/container" "github.com/nektos/act/pkg/exprparser" "gopkg.in/yaml.v3" ) @@ -47,6 +48,7 @@ func (rc *RunContext) NewExpressionEvaluator(ctx context.Context) ExpressionEval Steps: rc.getStepsContext(), Runner: map[string]interface{}{ "os": "Linux", + "arch": container.RunnerArch(ctx), "temp": "/tmp", "tool_cache": "/opt/hostedtoolcache", }, @@ -92,6 +94,7 @@ func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step) Steps: rc.getStepsContext(), Runner: map[string]interface{}{ "os": "Linux", + "arch": container.RunnerArch(ctx), "temp": "/tmp", "tool_cache": "/opt/hostedtoolcache", }, diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index acbff9b..89608ad 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -149,6 +149,7 @@ func (rc *RunContext) startJobContainer() common.Executor { envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache")) envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_OS", "Linux")) + envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx))) envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp")) binds, mounts := rc.GetBindsAndMounts() diff --git a/pkg/runner/step_docker.go b/pkg/runner/step_docker.go index 0130b83..6d625ee 100644 --- a/pkg/runner/step_docker.go +++ b/pkg/runner/step_docker.go @@ -105,6 +105,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd [] envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TOOL_CACHE", "/opt/hostedtoolcache")) envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_OS", "Linux")) + envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_ARCH", container.RunnerArch(ctx))) envList = append(envList, fmt.Sprintf("%s=%s", "RUNNER_TEMP", "/tmp")) binds, mounts := rc.GetBindsAndMounts()