1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
goreleaser/main.go

96 lines
2.5 KiB
Go
Raw Normal View History

2016-12-21 10:35:34 -02:00
package main
import (
2016-12-21 15:03:07 -02:00
"log"
2016-12-31 14:07:58 -02:00
"os"
2016-12-21 10:35:34 -02:00
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
2017-01-14 20:13:49 -02:00
"github.com/goreleaser/goreleaser/pipeline/archive"
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/pipeline/brew"
"github.com/goreleaser/goreleaser/pipeline/build"
"github.com/goreleaser/goreleaser/pipeline/defaults"
"github.com/goreleaser/goreleaser/pipeline/env"
2017-01-29 21:55:32 -02:00
"github.com/goreleaser/goreleaser/pipeline/fpm"
2017-01-14 20:01:32 -02:00
"github.com/goreleaser/goreleaser/pipeline/git"
"github.com/goreleaser/goreleaser/pipeline/release"
2017-03-22 21:06:56 -03:00
"github.com/goreleaser/goreleaser/pipeline/source"
2016-12-31 13:57:39 -02:00
"github.com/urfave/cli"
2016-12-21 10:35:34 -02:00
)
2017-03-25 20:24:38 -03:00
var (
2017-03-25 20:25:38 -03:00
version = "dev"
commit = "none"
date = "unknown"
2017-03-25 20:24:38 -03:00
)
2016-12-21 14:42:23 -02:00
2016-12-21 10:35:34 -02:00
func main() {
2016-12-31 13:57:39 -02:00
var app = cli.NewApp()
2017-01-18 15:45:42 -02:00
app.Name = "goreleaser"
2017-03-25 20:26:03 -03:00
app.Version = version + ", commit " + commit + ", built at " + date
2016-12-31 13:57:39 -02:00
app.Usage = "Deliver Go binaries as fast and easily as possible"
app.Flags = []cli.Flag{
cli.StringFlag{
2017-03-29 21:29:42 -03:00
Name: "config, file, c, f",
2016-12-31 13:57:39 -02:00
Usage: "Load configuration from `FILE`",
Value: "goreleaser.yml",
},
2017-03-04 19:06:16 -03:00
cli.BoolFlag{
Name: "build-only, skip-release, no-release, nr",
Usage: "Skip all the release processes and run only the build and packaging steps",
},
2016-12-28 22:23:39 -02:00
}
2017-01-21 19:11:54 -02:00
app.Action = func(c *cli.Context) (err error) {
2016-12-31 13:57:39 -02:00
var file = c.String("config")
2017-01-14 19:29:57 +01:00
cfg, err := config.Load(file)
// Allow failing to load the config file if file is not explicitly specified
if err != nil && c.IsSet("config") {
2016-12-31 13:57:39 -02:00
return cli.NewExitError(err.Error(), 1)
}
ctx := context.New(cfg)
2017-01-14 14:06:57 -02:00
log.SetFlags(0)
2017-03-04 19:06:16 -03:00
for _, pipe := range pipes(c.Bool("build-only")) {
2017-01-21 19:11:54 -02:00
log.Println(pipe.Description())
log.SetPrefix(" -> ")
if err := pipe.Run(ctx); err != nil {
return cli.NewExitError(err.Error(), 1)
}
log.SetPrefix("")
2016-12-29 09:58:22 -02:00
}
2016-12-31 13:57:39 -02:00
log.Println("Done!")
2017-01-21 19:11:54 -02:00
return
2016-12-21 15:03:07 -02:00
}
2017-01-02 13:20:33 -02:00
if err := app.Run(os.Args); err != nil {
log.Fatalln(err)
}
2016-12-21 10:35:34 -02:00
}
2017-03-04 19:06:16 -03:00
func pipes(buildOnly bool) []pipeline.Pipe {
var pipes = []pipeline.Pipe{
defaults.Pipe{}, // load default configs
}
if !buildOnly {
pipes = append(
pipes,
2017-03-22 21:06:56 -03:00
git.Pipe{}, // get current tag info
env.Pipe{}, // load and validate environment variables
source.Pipe{}, // validate current git state
2017-03-04 19:06:16 -03:00
)
}
pipes = append(
pipes,
build.Pipe{}, // build
archive.Pipe{}, // archive (tar.gz, zip, etc)
fpm.Pipe{}, // archive via fpm (deb, rpm, etc)
)
if !buildOnly {
pipes = append(
pipes,
release.Pipe{}, // release to github
brew.Pipe{}, // push to brew tap
)
}
return pipes
}