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

92 lines
2.4 KiB
Go
Raw Normal View History

2016-12-21 14:35:34 +02:00
package main
import (
2016-12-21 19:03:07 +02:00
"log"
2016-12-31 18:07:58 +02:00
"os"
2016-12-21 14:35:34 +02:00
2017-01-15 00:01:32 +02:00
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
2017-01-15 00:13:49 +02:00
"github.com/goreleaser/goreleaser/pipeline/archive"
2017-01-15 00: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-30 01:55:32 +02:00
"github.com/goreleaser/goreleaser/pipeline/fpm"
2017-01-15 00:01:32 +02:00
"github.com/goreleaser/goreleaser/pipeline/git"
"github.com/goreleaser/goreleaser/pipeline/release"
2017-03-23 02:06:56 +02:00
"github.com/goreleaser/goreleaser/pipeline/source"
2016-12-31 17:57:39 +02:00
"github.com/urfave/cli"
2016-12-21 14:35:34 +02:00
)
2016-12-29 22:10:11 +02:00
var version = "master"
2016-12-21 18:42:23 +02:00
2016-12-21 14:35:34 +02:00
func main() {
2016-12-31 17:57:39 +02:00
var app = cli.NewApp()
2017-01-18 19:45:42 +02:00
app.Name = "goreleaser"
2016-12-31 17:57:39 +02:00
app.Version = version
app.Usage = "Deliver Go binaries as fast and easily as possible"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Load configuration from `FILE`",
Value: "goreleaser.yml",
},
2017-03-05 00:06:16 +02: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-29 02:23:39 +02:00
}
2017-01-21 23:11:54 +02:00
app.Action = func(c *cli.Context) (err error) {
2016-12-31 17:57:39 +02:00
var file = c.String("config")
2017-01-14 20:29:57 +02: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 17:57:39 +02:00
return cli.NewExitError(err.Error(), 1)
}
ctx := context.New(cfg)
2017-01-14 18:06:57 +02:00
log.SetFlags(0)
2017-03-05 00:06:16 +02:00
for _, pipe := range pipes(c.Bool("build-only")) {
2017-01-21 23: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 13:58:22 +02:00
}
2016-12-31 17:57:39 +02:00
log.Println("Done!")
2017-01-21 23:11:54 +02:00
return
2016-12-21 19:03:07 +02:00
}
2017-01-02 17:20:33 +02:00
if err := app.Run(os.Args); err != nil {
log.Fatalln(err)
}
2016-12-21 14:35:34 +02:00
}
2017-03-05 00:06:16 +02:00
func pipes(buildOnly bool) []pipeline.Pipe {
var pipes = []pipeline.Pipe{
defaults.Pipe{}, // load default configs
}
if !buildOnly {
pipes = append(
pipes,
2017-03-23 02:06:56 +02:00
git.Pipe{}, // get current tag info
env.Pipe{}, // load and validate environment variables
source.Pipe{}, // validate current git state
2017-03-05 00:06:16 +02: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
}