diff --git a/cmd/release.go b/cmd/release.go index a1484eb..12264ed 100644 --- a/cmd/release.go +++ b/cmd/release.go @@ -20,12 +20,16 @@ This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { defer logging.Logger.Sync() - logging.Logger.Info("Commit and push changes...") - if err := utils.CommitAndPushRepository(); err != nil { + logging.Logger.Info("Commit changes...") + if err := utils.CommitRepository(); err != nil { log.Fatal(err.Error()) } - logging.Logger.Info("CreateAndPush tag changes...") - if err := utils.ReleaseAndPushRepository(); err != nil { + logging.Logger.Info("Create tag changes...") + if err := utils.ReleaseRepository(); err != nil { + log.Fatal(err.Error()) + } + logging.Logger.Info("Push...") + if err := utils.Push(); err != nil { log.Fatal(err.Error()) } logging.Logger.Info("Do release successfully.") diff --git a/task/main.go b/task/main.go index 78b4d9b..0b99b37 100644 --- a/task/main.go +++ b/task/main.go @@ -112,8 +112,11 @@ func doBundleRelease(categories *utils.CategoryUnitCollection, sentencesMap *map if err := generateBundle(categories, sentencesMap, versionData); err != nil { return err } // generate new build - if err := utils.CommitAndPushRepository(); err != nil { + if err := utils.CommitRepository(); err != nil { return err } - return utils.ReleaseAndPushRepository() + if err := utils.ReleaseRepository(); err != nil { + return err + } + return utils.Push() } diff --git a/utils/git.go b/utils/git.go index 4a27a17..d38b6a8 100644 --- a/utils/git.go +++ b/utils/git.go @@ -74,8 +74,8 @@ func SyncRepository() error { }) } -// CommitAndPushRepository will commit all local changes and push to remote repository -func CommitAndPushRepository() error { +// CommitRepository will commit all local changes +func CommitRepository() error { defer logging.Logger.Sync() logging.Logger.Info("Open local repository...") repository, err := git.PlainOpen(config.Core.Workdir) @@ -110,23 +110,11 @@ func CommitAndPushRepository() error { }, }, ) - if err != nil { - return err - } - logging.Logger.Info("Push to remote source...") - auth, err := GetGitAuth() - if err != nil { - return err - } - return repository.Push(&git.PushOptions{ - RemoteName: "origin", - Auth: auth, - Progress: os.Stdout, - }) + return err } -// ReleaseAndPushRepository will create a git tag and push tags to remote repository -func ReleaseAndPushRepository() error { +// ReleaseRepository will create a git tag +func ReleaseRepository() error { defer logging.Logger.Sync() logging.Logger.Info("Open local repository...") repository, err := git.PlainOpen(config.Core.Workdir) @@ -143,16 +131,40 @@ func ReleaseAndPushRepository() error { return err } _, err = repository.CreateTag(fmt.Sprintf("v%s", version), ref.Hash(), &git.CreateTagOptions{ + Tagger: &object.Signature{ + Name: config.Git.Name, + Email: config.Git.Email, + When: time.Now(), + }, Message: fmt.Sprintf("release v%s", version), }) + return err +} + +// Push will push local changes(includes tags) to remote repository +func Push() error { + defer logging.Logger.Sync() + logging.Logger.Info("Open local repository...") + repository, err := git.PlainOpen(config.Core.Workdir) if err != nil { return err } - logging.Logger.Info("Pushing...") + logging.Logger.Debug("Get Auth instance...") auth, err := GetGitAuth() if err != nil { return err } + + logging.Logger.Info("Pushing commits...") + if err := repository.Push(&git.PushOptions{ + RemoteName: "origin", + Auth: auth, + Progress: os.Stdout, + }); err != nil { + return err + } + + logging.Logger.Info("Pushing Tags...") return repository.Push(&git.PushOptions{ RemoteName: "origin", Progress: os.Stdout,