fix #24 - support both branch refs and hash refs
This commit is contained in:
parent
ecae898a7b
commit
bc5c23e8e4
|
@ -10,7 +10,7 @@ action "build" {
|
|||
|
||||
action "test" {
|
||||
uses = "docker://ubuntu:18.04"
|
||||
args = "echo 'test'"
|
||||
args = "env"
|
||||
needs = ["build"]
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue