···
8
+
"tangled.sh/tangled.sh/core/api/tangled"
11
+
// checkoutStep checks out the specified ref in the cloned repository.
12
+
func checkoutStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata) Step {
21
+
case "pull_request":
22
+
ref = tr.PullRequest.TargetBranch
24
+
// TODO: this needs to be specified in lexicon
26
+
ref = tr.Repo.DefaultBranch
29
+
checkoutCmd := fmt.Sprintf("git config advice.detachedHead false; git checkout --progress --force %s", ref)
32
+
Command: checkoutCmd,
33
+
Name: "Checkout ref " + ref,
37
+
// cloneOptsAsSteps processes clone options and adds corresponding steps
38
+
// to the beginning of the workflow's step list if cloning is not skipped.
39
+
func cloneStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerRepo, dev bool) Step {
47
+
tr.Knot = strings.ReplaceAll(tr.Knot, "localhost", "host.docker.internal")
50
+
cloneUrl := uri + path.Join(tr.Knot, tr.Did, tr.Repo)
51
+
cloneCmd := []string{"git", "clone", cloneUrl, "."}
53
+
// default clone depth is 1
55
+
if twf.Clone.Depth > 1 {
56
+
cloneDepth = int(twf.Clone.Depth)
57
+
cloneCmd = append(cloneCmd, []string{"--depth", fmt.Sprintf("%d", cloneDepth)}...)
60
+
if twf.Clone.Submodules {
61
+
cloneCmd = append(cloneCmd, "--recursive")
64
+
fmt.Println(strings.Join(cloneCmd, " "))
67
+
Command: strings.Join(cloneCmd, " "),
68
+
Name: "Clone repository into workspace",
73
+
// dependencyStep processes dependencies defined in the workflow.
74
+
// For dependencies using a custom registry (i.e. not nixpkgs), it collects
75
+
// all packages and adds a single 'nix profile install' step to the
76
+
// beginning of the workflow's step list.
77
+
func dependencyStep(twf tangled.Pipeline_Workflow) Step {
78
+
var customPackages []string
80
+
for _, d := range twf.Dependencies {
81
+
registry := d.Registry
82
+
packages := d.Packages
84
+
if registry == "nixpkgs" {
88
+
// collect packages from custom registries
89
+
for _, pkg := range packages {
90
+
customPackages = append(customPackages, fmt.Sprintf("'%s#%s'", registry, pkg))
94
+
if len(customPackages) > 0 {
95
+
installCmd := "nix --extra-experimental-features nix-command --extra-experimental-features flakes profile install"
96
+
cmd := fmt.Sprintf("%s %s", installCmd, strings.Join(customPackages, " "))
97
+
installStep := Step{
99
+
Name: "Install custom dependencies",
100
+
Environment: map[string]string{
101
+
"NIX_NO_COLOR": "1",
102
+
"NIX_SHOW_DOWNLOAD_PROGRESS": "0",