From 2b471fbff0f5613c82c3442f55e64c4ea28bc8cf Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Tue, 15 Jan 2019 09:57:36 -0800 Subject: [PATCH] fix #2 - add support for an array of 'Runs' --- actions/parser.go | 27 ++++++++++++++++++++++++++- actions/runner.go | 1 + actions/types.go | 2 +- common/git.go | 4 +++- container/docker_run.go | 16 ++++------------ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/actions/parser.go b/actions/parser.go index 6fae1dd..c787172 100644 --- a/actions/parser.go +++ b/actions/parser.go @@ -2,12 +2,15 @@ package actions import ( "bytes" + "fmt" "io/ioutil" "os" "path/filepath" + "strings" "github.com/hashicorp/hcl" "github.com/hashicorp/hcl/hcl/ast" + "github.com/hashicorp/hcl/hcl/token" log "github.com/sirupsen/logrus" ) @@ -64,11 +67,33 @@ func cleanWorkflowsAST(node ast.Node) (ast.Node, bool) { // handle condition where value is a string but should be a list switch key { - case "resolves", "needs", "args": + case "args", "runs": + if literalType, ok := objectItem.Val.(*ast.LiteralType); ok { + listType := new(ast.ListType) + parts := strings.Split(literalType.Token.Value().(string), " ") + log.Debugf("got list: %v", parts) + if len(parts) > 0 { + quote := literalType.Token.Text[0] + for _, part := range parts { + part = fmt.Sprintf("%c%s%c", quote, part, quote) + log.Debugf("Adding part %s", part) + listType.Add(&ast.LiteralType{ + Token: token.Token{ + Type: token.STRING, + Text: part, + }, + }) + } + } + objectItem.Val = listType + + } + case "resolves", "needs": if literalType, ok := objectItem.Val.(*ast.LiteralType); ok { listType := new(ast.ListType) listType.Add(literalType) objectItem.Val = listType + } } } diff --git a/actions/runner.go b/actions/runner.go index 472ba5a..acc8a6b 100644 --- a/actions/runner.go +++ b/actions/runner.go @@ -216,6 +216,7 @@ func (action *actionDef) asExecutor(ctx context.Context, dryrun bool, workingDir executors = append(executors, container.NewDockerRunExecutor(container.NewDockerRunExecutorInput{ DockerExecutorInput: in, Cmd: action.Args, + Entrypoint: action.Runs, Image: image, WorkingDir: "/github/workspace", Env: env, diff --git a/actions/types.go b/actions/types.go index 334503d..1677792 100644 --- a/actions/types.go +++ b/actions/types.go @@ -41,7 +41,7 @@ type workflowDef struct { type actionDef struct { Needs []string Uses string - Runs string + Runs []string Args []string Env map[string]string Secrets []string diff --git a/common/git.go b/common/git.go index 549727b..c9154b1 100644 --- a/common/git.go +++ b/common/git.go @@ -204,7 +204,9 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { return err } - w.Pull(&git.PullOptions{}) + w.Pull(&git.PullOptions{ + ReferenceName: refName, + }) input.Logger.Debugf("Cloned %s to %s", input.URL.String(), input.Dir) err = w.Checkout(&git.CheckoutOptions{ diff --git a/container/docker_run.go b/container/docker_run.go index 689b47a..4c12ae4 100644 --- a/container/docker_run.go +++ b/container/docker_run.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "strings" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" @@ -19,7 +18,7 @@ import ( type NewDockerRunExecutorInput struct { DockerExecutorInput Image string - Entrypoint string + Entrypoint []string Cmd []string WorkingDir string Env []string @@ -33,7 +32,7 @@ type NewDockerRunExecutorInput struct { func NewDockerRunExecutor(input NewDockerRunExecutorInput) common.Executor { return func() error { - input.Logger.Infof("docker run %s %s", input.Image, input.Cmd) + input.Logger.Infof("docker run %s %s %s", input.Image, input.Entrypoint, input.Cmd) if input.Dryrun { return nil } @@ -73,14 +72,10 @@ func NewDockerRunExecutor(input NewDockerRunExecutorInput) common.Executor { func createContainer(input NewDockerRunExecutorInput, cli *client.Client) (string, error) { isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) - cmd := input.Cmd - if len(input.Cmd) == 1 { - cmd = strings.Split(cmd[0], " ") - } - config := &container.Config{ Image: input.Image, - Cmd: cmd, + Cmd: input.Cmd, + Entrypoint: input.Entrypoint, WorkingDir: input.WorkingDir, Env: input.Env, Tty: isTerminal, @@ -93,9 +88,6 @@ func createContainer(input NewDockerRunExecutorInput, cli *client.Client) (strin } } - if input.Entrypoint != "" { - config.Entrypoint = []string{input.Entrypoint} - } resp, err := cli.ContainerCreate(input.Ctx, config, &container.HostConfig{ Binds: input.Binds, }, nil, input.Name)