diff --git a/actions/testdata/basic.workflow b/actions/testdata/basic.workflow index 691c643..c3e829c 100644 --- a/actions/testdata/basic.workflow +++ b/actions/testdata/basic.workflow @@ -10,7 +10,7 @@ action "build" { action "test" { uses = "docker://ubuntu:18.04" - args = "echo 'test'" + args = "env" needs = ["build"] } diff --git a/actions/testdata/gitref.workflow b/actions/testdata/gitref.workflow new file mode 100644 index 0000000..1cd47e0 --- /dev/null +++ b/actions/testdata/gitref.workflow @@ -0,0 +1,14 @@ +workflow "New workflow" { + on = "push" + resolves = ["branch-ref","commit-ref"] +} + +action "branch-ref" { + uses = "actions/docker/cli@master" + args = "version" +} + +action "commit-ref" { + uses = "actions/docker/cli@c08a5fc9e0286844156fefff2c141072048141f6" + args = "version" +} \ No newline at end of file diff --git a/common/git.go b/common/git.go index 13ba819..a2f7925 100644 --- a/common/git.go +++ b/common/git.go @@ -194,7 +194,7 @@ type NewGitCloneExecutorInput struct { // NewGitCloneExecutor creates an executor to clone git repos func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { return func() error { - input.Logger.Infof("git clone '%s'", input.URL) + input.Logger.Infof("git clone '%s' # ref=%s", input.URL, input.Ref) input.Logger.Debugf(" cloning %s to %s", input.URL, input.Dir) if input.Dryrun { @@ -209,11 +209,12 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { r, err := git.PlainOpen(input.Dir) if err != nil { r, err = git.PlainClone(input.Dir, false, &git.CloneOptions{ - URL: input.URL, - Progress: input.Logger.WriterLevel(log.DebugLevel), - ReferenceName: refName, + URL: input.URL, + Progress: input.Logger.WriterLevel(log.DebugLevel), + //ReferenceName: refName, }) if err != nil { + input.Logger.Errorf("Unable to clone %v %s: %v", input.URL, refName, err) return err } } @@ -224,17 +225,24 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor { } err = w.Pull(&git.PullOptions{ - ReferenceName: refName, - Force: true, + //ReferenceName: refName, + Force: true, }) if err != nil && err.Error() != "already up-to-date" { input.Logger.Errorf("Unable to pull %s: %v", refName, err) } input.Logger.Debugf("Cloned %s to %s", input.URL, input.Dir) + hash, err := r.ResolveRevision(plumbing.Revision(input.Ref)) + if err != nil { + input.Logger.Errorf("Unable to resolve %s: %v", input.Ref, err) + return err + } + err = w.Checkout(&git.CheckoutOptions{ - Branch: refName, - Force: true, + //Branch: refName, + Hash: *hash, + Force: true, }) if err != nil { input.Logger.Errorf("Unable to checkout %s: %v", refName, err) diff --git a/container/docker_run.go b/container/docker_run.go index 314facb..246fca2 100644 --- a/container/docker_run.go +++ b/container/docker_run.go @@ -204,7 +204,7 @@ func waitContainer(input NewDockerRunExecutorInput, cli *client.Client, containe if statusCode == 0 { return nil } else if statusCode == 78 { - return fmt.Errorf("exiting with `NEUTRAL`: 78") + return fmt.Errorf("exit with `NEUTRAL`: 78") } return fmt.Errorf("exit with `FAILURE`: %v", statusCode)