add support to override platform

Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Casey Lee
2020-02-19 22:16:40 -05:00
parent e4ee2ddab7
commit 543501a36a
8 changed files with 59 additions and 37 deletions

View File

@@ -102,7 +102,7 @@ func (rc *RunContext) Executor() common.Executor {
}
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
if img := platformImage(platformName); img == "" {
if img, ok := rc.Config.Platforms[strings.ToLower(platformName)]; !ok || img == "" {
log.Infof(" \U0001F6A7 Skipping unsupported platform '%s'", platformName)
return nil
}

View File

@@ -25,6 +25,7 @@ type Config struct {
ForcePull bool // force pulling of the image, if already present
LogOutput bool // log the output from docker run
Secrets map[string]string // list of secrets
Platforms map[string]string // list of platforms
}
type runnerImpl struct {

View File

@@ -51,7 +51,7 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
containerSpec.Options = job.Container.Options
} else {
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
containerSpec.Image = platformImage(platformName)
containerSpec.Image = rc.Config.Platforms[strings.ToLower(platformName)]
}
return common.NewPipelineExecutor(
rc.setupEnv(containerSpec, step),
@@ -162,24 +162,11 @@ func (rc *RunContext) setupShellCommand(containerSpec *model.ContainerSpec, shel
return err
}
containerPath := fmt.Sprintf("/github/home/%s", filepath.Base(tempScript.Name()))
containerSpec.Args = strings.Replace(shellCommand, "{0}", containerPath, 1)
containerSpec.Entrypoint = strings.Replace(shellCommand, "{0}", containerPath, 1)
return nil
}
}
func platformImage(platform string) string {
switch strings.ToLower(platform) {
case "ubuntu-latest", "ubuntu-18.04":
return "ubuntu:18.04"
case "ubuntu-16.04":
return "ubuntu:16.04"
case "windows-latest", "windows-2019", "macos-latest", "macos-10.15":
return ""
default:
return ""
}
}
func (rc *RunContext) setupAction(containerSpec *model.ContainerSpec, actionDir string) common.Executor {
return func(ctx context.Context) error {
f, err := os.Open(filepath.Join(actionDir, "action.yml"))

View File

@@ -2,8 +2,14 @@ name: basic
on: push
jobs:
check:
runs-on: ubuntu-latest
steps:
- run: echo 'hello world'
build:
runs-on: ubuntu-latest
needs: [check]
steps:
- uses: ./actions/action1
with: