* Add support for runs-on array form (closes #146) * Fixed style issues Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
parent
fea9a8afa5
commit
4a4bd36cf6
3 changed files with 60 additions and 14 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
14
pkg/runner/testdata/runs-on/push.yml
vendored
14
pkg/runner/testdata/runs-on/push.yml
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue