fix: make branches available as recipe source #453

Closed
stevensting wants to merge 3 commits from branch-recipes into main
3 changed files with 16 additions and 24 deletions

View File

@ -8,7 +8,6 @@ import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
) )
// Clone runs a git clone which accounts for different default branches. // Clone runs a git clone which accounts for different default branches.
@ -17,28 +16,19 @@ func Clone(dir, url string) error {
log.Debugf("%s does not exist, attempting to git clone from %s", dir, url) log.Debugf("%s does not exist, attempting to git clone from %s", dir, url)
_, err := git.PlainClone(dir, false, &git.CloneOptions{ _, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url, URL: url,
Tags: git.AllTags, Tags: git.AllTags,
ReferenceName: plumbing.ReferenceName("refs/heads/master"), // To be able to pull recipe from any branch
SingleBranch: true, SingleBranch: false,
}) })
if err != nil { if err != nil {
log.Debugf("cloning %s default branch failed, attempting from main branch", url) if strings.Contains(err.Error(), "authentication required") {
name := filepath.Base(dir)
_, err := git.PlainClone(dir, false, &git.CloneOptions{ return fmt.Errorf("unable to clone %s, does %s exist?", name, url)
URL: url,
Tags: git.AllTags,
ReferenceName: plumbing.ReferenceName("refs/heads/main"),
SingleBranch: true,
})
if err != nil {
if strings.Contains(err.Error(), "authentication required") {
name := filepath.Base(dir)
return fmt.Errorf("unable to clone %s, does %s exist?", name, url)
}
return err
} }
return err
} }
log.Debugf("%s has been git cloned successfully", dir) log.Debugf("%s has been git cloned successfully", dir)

View File

@ -95,6 +95,7 @@ func (r Recipe) GetVersionLabelLocal() (string, error) {
for _, service := range config.Services { for _, service := range config.Services {
for label, value := range service.Deploy.Labels { for label, value := range service.Deploy.Labels {
log.Debugf("checking deploy label '%s' with value '%s' for correct formatting", label, value)
decentral1se marked this conversation as resolved Outdated

Could we make this message more specific, e.g. what are we checking for?

Also, you don't log the value, is that by choice?

Could we make this message more specific, e.g. what are we checking for? Also, you don't log the `value`, is that by choice?
if strings.HasPrefix(label, "coop-cloud") && strings.Contains(label, "version") { if strings.HasPrefix(label, "coop-cloud") && strings.Contains(label, "version") {
return value, nil return value, nil
} }

View File

@ -68,6 +68,7 @@ func (r Recipe) EnsureExists() error {
// EnsureVersion checks whether a specific version exists for a recipe. // EnsureVersion checks whether a specific version exists for a recipe.
func (r Recipe) EnsureVersion(version string) (bool, error) { func (r Recipe) EnsureVersion(version string) (bool, error) {
isChaosCommit := false isChaosCommit := false
log.Debugf("ensuring version '%s' exists for recipe '%s'", version, r.Name)
decentral1se marked this conversation as resolved Outdated

%s/Ensuring/ensuring (lowercase convention everywhere else in the codebase).

Also, can you make this more specific, e.g. using the r.Name there too?

`%s/Ensuring/ensuring` (lowercase convention everywhere else in the codebase). Also, can you make this more specific, e.g. using the `r.Name` there too?
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil { if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
return isChaosCommit, err return isChaosCommit, err
@ -78,7 +79,7 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
return isChaosCommit, err return isChaosCommit, err
} }
tags, err := repo.Tags() tags, err := repo.References()
if err != nil { if err != nil {
return isChaosCommit, err return isChaosCommit, err
} }
@ -117,11 +118,11 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
worktree, err := repo.Worktree() worktree, err := repo.Worktree()
if err != nil { if err != nil {
return isChaosCommit, nil return isChaosCommit, err
} }
if err := worktree.Checkout(opts); err != nil { if err := worktree.Checkout(opts); err != nil {
return isChaosCommit, nil return isChaosCommit, err
} }
log.Debugf("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir) log.Debugf("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir)
@ -216,7 +217,7 @@ func (r Recipe) EnsureUpToDate() error {
opts := &git.PullOptions{ opts := &git.PullOptions{
Force: true, Force: true,
ReferenceName: branch, ReferenceName: branch,
SingleBranch: true, SingleBranch: false,
} }
if err := worktree.Pull(opts); err != nil { if err := worktree.Pull(opts); err != nil {