Skip to content

Commit

Permalink
fix: release logics
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed May 13, 2021
1 parent 9437233 commit 72c88f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
12 changes: 8 additions & 4 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
7 changes: 5 additions & 2 deletions task/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
48 changes: 30 additions & 18 deletions utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 72c88f2

Please sign in to comment.