feat: support PlatformPicker

This commit is contained in:
Jason Song 2022-11-22 16:39:19 +08:00
parent 64cae197a4
commit c6b8548d35
No known key found for this signature in database
GPG key ID: 8402EEEE4511A8B5
2 changed files with 20 additions and 9 deletions

View file

@ -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
}

View file

@ -62,6 +62,7 @@ type Config struct {
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