fix: ensure tags & commits are pushed
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
cellarspoon 2021-12-23 02:24:43 +01:00
parent a7894cbda9
commit 014d32112e
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
4 changed files with 39 additions and 14 deletions

View File

@ -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") 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) logrus.Fatal(err)
} }
if internal.Push {
if err := gitPkg.Push(cataloguePath); err != nil {
logrus.Fatal(err)
}
}
} }
return nil return nil

View File

@ -230,7 +230,7 @@ func btoi(b bool) int {
func getTagCreateOptions() (git.CreateTagOptions, error) { func getTagCreateOptions() (git.CreateTagOptions, error) {
if internal.TagMessage == "" && !internal.NoInput { if internal.TagMessage == "" && !internal.NoInput {
prompt := &survey.Input{ prompt := &survey.Input{
Message: "git tag message", Message: "git tag message?",
Default: "chore: publish new release", Default: "chore: publish new release",
} }
@ -260,7 +260,7 @@ func commitRelease(recipe recipe.Recipe) error {
if internal.CommitMessage == "" && !internal.NoInput && internal.Commit { if internal.CommitMessage == "" && !internal.NoInput && internal.Commit {
prompt := &survey.Input{ prompt := &survey.Input{
Message: "commit message", Message: "git commit message?",
Default: "chore: publish new version", Default: "chore: publish new version",
} }
if err := survey.AskOne(prompt, &internal.CommitMessage); err != nil { if err := survey.AskOne(prompt, &internal.CommitMessage); err != nil {
@ -270,7 +270,7 @@ func commitRelease(recipe recipe.Recipe) error {
if internal.Commit { if internal.Commit {
repoPath := path.Join(config.APPS_DIR, recipe.Name) 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 return err
} }
} }
@ -322,6 +322,10 @@ func pushRelease(tagString string, repo *git.Repository) error {
} }
if internal.Push { if internal.Push {
if err := repo.Push(&git.PushOptions{}); err != nil {
return err
}
tagRef := fmt.Sprintf("+refs/tags/%s:refs/tags/%s", tagString, tagString) tagRef := fmt.Sprintf("+refs/tags/%s:refs/tags/%s", tagString, tagString)
pushOpts := &git.PushOptions{ pushOpts := &git.PushOptions{
RefSpecs: []configPkg.RefSpec{ RefSpecs: []configPkg.RefSpec{
@ -331,6 +335,7 @@ func pushRelease(tagString string, repo *git.Repository) error {
if err := repo.Push(pushOpts); err != nil { if err := repo.Push(pushOpts); err != nil {
return err return err
} }
logrus.Info(fmt.Sprintf("pushed tag %s to remote", tagString)) logrus.Info(fmt.Sprintf("pushed tag %s to remote", tagString))
} }

View File

@ -8,7 +8,7 @@ import (
) )
// Commit runs a git commit // 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 == "" { if commitMessage == "" {
return fmt.Errorf("no commit message specified?") 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") 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 return nil
} }

22
pkg/git/push.go Normal file
View File

@ -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
}