skip unsupported platforms

Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Casey Lee 2020-02-16 22:04:13 -08:00
parent 73559207c7
commit 5b7019cd0b
No known key found for this signature in database
GPG Key ID: 1899120ECD0A1784
6 changed files with 23 additions and 14 deletions

View File

@ -62,8 +62,8 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
var eventName string var eventName string
if len(args) > 0 { if len(args) > 0 {
eventName = args[0] eventName = args[0]
} else if events := planner.GetEvents(); len(events) == 1 { } else if events := planner.GetEvents(); len(events) > 1 {
// set default event type if we only have a single workflow in the file. // set default event type to first event
// this way user dont have to specify the event. // this way user dont have to specify the event.
log.Debugf("Using detected workflow event: %s", events[0]) log.Debugf("Using detected workflow event: %s", events[0])
eventName = events[0] eventName = events[0]

View File

@ -42,7 +42,7 @@ func NewInfoExecutor(format string, args ...interface{}) Executor {
// NewPipelineExecutor creates a new executor from a series of other executors // NewPipelineExecutor creates a new executor from a series of other executors
func NewPipelineExecutor(executors ...Executor) Executor { func NewPipelineExecutor(executors ...Executor) Executor {
if executors == nil { if len(executors) == 0 {
return func(ctx context.Context) error { return func(ctx context.Context) error {
return nil return nil
} }

View File

@ -64,6 +64,7 @@ func NewWorkflowPlanner(dirname string) (WorkflowPlanner, error) {
return nil, err return nil, err
} }
log.Debugf("Reading workflow '%s'", f.Name())
workflow, err := ReadWorkflow(f) workflow, err := ReadWorkflow(f)
if err != nil { if err != nil {
f.Close() f.Close()

View File

@ -24,15 +24,16 @@ import (
// RunContext contains info about current job // RunContext contains info about current job
type RunContext struct { type RunContext struct {
Config *Config Config *Config
Matrix map[string]interface{} Matrix map[string]interface{}
Run *model.Run Run *model.Run
EventJSON string EventJSON string
Env map[string]string Env map[string]string
Tempdir string Tempdir string
ExtraPath []string ExtraPath []string
CurrentStep string CurrentStep string
StepResults map[string]*stepResult StepResults map[string]*stepResult
PlatformName string
} }
type stepResult struct { type stepResult struct {
@ -55,6 +56,10 @@ func (rc *RunContext) Close(ctx context.Context) error {
// Executor returns a pipeline executor for all the steps in the job // Executor returns a pipeline executor for all the steps in the job
func (rc *RunContext) Executor() common.Executor { func (rc *RunContext) Executor() common.Executor {
if img := platformImage(rc.PlatformName); img == "" {
return common.NewInfoExecutor(" \U0001F6A7 Skipping unsupported platform '%s'", rc.PlatformName)
}
err := rc.setupTempDir() err := rc.setupTempDir()
if err != nil { if err != nil {
return common.NewErrorExecutor(err) return common.NewErrorExecutor(err)

View File

@ -79,6 +79,9 @@ func (runner *runnerImpl) NewRunExecutor(run *model.Run, matrix map[string]inter
rc.EventJSON = runner.eventJSON rc.EventJSON = runner.eventJSON
rc.StepResults = make(map[string]*stepResult) rc.StepResults = make(map[string]*stepResult)
rc.Matrix = matrix rc.Matrix = matrix
ee := rc.NewExpressionEvaluator()
rc.PlatformName = ee.Interpolate(run.Job().RunsOn)
return func(ctx context.Context) error { return func(ctx context.Context) error {
ctx = WithJobLogger(ctx, rc.Run.String()) ctx = WithJobLogger(ctx, rc.Run.String())
return rc.Executor()(ctx) return rc.Executor()(ctx)

View File

@ -34,7 +34,7 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor {
containerSpec.Volumes = job.Container.Volumes containerSpec.Volumes = job.Container.Volumes
containerSpec.Options = job.Container.Options containerSpec.Options = job.Container.Options
} else { } else {
containerSpec.Image = platformImage(ee.Interpolate(job.RunsOn)) containerSpec.Image = platformImage(rc.PlatformName)
} }
return common.NewPipelineExecutor( return common.NewPipelineExecutor(
rc.setupShellCommand(containerSpec, step.Shell, step.Run), rc.setupShellCommand(containerSpec, step.Shell, step.Run),
@ -154,7 +154,7 @@ func (rc *RunContext) setupShellCommand(containerSpec *model.ContainerSpec, shel
} }
func platformImage(platform string) string { func platformImage(platform string) string {
switch platform { switch strings.ToLower(platform) {
case "ubuntu-latest", "ubuntu-18.04": case "ubuntu-latest", "ubuntu-18.04":
return "ubuntu:18.04" return "ubuntu:18.04"
case "ubuntu-16.04": case "ubuntu-16.04":