gitee.com/mirrors_opencollective/goreleaser@v0.45.0/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "time" 7 8 "github.com/apex/log" 9 lcli "github.com/apex/log/handlers/cli" 10 "github.com/fatih/color" 11 "github.com/goreleaser/goreleaser/goreleaserlib" 12 "github.com/urfave/cli" 13 ) 14 15 var ( 16 version = "dev" 17 commit = "none" 18 date = "unknown" 19 20 bold = color.New(color.Bold) 21 ) 22 23 func init() { 24 log.SetHandler(lcli.Default) 25 } 26 27 func main() { 28 fmt.Println() 29 defer fmt.Println() 30 var app = cli.NewApp() 31 app.Name = "goreleaser" 32 app.Version = fmt.Sprintf("%v, commit %v, built at %v", version, commit, date) 33 app.Usage = "Deliver Go binaries as fast and easily as possible" 34 app.Flags = []cli.Flag{ 35 cli.StringFlag{ 36 Name: "config, file, c, f", 37 Usage: "Load configuration from `FILE`", 38 Value: ".goreleaser.yml", 39 }, 40 cli.StringFlag{ 41 Name: "release-notes", 42 Usage: "Load custom release notes from a markdown `FILE`", 43 }, 44 cli.BoolFlag{ 45 Name: "skip-validate", 46 Usage: "Skip all the validations against the release", 47 }, 48 cli.BoolFlag{ 49 Name: "skip-publish", 50 Usage: "Skip all publishing pipes of the release", 51 }, 52 cli.BoolFlag{ 53 Name: "snapshot", 54 Usage: "Generate an unversioned snapshot release", 55 }, 56 cli.BoolFlag{ 57 Name: "rm-dist", 58 Usage: "Remove ./dist before building", 59 }, 60 cli.IntFlag{ 61 Name: "parallelism, p", 62 Usage: "Amount of builds launch in parallel", 63 Value: 4, 64 }, 65 cli.BoolFlag{ 66 Name: "debug", 67 Usage: "Enable debug mode", 68 }, 69 cli.DurationFlag{ 70 Name: "timeout", 71 Usage: "How much time the entire release process is allowed to take", 72 Value: 30 * time.Minute, 73 }, 74 } 75 app.Action = func(c *cli.Context) error { 76 start := time.Now() 77 log.Infof(bold.Sprint("releasing...")) 78 if err := goreleaserlib.Release(c); err != nil { 79 log.WithError(err).Errorf(bold.Sprintf("release failed after %0.2fs", time.Since(start).Seconds())) 80 return cli.NewExitError("\n", 1) 81 } 82 log.Infof(bold.Sprintf("release succeeded after %0.2fs", time.Since(start).Seconds())) 83 return nil 84 } 85 app.Commands = []cli.Command{ 86 { 87 Name: "init", 88 Aliases: []string{"i"}, 89 Usage: "generate .goreleaser.yml", 90 Action: func(c *cli.Context) error { 91 var filename = ".goreleaser.yml" 92 if err := goreleaserlib.InitProject(filename); err != nil { 93 log.WithError(err).Error("failed to init project") 94 return cli.NewExitError("\n", 1) 95 } 96 97 log.WithField("file", filename). 98 Info("config created; please edit accordingly to your needs") 99 return nil 100 }, 101 }, 102 } 103 if err := app.Run(os.Args); err != nil { 104 log.WithError(err).Fatal("failed") 105 } 106 }