github.com/azunymous/cdx@v0.0.0-20201122180449-fbb46cc4d252/commands/release.go (about) 1 package commands 2 3 import ( 4 "github.com/azunymous/cdx/commands/options" 5 "github.com/azunymous/cdx/vcs" 6 "github.com/azunymous/cdx/vcs/gogit" 7 "github.com/sirupsen/logrus" 8 "github.com/spf13/cobra" 9 ) 10 11 // addRelease adds the increment command to a top level command. 12 func addRelease(topLevel *cobra.Command, app *options.App) { 13 incrOpts := &options.Increment{} 14 gitOpts := &options.Git{} 15 releaseCmd := &cobra.Command{ 16 Use: "release", 17 Short: "Release a new version", 18 Long: `The release command increments the version via a git tag 19 `, 20 Run: func(cmd *cobra.Command, args []string) { 21 err := release(app, incrOpts, gitOpts) 22 if err != nil { 23 logrus.Fatal(err) 24 } 25 }, 26 } 27 options.AddIncrementArg(releaseCmd, incrOpts) 28 options.AddPushArg(releaseCmd, gitOpts) 29 topLevel.AddCommand(releaseCmd) 30 } 31 32 func release(app *options.App, incr *options.Increment, gitOpts *options.Git) error { 33 logrus.Printf("Releasing %v", app.Name) 34 v, err := vcs.NewGit(app.Name, incr.GetField(), gitOpts.Push, func() (vcs.Repository, error) { return gogit.NewRepo() }) 35 if err != nil { 36 return err 37 } 38 if !v.Ready() { 39 return nil 40 } 41 err = v.Release() 42 if err != nil { 43 return err 44 } 45 return v.Distribute() 46 }