fix: sync recipes from remotes
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
dddf84d92b
commit
14400d4ed8
|
@ -25,7 +25,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||||
ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
|
ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
|
||||||
}
|
}
|
||||||
|
|
||||||
recipe, err := recipe.Get(recipeName)
|
chosenRecipe, err := recipe.Get(recipeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c.Command.Name == "generate" {
|
if c.Command.Name == "generate" {
|
||||||
if strings.Contains(err.Error(), "missing a compose") {
|
if strings.Contains(err.Error(), "missing a compose") {
|
||||||
|
@ -37,9 +37,13 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Debugf("validated '%s' as recipe argument", recipeName)
|
if err := recipe.EnsureUpToDate(recipeName); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
return recipe
|
logrus.Debugf("validated %s as recipe argument", recipeName)
|
||||||
|
|
||||||
|
return chosenRecipe
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateRecipeWithPrompt ensures a recipe argument is present before
|
// ValidateRecipeWithPrompt ensures a recipe argument is present before
|
||||||
|
@ -93,14 +97,18 @@ func ValidateRecipeWithPrompt(c *cli.Context) recipe.Recipe {
|
||||||
ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
|
ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
|
||||||
}
|
}
|
||||||
|
|
||||||
recipe, err := recipe.Get(recipeName)
|
chosenRecipe, err := recipe.Get(recipeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := recipe.EnsureUpToDate(chosenRecipe.Name); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
logrus.Debugf("validated %s as recipe argument", recipeName)
|
logrus.Debugf("validated %s as recipe argument", recipeName)
|
||||||
|
|
||||||
return recipe
|
return chosenRecipe
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateApp ensures the app name arg is valid.
|
// ValidateApp ensures the app name arg is valid.
|
||||||
|
@ -125,6 +133,10 @@ func ValidateApp(c *cli.Context) config.App {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := recipe.EnsureUpToDate(app.Type); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := ssh.EnsureHostKey(app.Server); err != nil {
|
if err := ssh.EnsureHostKey(app.Server); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ func EnsureVersion(recipeName, version string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureLatest makes sure the latest commit is checkout on for a local recipe repository.
|
// EnsureLatest makes sure the latest commit is checked out for a local recipe repository
|
||||||
func EnsureLatest(recipeName string) error {
|
func EnsureLatest(recipeName string) error {
|
||||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||||
|
|
||||||
|
@ -285,3 +285,37 @@ func GetVersionLabelLocal(recipe Recipe) (string, error) {
|
||||||
|
|
||||||
return label, nil
|
return label, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnsureUpToDate ensures that the local repo is synced to the remote
|
||||||
|
func EnsureUpToDate(recipeName string) error {
|
||||||
|
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||||
|
|
||||||
|
repo, err := git.PlainOpen(recipeDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
worktree, err := repo.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
branch, err := gitPkg.GetCurrentBranch(repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := &git.PullOptions{
|
||||||
|
ReferenceName: plumbing.ReferenceName(branch),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := worktree.Pull(opts); err != nil {
|
||||||
|
if !strings.Contains(err.Error(), "already up-to-date") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Debugf("fetched latest git changes for %s", recipeName)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue