parent
e739f72c5e
commit
21e2bb8657
6 changed files with 34 additions and 17 deletions
|
@ -1,7 +1,6 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
@ -39,7 +38,7 @@ func (r *Run) String() string {
|
||||||
if jobName == "" {
|
if jobName == "" {
|
||||||
jobName = r.JobID
|
jobName = r.JobID
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s/%s", r.Workflow.Name, jobName)
|
return jobName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Job returns the job for this Run
|
// Job returns the job for this Run
|
||||||
|
|
|
@ -272,7 +272,7 @@ func (rc *RunContext) vmRunner() func(*otto.Otto) {
|
||||||
runner := map[string]interface{}{
|
runner := map[string]interface{}{
|
||||||
"os": "Linux",
|
"os": "Linux",
|
||||||
"temp": "/tmp",
|
"temp": "/tmp",
|
||||||
"tool_cache": "/tmp",
|
"tool_cache": "/opt/hostedtoolcache",
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(vm *otto.Otto) {
|
return func(vm *otto.Otto) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
// RunContext contains info about current job
|
// RunContext contains info about current job
|
||||||
type RunContext struct {
|
type RunContext struct {
|
||||||
|
Name string
|
||||||
Config *Config
|
Config *Config
|
||||||
Matrix map[string]interface{}
|
Matrix map[string]interface{}
|
||||||
Run *model.Run
|
Run *model.Run
|
||||||
|
@ -32,6 +33,10 @@ type RunContext struct {
|
||||||
JobContainer container.Container
|
JobContainer container.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) String() string {
|
||||||
|
return fmt.Sprintf("%s/%s", rc.Run.Workflow.Name, rc.Name)
|
||||||
|
}
|
||||||
|
|
||||||
type stepResult struct {
|
type stepResult struct {
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
Outputs map[string]string `json:"outputs"`
|
Outputs map[string]string `json:"outputs"`
|
||||||
|
@ -46,7 +51,7 @@ func (rc *RunContext) GetEnv() map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RunContext) jobContainerName() string {
|
func (rc *RunContext) jobContainerName() string {
|
||||||
return createContainerName("act", rc.Run.String())
|
return createContainerName("act", rc.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *RunContext) startJobContainer() common.Executor {
|
func (rc *RunContext) startJobContainer() common.Executor {
|
||||||
|
@ -156,6 +161,14 @@ func (rc *RunContext) ActionCacheDir() string {
|
||||||
// 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 {
|
||||||
steps := make([]common.Executor, 0)
|
steps := make([]common.Executor, 0)
|
||||||
|
|
||||||
|
steps = append(steps, func(ctx context.Context) error {
|
||||||
|
if len(rc.Matrix) > 0 {
|
||||||
|
common.Logger(ctx).Infof("\U0001F9EA Matrix: %v", rc.Matrix)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
steps = append(steps, rc.startJobContainer())
|
steps = append(steps, rc.startJobContainer())
|
||||||
|
|
||||||
for i, step := range rc.Run.Job().Steps {
|
for i, step := range rc.Run.Job().Steps {
|
||||||
|
@ -209,7 +222,7 @@ func (rc *RunContext) isEnabled(ctx context.Context) bool {
|
||||||
|
|
||||||
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
|
platformName := rc.ExprEval.Interpolate(rc.Run.Job().RunsOn)
|
||||||
if img, ok := rc.Config.Platforms[strings.ToLower(platformName)]; !ok || img == "" {
|
if img, ok := rc.Config.Platforms[strings.ToLower(platformName)]; !ok || img == "" {
|
||||||
log.Infof(" \U0001F6A7 Skipping unsupported platform '%s'", platformName)
|
log.Infof("\U0001F6A7 Skipping unsupported platform '%s'", platformName)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -52,7 +52,7 @@ func New(runnerConfig *Config) (Runner, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
|
func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
|
||||||
maxJobNameLen := plan.MaxRunNameLen()
|
maxJobNameLen := 0
|
||||||
|
|
||||||
pipeline := make([]common.Executor, 0)
|
pipeline := make([]common.Executor, 0)
|
||||||
for _, stage := range plan.Stages {
|
for _, stage := range plan.Stages {
|
||||||
|
@ -61,16 +61,17 @@ func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
|
||||||
job := run.Job()
|
job := run.Job()
|
||||||
matrixes := job.GetMatrixes()
|
matrixes := job.GetMatrixes()
|
||||||
|
|
||||||
jobName := fmt.Sprintf("%-*s", maxJobNameLen, run.String())
|
for i, matrix := range matrixes {
|
||||||
for _, matrix := range matrixes {
|
rc := runner.newRunContext(run, matrix)
|
||||||
m := matrix
|
if len(matrix) > 1 {
|
||||||
runExecutor := runner.newRunExecutor(run, matrix)
|
rc.Name = fmt.Sprintf("%s-%d", rc.Name, i+1)
|
||||||
stageExecutor = append(stageExecutor, func(ctx context.Context) error {
|
|
||||||
ctx = WithJobLogger(ctx, jobName)
|
|
||||||
if len(m) > 0 {
|
|
||||||
common.Logger(ctx).Infof("\U0001F9EA Matrix: %v", m)
|
|
||||||
}
|
}
|
||||||
return runExecutor(ctx)
|
if len(rc.String()) > maxJobNameLen {
|
||||||
|
maxJobNameLen = len(rc.String())
|
||||||
|
}
|
||||||
|
stageExecutor = append(stageExecutor, func(ctx context.Context) error {
|
||||||
|
jobName := fmt.Sprintf("%-*s", maxJobNameLen, rc.String())
|
||||||
|
return rc.Executor()(WithJobLogger(ctx, jobName))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +81,7 @@ func (runner *runnerImpl) NewPlanExecutor(plan *model.Plan) common.Executor {
|
||||||
return common.NewPipelineExecutor(pipeline...)
|
return common.NewPipelineExecutor(pipeline...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runner *runnerImpl) newRunExecutor(run *model.Run, matrix map[string]interface{}) common.Executor {
|
func (runner *runnerImpl) newRunContext(run *model.Run, matrix map[string]interface{}) *RunContext {
|
||||||
rc := &RunContext{
|
rc := &RunContext{
|
||||||
Config: runner.config,
|
Config: runner.config,
|
||||||
Run: run,
|
Run: run,
|
||||||
|
@ -89,5 +90,6 @@ func (runner *runnerImpl) newRunExecutor(run *model.Run, matrix map[string]inter
|
||||||
Matrix: matrix,
|
Matrix: matrix,
|
||||||
}
|
}
|
||||||
rc.ExprEval = rc.NewExpressionEvaluator()
|
rc.ExprEval = rc.NewExpressionEvaluator()
|
||||||
return rc.Executor()
|
rc.Name = rc.ExprEval.Interpolate(run.String())
|
||||||
|
return rc
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,8 @@ func TestRunEvent(t *testing.T) {
|
||||||
{"remote-action-js", "push", ""},
|
{"remote-action-js", "push", ""},
|
||||||
{"local-action-docker-url", "push", ""},
|
{"local-action-docker-url", "push", ""},
|
||||||
{"local-action-dockerfile", "push", ""},
|
{"local-action-dockerfile", "push", ""},
|
||||||
|
{"matrix", "push", ""},
|
||||||
|
{"commands", "push", ""},
|
||||||
}
|
}
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
|
|
||||||
|
|
1
pkg/runner/testdata/matrix/push.yml
vendored
1
pkg/runner/testdata/matrix/push.yml
vendored
|
@ -3,6 +3,7 @@ on: push
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
name: PHP ${{ matrix.os }} ${{ matrix.node}}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- run: echo ${NODE_VERSION} | grep ${{ matrix.node }}
|
- run: echo ${NODE_VERSION} | grep ${{ matrix.node }}
|
||||||
|
|
Loading…
Reference in a new issue