local actions done
This commit is contained in:
parent
ac1bd0893e
commit
94591c58d7
4 changed files with 105 additions and 113 deletions
|
@ -70,7 +70,7 @@ func (cr *containerReference) Create() common.Executor {
|
||||||
}
|
}
|
||||||
func (cr *containerReference) Start(attach bool) common.Executor {
|
func (cr *containerReference) Start(attach bool) common.Executor {
|
||||||
return common.
|
return common.
|
||||||
NewDebugExecutor("%sdocker run image=%s entrypoint=%+q cmd=%+q", logPrefix, cr.input.Image, cr.input.Entrypoint, cr.input.Cmd).
|
NewInfoExecutor("%sdocker run image=%s entrypoint=%+q cmd=%+q", logPrefix, cr.input.Image, cr.input.Entrypoint, cr.input.Cmd).
|
||||||
Then(
|
Then(
|
||||||
common.NewPipelineExecutor(
|
common.NewPipelineExecutor(
|
||||||
cr.connect(),
|
cr.connect(),
|
||||||
|
@ -173,9 +173,9 @@ func (cr *containerReference) remove() common.Executor {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
cr.id = ""
|
|
||||||
|
|
||||||
logger.Debugf("Removed container: %v", cr.id)
|
logger.Debugf("Removed container: %v", cr.id)
|
||||||
|
cr.id = ""
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,10 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
||||||
Name: "workflow/event.json",
|
Name: "workflow/event.json",
|
||||||
Mode: 644,
|
Mode: 644,
|
||||||
Body: rc.EventJSON,
|
Body: rc.EventJSON,
|
||||||
|
}, &container.FileEntry{
|
||||||
|
Name: "home/.actions/.keep",
|
||||||
|
Mode: 644,
|
||||||
|
Body: "",
|
||||||
}),
|
}),
|
||||||
)(ctx)
|
)(ctx)
|
||||||
}
|
}
|
||||||
|
@ -202,68 +206,14 @@ func mergeMaps(maps ...map[string]string) map[string]string {
|
||||||
return rtnMap
|
return rtnMap
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (rc *RunContext) runContainer(containerSpec *model.ContainerSpec) common.Executor {
|
|
||||||
return func(ctx context.Context) error {
|
|
||||||
ghReader, err := rc.createGithubTarball()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
envList := make([]string, 0)
|
|
||||||
for k, v := range containerSpec.Env {
|
|
||||||
envList = append(envList, fmt.Sprintf("%s=%s", k, v))
|
|
||||||
}
|
|
||||||
var cmd, entrypoint []string
|
|
||||||
if containerSpec.Args != "" {
|
|
||||||
cmd = strings.Fields(rc.ExprEval.Interpolate(containerSpec.Args))
|
|
||||||
}
|
|
||||||
if containerSpec.Entrypoint != "" {
|
|
||||||
entrypoint = strings.Fields(rc.ExprEval.Interpolate(containerSpec.Entrypoint))
|
|
||||||
}
|
|
||||||
|
|
||||||
rawLogger := common.Logger(ctx).WithField("raw_output", true)
|
|
||||||
logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) {
|
|
||||||
if rc.Config.LogOutput {
|
|
||||||
rawLogger.Infof(s)
|
|
||||||
} else {
|
|
||||||
rawLogger.Debugf(s)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
c := container.NewContainer(&container.NewContainerInput{
|
|
||||||
Cmd: cmd,
|
|
||||||
Entrypoint: entrypoint,
|
|
||||||
Image: containerSpec.Image,
|
|
||||||
WorkingDir: "/github/workspace",
|
|
||||||
Env: envList,
|
|
||||||
Name: containerSpec.Name,
|
|
||||||
Binds: []string{
|
|
||||||
fmt.Sprintf("%s:%s", rc.Config.Workdir, "/github/workspace"),
|
|
||||||
fmt.Sprintf("%s:%s", rc.Tempdir, "/github/home"),
|
|
||||||
fmt.Sprintf("%s:%s", "/var/run/docker.sock", "/var/run/docker.sock"),
|
|
||||||
},
|
|
||||||
Stdout: logWriter,
|
|
||||||
Stderr: logWriter,
|
|
||||||
})
|
|
||||||
|
|
||||||
return c.Create().
|
|
||||||
Then(c.Copy("/github", ghReader)).
|
|
||||||
Then(c.Start()).
|
|
||||||
Finally(c.Remove().IfBool(!rc.Config.ReuseContainers))(ctx)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
func createContainerName(parts ...string) string {
|
func createContainerName(parts ...string) string {
|
||||||
name := make([]string, 0)
|
name := make([]string, 0)
|
||||||
pattern := regexp.MustCompile("[^a-zA-Z0-9]")
|
pattern := regexp.MustCompile("[^a-zA-Z0-9]")
|
||||||
|
partLen := (30 / len(parts)) - 1
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
name = append(name, pattern.ReplaceAllString(part, "-"))
|
name = append(name, trimToLen(pattern.ReplaceAllString(part, "-"), partLen))
|
||||||
}
|
}
|
||||||
return trimToLen(strings.Join(name, "-"), 30)
|
return strings.Join(name, "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
func trimToLen(s string, l int) string {
|
func trimToLen(s string, l int) string {
|
||||||
|
|
|
@ -3,6 +3,8 @@ package runner
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -18,6 +20,7 @@ type StepContext struct {
|
||||||
Step *model.Step
|
Step *model.Step
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
Cmd []string
|
Cmd []string
|
||||||
|
Action *model.Action
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *StepContext) execJobContainer() common.Executor {
|
func (sc *StepContext) execJobContainer() common.Executor {
|
||||||
|
@ -45,15 +48,13 @@ func (sc *StepContext) Executor() common.Executor {
|
||||||
sc.runUsesContainer(),
|
sc.runUsesContainer(),
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
case model.StepTypeUsesActionLocal:
|
case model.StepTypeUsesActionLocal:
|
||||||
return common.NewPipelineExecutor(
|
return common.NewPipelineExecutor(
|
||||||
sc.setupEnv(),
|
sc.setupEnv(),
|
||||||
sc.setupAction(),
|
sc.setupAction(),
|
||||||
applyWith(containerSpec, step),
|
sc.runAction(),
|
||||||
rc.pullImage(containerSpec),
|
|
||||||
rc.runContainer(containerSpec),
|
|
||||||
)
|
)
|
||||||
|
/*
|
||||||
case model.StepTypeUsesActionRemote:
|
case model.StepTypeUsesActionRemote:
|
||||||
remoteAction := newRemoteAction(step.Uses)
|
remoteAction := newRemoteAction(step.Uses)
|
||||||
if remoteAction.Org == "actions" && remoteAction.Repo == "checkout" {
|
if remoteAction.Org == "actions" && remoteAction.Repo == "checkout" {
|
||||||
|
@ -198,8 +199,6 @@ func (sc *StepContext) runUsesContainer() common.Executor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
func (sc *StepContext) setupAction() common.Executor {
|
func (sc *StepContext) setupAction() common.Executor {
|
||||||
rc := sc.RunContext
|
rc := sc.RunContext
|
||||||
step := sc.Step
|
step := sc.Step
|
||||||
|
@ -215,20 +214,64 @@ func (sc *StepContext) setupAction() common.Executor {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
action, err := model.ReadAction(f)
|
sc.Action, err = model.ReadAction(f)
|
||||||
if err != nil {
|
log.Debugf("Read action %v from '%s'", sc.Action, f.Name())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *StepContext) runAction() common.Executor {
|
||||||
|
rc := sc.RunContext
|
||||||
|
step := sc.Step
|
||||||
|
return func(ctx context.Context) error {
|
||||||
|
action := sc.Action
|
||||||
|
log.Debugf("About to run action %v", action)
|
||||||
for inputID, input := range action.Inputs {
|
for inputID, input := range action.Inputs {
|
||||||
envKey := regexp.MustCompile("[^A-Z0-9-]").ReplaceAllString(strings.ToUpper(inputID), "_")
|
envKey := regexp.MustCompile("[^A-Z0-9-]").ReplaceAllString(strings.ToUpper(inputID), "_")
|
||||||
envKey = fmt.Sprintf("INPUT_%s", envKey)
|
envKey = fmt.Sprintf("INPUT_%s", envKey)
|
||||||
if _, ok := containerSpec.Env[envKey]; !ok {
|
if _, ok := sc.Env[envKey]; !ok {
|
||||||
containerSpec.Env[envKey] = input.Default
|
sc.Env[envKey] = input.Default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch action.Runs.Using {
|
switch action.Runs.Using {
|
||||||
|
case model.ActionRunsUsingNode12:
|
||||||
|
return rc.execJobContainer([]string{"node", action.Runs.Main}, sc.Env)(ctx)
|
||||||
|
case model.ActionRunsUsingDocker:
|
||||||
|
var prepImage common.Executor
|
||||||
|
var image string
|
||||||
|
if strings.HasPrefix(action.Runs.Image, "docker://") {
|
||||||
|
image = strings.TrimPrefix(action.Runs.Image, "docker://")
|
||||||
|
} else {
|
||||||
|
image = fmt.Sprintf("%s:%s", regexp.MustCompile("[^a-zA-Z0-9]").ReplaceAllString(step.Uses, "-"), "latest")
|
||||||
|
image = strings.TrimLeft(image, "-")
|
||||||
|
contextDir := filepath.Join(rc.Config.Workdir, step.Uses, action.Runs.Main)
|
||||||
|
prepImage = container.NewDockerBuildExecutor(container.NewDockerBuildExecutorInput{
|
||||||
|
ContextDir: contextDir,
|
||||||
|
ImageTag: image,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := strings.Fields(step.With["args"])
|
||||||
|
if len(cmd) == 0 {
|
||||||
|
cmd = action.Runs.Args
|
||||||
|
}
|
||||||
|
entrypoint := strings.Fields(step.With["entrypoint"])
|
||||||
|
if len(entrypoint) == 0 {
|
||||||
|
entrypoint = action.Runs.Entrypoint
|
||||||
|
}
|
||||||
|
stepContainer := sc.newStepContainer(ctx, image, cmd, entrypoint)
|
||||||
|
return common.NewPipelineExecutor(
|
||||||
|
prepImage,
|
||||||
|
stepContainer.Pull(rc.Config.ForcePull),
|
||||||
|
stepContainer.Remove().IfBool(!rc.Config.ReuseContainers),
|
||||||
|
stepContainer.Create(),
|
||||||
|
stepContainer.Start(true),
|
||||||
|
).Finally(
|
||||||
|
stepContainer.Remove().IfBool(!rc.Config.ReuseContainers),
|
||||||
|
)(ctx)
|
||||||
|
|
||||||
|
/*
|
||||||
case model.ActionRunsUsingNode12:
|
case model.ActionRunsUsingNode12:
|
||||||
if strings.HasPrefix(actionDir, rc.Config.Workdir) {
|
if strings.HasPrefix(actionDir, rc.Config.Workdir) {
|
||||||
containerSpec.Entrypoint = fmt.Sprintf("node /github/workspace/%s/%s", strings.TrimPrefix(actionDir, rc.Config.Workdir), action.Runs.Main)
|
containerSpec.Entrypoint = fmt.Sprintf("node /github/workspace/%s/%s", strings.TrimPrefix(actionDir, rc.Config.Workdir), action.Runs.Main)
|
||||||
|
@ -254,11 +297,11 @@ func (sc *StepContext) setupAction() common.Executor {
|
||||||
ImageTag: containerSpec.Image,
|
ImageTag: containerSpec.Image,
|
||||||
})(ctx)
|
})(ctx)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
type remoteAction struct {
|
type remoteAction struct {
|
||||||
Org string
|
Org string
|
||||||
|
|
1
pkg/runner/testdata/basic/push.yml
vendored
1
pkg/runner/testdata/basic/push.yml
vendored
|
@ -10,7 +10,6 @@ jobs:
|
||||||
- run: cat /github/sha.txt | grep ${GITHUB_SHA}
|
- run: cat /github/sha.txt | grep ${GITHUB_SHA}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
if: false
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [check]
|
needs: [check]
|
||||||
steps:
|
steps:
|
||||||
|
|
Loading…
Reference in a new issue