From c6b8548d35ab4a5fc0f4478ef9f001ee4fbda16f Mon Sep 17 00:00:00 2001 From: Jason Song Date: Tue, 22 Nov 2022 16:39:19 +0800 Subject: [PATCH] feat: support PlatformPicker --- pkg/runner/run_context.go | 16 +++++++++++++--- pkg/runner/runner.go | 13 +++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index b6a149c..4b42cd1 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -299,9 +299,19 @@ func (rc *RunContext) platformImage(ctx context.Context) string { common.Logger(ctx).Errorf("'runs-on' key not defined in %s", rc.String()) } - for _, runnerLabel := range job.RunsOn() { - platformName := rc.ExprEval.Interpolate(ctx, runnerLabel) - image := rc.Config.Platforms[strings.ToLower(platformName)] + runsOn := job.RunsOn() + for i, v := range runsOn { + runsOn[i] = rc.ExprEval.Interpolate(ctx, v) + } + + if pick := rc.Config.PlatformPicker; pick != nil { + if image := pick(runsOn); image != "" { + return image + } + } + + for _, runnerLabel := range runsOn { + image := rc.Config.Platforms[strings.ToLower(runnerLabel)] if image != "" { return image } diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index c36fec4..0c2a988 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -56,12 +56,13 @@ type Config struct { ReplaceGheActionWithGithubCom []string // Use actions from GitHub Enterprise instance to GitHub ReplaceGheActionTokenWithGithubCom string // Token of private action repo on GitHub. - PresetGitHubContext *model.GithubContext // the preset github context, overrides some fields like DefaultBranch, Env, Secrets etc. - EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath - ContainerNamePrefix string // the prefix of container name - ContainerMaxLifetime time.Duration // the max lifetime of job containers - ContainerNetworkMode string // the network mode of job containers - DefaultActionInstance string // the default actions web site + PresetGitHubContext *model.GithubContext // the preset github context, overrides some fields like DefaultBranch, Env, Secrets etc. + EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath + ContainerNamePrefix string // the prefix of container name + ContainerMaxLifetime time.Duration // the max lifetime of job containers + ContainerNetworkMode string // the network mode of job containers + DefaultActionInstance string // the default actions web site + PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil } // Resolves the equivalent host path inside the container