From 014d32112e035a9e992f1df5ba7426a6ea4f0175 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Thu, 23 Dec 2021 02:24:43 +0100 Subject: [PATCH] fix: ensure tags & commits are pushed --- cli/catalogue/catalogue.go | 9 ++++++++- cli/recipe/release.go | 11 ++++++++--- pkg/git/commit.go | 11 +---------- pkg/git/push.go | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 pkg/git/push.go diff --git a/cli/catalogue/catalogue.go b/cli/catalogue/catalogue.go index c2c35754..f67b24f5 100644 --- a/cli/catalogue/catalogue.go +++ b/cli/catalogue/catalogue.go @@ -236,9 +236,16 @@ A new catalogue copy can be published to the recipes repository by passing the } cataloguePath := path.Join(config.ABRA_DIR, "catalogue") - if err := gitPkg.Commit(cataloguePath, "**.json", internal.CommitMessage, internal.Dry, internal.Push); err != nil { + if err := gitPkg.Commit(cataloguePath, "**.json", internal.CommitMessage, internal.Dry); err != nil { logrus.Fatal(err) } + + if internal.Push { + if err := gitPkg.Push(cataloguePath); err != nil { + logrus.Fatal(err) + } + } + } return nil diff --git a/cli/recipe/release.go b/cli/recipe/release.go index 88a80616..b6b24678 100644 --- a/cli/recipe/release.go +++ b/cli/recipe/release.go @@ -230,7 +230,7 @@ func btoi(b bool) int { func getTagCreateOptions() (git.CreateTagOptions, error) { if internal.TagMessage == "" && !internal.NoInput { prompt := &survey.Input{ - Message: "git tag message", + Message: "git tag message?", Default: "chore: publish new release", } @@ -260,7 +260,7 @@ func commitRelease(recipe recipe.Recipe) error { if internal.CommitMessage == "" && !internal.NoInput && internal.Commit { prompt := &survey.Input{ - Message: "commit message", + Message: "git commit message?", Default: "chore: publish new version", } if err := survey.AskOne(prompt, &internal.CommitMessage); err != nil { @@ -270,7 +270,7 @@ func commitRelease(recipe recipe.Recipe) error { if internal.Commit { repoPath := path.Join(config.APPS_DIR, recipe.Name) - if err := gitPkg.Commit(repoPath, "compose.**yml", internal.CommitMessage, internal.Dry, false); err != nil { + if err := gitPkg.Commit(repoPath, "compose.**yml", internal.CommitMessage, internal.Dry); err != nil { return err } } @@ -322,6 +322,10 @@ func pushRelease(tagString string, repo *git.Repository) error { } if internal.Push { + if err := repo.Push(&git.PushOptions{}); err != nil { + return err + } + tagRef := fmt.Sprintf("+refs/tags/%s:refs/tags/%s", tagString, tagString) pushOpts := &git.PushOptions{ RefSpecs: []configPkg.RefSpec{ @@ -331,6 +335,7 @@ func pushRelease(tagString string, repo *git.Repository) error { if err := repo.Push(pushOpts); err != nil { return err } + logrus.Info(fmt.Sprintf("pushed tag %s to remote", tagString)) } diff --git a/pkg/git/commit.go b/pkg/git/commit.go index b4ab636e..3e186717 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -8,7 +8,7 @@ import ( ) // Commit runs a git commit -func Commit(repoPath, glob, commitMessage string, dryRun, push bool) error { +func Commit(repoPath, glob, commitMessage string, dryRun bool) error { if commitMessage == "" { return fmt.Errorf("no commit message specified?") } @@ -52,14 +52,5 @@ func Commit(repoPath, glob, commitMessage string, dryRun, push bool) error { logrus.Info("dry run: no changes commited") } - if !dryRun && push { - if err := commitRepo.Push(&git.PushOptions{}); err != nil { - return err - } - logrus.Info("changes pushed") - } else { - logrus.Info("dry run: no changes pushed") - } - return nil } diff --git a/pkg/git/push.go b/pkg/git/push.go new file mode 100644 index 00000000..68adf807 --- /dev/null +++ b/pkg/git/push.go @@ -0,0 +1,22 @@ +package git + +import ( + "github.com/go-git/go-git/v5" + "github.com/sirupsen/logrus" +) + +// Push pushes the latest changes +func Push(repoPath string) error { + commitRepo, err := git.PlainOpen(repoPath) + if err != nil { + return err + } + + if err := commitRepo.Push(&git.PushOptions{}); err != nil { + return err + } + + logrus.Info("changes pushed") + + return nil +}