+2
-2
.tangled/workflows/test.yaml
.tangled/workflows/test.yml
+2
-2
.tangled/workflows/test.yaml
.tangled/workflows/test.yml
+1
-1
spindle/models/pipeline.go
+1
-1
spindle/models/pipeline.go
···
68
68
setup := &setupSteps{}
69
69
70
70
setup.addStep(nixConfStep())
71
-
setup.addStep(cloneStep(*twf, *pl.TriggerMetadata.Repo, cfg.Server.Dev))
71
+
setup.addStep(cloneStep(*twf, *pl.TriggerMetadata, cfg.Server.Dev))
72
72
setup.addStep(checkoutStep(*twf, *pl.TriggerMetadata))
73
73
// this step could be empty
74
74
if s := dependencyStep(*twf); s != nil {
+23
-4
spindle/models/setup_steps.go
+23
-4
spindle/models/setup_steps.go
···
5
5
"path"
6
6
"strings"
7
7
8
+
"github.com/go-git/go-git/v5/plumbing"
8
9
"tangled.sh/tangled.sh/core/api/tangled"
10
+
"tangled.sh/tangled.sh/core/workflow"
9
11
)
10
12
11
13
func nixConfStep() Step {
···
45
47
46
48
// cloneOptsAsSteps processes clone options and adds corresponding steps
47
49
// to the beginning of the workflow's step list if cloning is not skipped.
48
-
func cloneStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerRepo, dev bool) Step {
50
+
func cloneStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata, dev bool) Step {
49
51
if twf.Clone.Skip {
50
52
return Step{}
51
53
}
···
53
55
uri := "https://"
54
56
if dev {
55
57
uri = "http://"
56
-
tr.Knot = strings.ReplaceAll(tr.Knot, "localhost", "host.docker.internal")
58
+
tr.Repo.Knot = strings.ReplaceAll(tr.Repo.Knot, "localhost", "host.docker.internal")
57
59
}
58
60
59
-
cloneUrl := uri + path.Join(tr.Knot, tr.Did, tr.Repo)
61
+
cloneUrl := uri + path.Join(tr.Repo.Knot, tr.Repo.Did, tr.Repo.Repo)
60
62
cloneCmd := []string{"git", "clone", cloneUrl, "."}
61
63
62
64
// default clone depth is 1
···
64
66
if twf.Clone.Depth > 1 {
65
67
cloneDepth = int(twf.Clone.Depth)
66
68
}
67
-
cloneCmd = append(cloneCmd, []string{"--depth", fmt.Sprintf("%d", cloneDepth)}...)
69
+
cloneCmd = append(cloneCmd, fmt.Sprintf("--depth=%d", cloneDepth))
70
+
71
+
// select the clone branch
72
+
cloneBranch := ""
73
+
switch tr.Kind {
74
+
case workflow.TriggerKindManual:
75
+
// TODO: unimplemented
76
+
case workflow.TriggerKindPush:
77
+
ref := tr.Push.Ref
78
+
refName := plumbing.ReferenceName(ref)
79
+
cloneBranch = refName.Short()
80
+
case workflow.TriggerKindPullRequest:
81
+
cloneBranch = tr.PullRequest.SourceBranch
82
+
}
83
+
84
+
if cloneBranch != "" {
85
+
cloneCmd = append(cloneCmd, fmt.Sprintf("--branch=%s", cloneBranch))
86
+
}
68
87
69
88
if twf.Clone.Submodules {
70
89
cloneCmd = append(cloneCmd, "--recursive")