1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/main.go

107 lines
2.5 KiB
Go
Raw Normal View History

2017-04-21 20:25:32 +02:00
package main
import (
2017-04-22 02:58:59 +02:00
"fmt"
2017-04-21 20:25:32 +02:00
"os"
"time"
2017-04-21 20:25:32 +02:00
2017-06-22 05:09:14 +02:00
"github.com/apex/log"
2017-06-22 05:38:24 +02:00
lcli "github.com/apex/log/handlers/cli"
2018-01-17 22:48:01 +02:00
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/goreleaserlib"
2017-04-21 20:25:32 +02:00
"github.com/urfave/cli"
)
var (
version = "dev"
commit = "none"
date = "unknown"
2018-01-17 22:48:01 +02:00
bold = color.New(color.Bold)
2017-04-21 20:25:32 +02:00
)
2017-06-22 05:09:14 +02:00
func init() {
log.SetHandler(lcli.Default)
2017-06-22 05:09:14 +02:00
}
2017-04-21 20:25:32 +02:00
func main() {
fmt.Println()
defer fmt.Println()
2017-04-21 20:25:32 +02:00
var app = cli.NewApp()
app.Name = "goreleaser"
2017-04-22 02:58:59 +02:00
app.Version = fmt.Sprintf("%v, commit %v, built at %v", version, commit, date)
2017-04-21 20:25:32 +02:00
app.Usage = "Deliver Go binaries as fast and easily as possible"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, file, c, f",
Usage: "Load configuration from `FILE`",
2017-07-05 04:51:45 +02:00
Value: ".goreleaser.yml",
2017-04-21 20:25:32 +02:00
},
cli.StringFlag{
Name: "release-notes",
Usage: "Load custom release notes from a markdown `FILE`",
},
cli.BoolFlag{
Name: "skip-validate",
Usage: "Skip all the validations against the release",
},
cli.BoolFlag{
Name: "skip-publish",
Usage: "Skip all publishing pipes of the release",
},
2017-04-29 12:49:22 +02:00
cli.BoolFlag{
Name: "snapshot",
Usage: "Generate an unversioned snapshot release",
},
2017-07-05 03:53:50 +02:00
cli.BoolFlag{
Name: "rm-dist",
Usage: "Remove ./dist before building",
},
2017-07-15 21:49:52 +02:00
cli.IntFlag{
Name: "parallelism, p",
Usage: "Amount of builds launch in parallel",
Value: 4,
},
2017-06-22 05:25:52 +02:00
cli.BoolFlag{
Name: "debug",
Usage: "Enable debug mode",
},
2017-12-29 21:07:06 +02:00
cli.DurationFlag{
Name: "timeout",
Usage: "How much time the entire release process is allowed to take",
Value: 30 * time.Minute,
},
2017-04-21 20:25:32 +02:00
}
app.Action = func(c *cli.Context) error {
start := time.Now()
2018-01-17 22:48:01 +02:00
log.Infof(bold.Sprint("releasing..."))
if err := goreleaserlib.Release(c); err != nil {
2018-01-17 22:48:01 +02:00
log.WithError(err).Errorf(bold.Sprintf("release failed after %0.2fs", time.Since(start).Seconds()))
2017-07-05 03:53:50 +02:00
return cli.NewExitError("\n", 1)
2017-04-21 20:25:32 +02:00
}
2018-01-17 22:48:01 +02:00
log.Infof(bold.Sprintf("release succeeded after %0.2fs", time.Since(start).Seconds()))
2017-04-21 20:25:32 +02:00
return nil
}
2017-04-27 11:03:26 +02:00
app.Commands = []cli.Command{
{
Name: "init",
Aliases: []string{"i"},
2017-07-05 04:51:45 +02:00
Usage: "generate .goreleaser.yml",
2017-04-27 11:03:26 +02:00
Action: func(c *cli.Context) error {
2017-07-05 04:51:45 +02:00
var filename = ".goreleaser.yml"
2017-04-28 15:47:15 +02:00
if err := goreleaserlib.InitProject(filename); err != nil {
2017-07-05 03:55:24 +02:00
log.WithError(err).Error("failed to init project")
return cli.NewExitError("\n", 1)
2017-04-27 11:03:26 +02:00
}
2017-06-22 15:47:34 +02:00
log.WithField("file", filename).
2017-07-15 11:01:49 +02:00
Info("config created; please edit accordingly to your needs")
2017-04-27 11:03:26 +02:00
return nil
},
},
}
2017-04-21 20:25:32 +02:00
if err := app.Run(os.Args); err != nil {
2017-06-22 15:47:34 +02:00
log.WithError(err).Fatal("failed")
2017-04-21 20:25:32 +02:00
}
}