diff --git a/pkg/model/workflow.go b/pkg/model/workflow.go index eb55d39..b51a59d 100644 --- a/pkg/model/workflow.go +++ b/pkg/model/workflow.go @@ -56,7 +56,7 @@ func (w *Workflow) On() []string { type Job struct { Name string `yaml:"name"` RawNeeds yaml.Node `yaml:"needs"` - RunsOn string `yaml:"runs-on"` + RawRunsOn yaml.Node `yaml:"runs-on"` Env map[string]string `yaml:"env"` If string `yaml:"if"` Steps []*Step `yaml:"steps"` @@ -115,6 +115,28 @@ func (j *Job) Needs() []string { return nil } +// RunsOn list for Job +func (j *Job) RunsOn() []string { + + switch j.RawRunsOn.Kind { + case yaml.ScalarNode: + var val string + err := j.RawRunsOn.Decode(&val) + if err != nil { + log.Fatal(err) + } + return []string{val} + case yaml.SequenceNode: + var val []string + err := j.RawRunsOn.Decode(&val) + if err != nil { + log.Fatal(err) + } + return val + } + return nil +} + // GetMatrixes returns the matrix cross product func (j *Job) GetMatrixes() []map[string]interface{} { matrixes := make([]map[string]interface{}, 0) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index e771111..6d9c387 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -55,16 +55,7 @@ func (rc *RunContext) jobContainerName() string { } func (rc *RunContext) startJobContainer() common.Executor { - job := rc.Run.Job() - - var image string - c := job.Container() - if c != nil { - image = c.Image - } else { - platformName := rc.ExprEval.Interpolate(job.RunsOn) - image = rc.Config.Platforms[strings.ToLower(platformName)] - } + image := rc.platformImage() return func(ctx context.Context) error { rawLogger := common.Logger(ctx).WithField("raw_output", true) @@ -221,6 +212,25 @@ func (rc *RunContext) newStepExecutor(step *model.Step) common.Executor { } } +func (rc *RunContext) platformImage() string { + job := rc.Run.Job() + + c := job.Container() + if c != nil { + return c.Image + } + + for _, runnerLabel := range job.RunsOn() { + platformName := rc.ExprEval.Interpolate(runnerLabel) + image := rc.Config.Platforms[strings.ToLower(platformName)] + if image != "" { + return image + } + } + + return "" +} + func (rc *RunContext) isEnabled(ctx context.Context) bool { job := rc.Run.Job() log := common.Logger(ctx) @@ -229,9 +239,9 @@ func (rc *RunContext) isEnabled(ctx context.Context) bool { return false } - platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn) - if img, ok := rc.Config.Platforms[strings.ToLower(platformName)]; !ok || img == "" { - log.Infof("\U0001F6A7 Skipping unsupported platform '%s'", platformName) + img := rc.platformImage() + if img == "" { + log.Infof("\U0001F6A7 Skipping unsupported platform '%+v'", job.RunsOn()) return false } return true diff --git a/pkg/runner/testdata/runs-on/push.yml b/pkg/runner/testdata/runs-on/push.yml index a0e49eb..f6ecedb 100644 --- a/pkg/runner/testdata/runs-on/push.yml +++ b/pkg/runner/testdata/runs-on/push.yml @@ -8,3 +8,17 @@ jobs: - run: env - run: echo ${GITHUB_ACTOR} - run: echo ${GITHUB_ACTOR} | grep nektos/act + + many: + runs-on: [ubuntu-latest] + steps: + - run: env + - run: echo ${GITHUB_ACTOR} + - run: echo ${GITHUB_ACTOR} | grep nektos/act + + selfmany: + runs-on: [self-hosted, ubuntu-latest] + steps: + - run: env + - run: echo ${GITHUB_ACTOR} + - run: echo ${GITHUB_ACTOR} | grep nektos/act