forked from tangled.org/core
Something went wrong. Try again.
Go
at fix-env-test
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137package models
import ( "fmt" "path" "strings"
"github.com/go-git/go-git/v5/plumbing" "tangled.sh/tangled.sh/core/api/tangled" "tangled.sh/tangled.sh/core/workflow")
func nixConfStep() Step { setupCmd := `echo 'extra-experimental-features = nix-command flakes' >> /etc/nix/nix.confecho 'build-users-group = ' >> /etc/nix/nix.conf` return Step{ Command: setupCmd, Name: "Configure Nix", }}
// checkoutStep checks out the specified ref in the cloned repository.func checkoutStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata) Step { if twf.Clone.Skip { return Step{} }
var ref string switch tr.Kind { case "push": ref = tr.Push.NewSha case "pull_request": ref = tr.PullRequest.TargetBranch
// TODO: this needs to be specified in lexicon case "manual": ref = tr.Repo.DefaultBranch }
checkoutCmd := fmt.Sprintf("git config advice.detachedHead false; git checkout --progress --force %s", ref)
return Step{ Command: checkoutCmd, Name: "Checkout ref " + ref, }}
// cloneOptsAsSteps processes clone options and adds corresponding steps// to the beginning of the workflow's step list if cloning is not skipped.func cloneStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata, dev bool) Step { if twf.Clone.Skip { return Step{} }
uri := "https://" if dev { uri = "http://" tr.Repo.Knot = strings.ReplaceAll(tr.Repo.Knot, "localhost", "host.docker.internal") }
cloneUrl := uri + path.Join(tr.Repo.Knot, tr.Repo.Did, tr.Repo.Repo) cloneCmd := []string{"git", "clone", cloneUrl, "."}
// default clone depth is 1 cloneDepth := 1 if twf.Clone.Depth > 1 { cloneDepth = int(twf.Clone.Depth) } cloneCmd = append(cloneCmd, fmt.Sprintf("--depth=%d", cloneDepth))
// select the clone branch cloneBranch := "" switch tr.Kind { case workflow.TriggerKindManual: // TODO: unimplemented case workflow.TriggerKindPush: ref := tr.Push.Ref refName := plumbing.ReferenceName(ref) cloneBranch = refName.Short() case workflow.TriggerKindPullRequest: cloneBranch = tr.PullRequest.SourceBranch }
if cloneBranch != "" { cloneCmd = append(cloneCmd, fmt.Sprintf("--branch=%s", cloneBranch)) }
if twf.Clone.Submodules { cloneCmd = append(cloneCmd, "--recursive") }
fmt.Println(strings.Join(cloneCmd, " "))
cloneStep := Step{ Command: strings.Join(cloneCmd, " "), Name: "Clone repository into workspace", } return cloneStep}
// dependencyStep processes dependencies defined in the workflow.// For dependencies using a custom registry (i.e. not nixpkgs), it collects// all packages and adds a single 'nix profile install' step to the// beginning of the workflow's step list.func dependencyStep(twf tangled.Pipeline_Workflow) *Step { var customPackages []string
for _, d := range twf.Dependencies { registry := d.Registry packages := d.Packages
if registry == "nixpkgs" { continue }
// collect packages from custom registries for _, pkg := range packages { customPackages = append(customPackages, fmt.Sprintf("'%s#%s'", registry, pkg)) } }
if len(customPackages) > 0 { installCmd := "nix --extra-experimental-features nix-command --extra-experimental-features flakes profile install" cmd := fmt.Sprintf("%s %s", installCmd, strings.Join(customPackages, " ")) installStep := Step{ Command: cmd, Name: "Install custom dependencies", Environment: map[string]string{ "NIX_NO_COLOR": "1", "NIX_SHOW_DOWNLOAD_PROGRESS": "0", }, } return &installStep } return nil}