refactor: the grand recipe release refactor

This commit is contained in:
2021-12-21 19:25:44 +01:00
parent f57222d6aa
commit fa45264ea0
4 changed files with 288 additions and 210 deletions

View File

@ -2,20 +2,17 @@ package git
import (
"fmt"
"path"
"coopcloud.tech/abra/pkg/config"
"github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
)
// Commit runs a git commit
func Commit(glob, commitMessage string, dryRun, push bool) error {
func Commit(repoPath, glob, commitMessage string, dryRun, push bool) error {
if commitMessage == "" {
return fmt.Errorf("no commit message specified?")
}
repoPath := path.Join(config.ABRA_DIR, "catalogue")
commitRepo, err := git.PlainOpen(repoPath)
if err != nil {
return err

View File

@ -158,7 +158,7 @@ func EnsureVersion(recipeName, version string) error {
return err
}
logrus.Debugf("read '%s' as tags for recipe '%s'", strings.Join(parsedTags, ", "), recipeName)
logrus.Debugf("read %s as tags for recipe %s", strings.Join(parsedTags, ", "), recipeName)
if tagRef.String() == "" {
logrus.Warnf("%s recipe has no local tag: %s? this recipe version is not released?", recipeName, version)
@ -179,7 +179,7 @@ func EnsureVersion(recipeName, version string) error {
return err
}
logrus.Debugf("successfully checked '%s' out to '%s' in '%s'", recipeName, tagRef.Short(), recipeDir)
logrus.Debugf("successfully checked %s out to %s in %s", recipeName, tagRef.Short(), recipeDir)
return nil
}
@ -194,14 +194,14 @@ func EnsureLatest(recipeName string) error {
}
if !isClean {
return fmt.Errorf("'%s' has locally unstaged changes", recipeName)
return fmt.Errorf("%s has locally unstaged changes", recipeName)
}
if err := gitPkg.EnsureGitRepo(recipeDir); err != nil {
return err
}
logrus.Debugf("attempting to open git repository in '%s'", recipeDir)
logrus.Debugf("attempting to open git repository in %s", recipeDir)
repo, err := git.PlainOpen(recipeDir)
if err != nil {
@ -216,7 +216,7 @@ func EnsureLatest(recipeName string) error {
branch := "master"
if _, err := repo.Branch("master"); err != nil {
if _, err := repo.Branch("main"); err != nil {
logrus.Debugf("failed to select branch in '%s'", path.Join(config.APPS_DIR, recipeName))
logrus.Debugf("failed to select branch in %s", path.Join(config.APPS_DIR, recipeName))
return err
}
branch = "main"
@ -230,7 +230,7 @@ func EnsureLatest(recipeName string) error {
}
if err := worktree.Checkout(checkOutOpts); err != nil {
logrus.Debugf("failed to check out '%s' in '%s'", branch, recipeDir)
logrus.Debugf("failed to check out %s in %s", branch, recipeDir)
return err
}
@ -271,3 +271,22 @@ func GetRecipesLocal() ([]string, error) {
return recipes, nil
}
// GetVersionLabelLocal retrieves the version label on the local recipe config
func GetVersionLabelLocal(recipe Recipe) (string, error) {
var label string
for _, service := range recipe.Config.Services {
for label, value := range service.Deploy.Labels {
if strings.HasPrefix(label, "coop-cloud") {
return value, nil
}
}
}
if label == "" {
return label, fmt.Errorf("unable to retrieve synced version label for %s", recipe.Name)
}
return label, nil
}