1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

Merge pull request #286 from goreleaser/dot-goreleaser

defaulting to .goreleaser.yml
This commit is contained in:
Carlos Alexandro Becker 2017-07-05 00:04:18 -03:00 committed by GitHub
commit 7f2b04f16a
6 changed files with 46 additions and 17 deletions

View File

@ -38,7 +38,7 @@ For questions join the [#goreleaser](https://gophers.slack.com/messages/goreleas
GoReleaser is a release automation tool for Golang projects, the goal is to simplify the build, release and publish steps while providing variant customization options for all steps.
GoReleaser is built for CI tools; you only need to [download and execute it](#integration-with-ci) in your build script.
You can [customize](#release-customization) your release process by createing a `goreleaser.yml` file.
You can [customize](#release-customization) your release process by createing a `.goreleaser.yml` file.
We are also working on integrating with package managers, we currently support Homebrew.
The idea started with a [simple shell script](https://github.com/goreleaser/old-go-releaser), but it quickly became more complex and I also wanted to publish binaries via Homebrew.
@ -59,7 +59,7 @@ func main() {
By default GoReleaser will build the current directory, but you can change the build package path in the GoReleaser configuration file.
```yml
# goreleaser.yml
# .goreleaser.yml
# Build customization
builds:
- binary: drum-roll
@ -80,7 +80,7 @@ You can change the archives name and format. You can also replace the OS and the
Another useful feature is to add files to archives, this is very useful for integrating assets like resource files.
```yml
# goreleaser.yml
# .goreleaser.yml
# Build customization
builds:
- main: main.go
@ -166,7 +166,7 @@ func main() {
## GoReleaser customization
GoReleaser provides multiple customizations via the `goreleaser.yml` file.
GoReleaser provides multiple customizations via the `.goreleaser.yml` file.
You can generate it by running `goreleaser init` or start from scratch. The
defaults are sensible and fit for most projects.
@ -175,7 +175,7 @@ We'll cover all customizations available bellow:
### Project name
```yml
# goreleaser.yml
# .goreleaser.yml
# The name of the project. It is used in the name of the brew formula, archives,
# etc. Defaults to the name of the git project.
project_name: myproject
@ -184,7 +184,7 @@ project_name: myproject
### Build customization
```yml
# goreleaser.yml
# .goreleaser.yml
builds:
# You can have multiple builds, its a common yaml list
-
@ -258,7 +258,7 @@ builds:
### Archive customization
```yml
# goreleaser.yml
# .goreleaser.yml
archive:
# You can change the name of the archive.
# This is parsed with Golang template engine and the following variables
@ -308,7 +308,7 @@ archive:
### Release customization
```yml
# goreleaser.yml
# .goreleaser.yml
release:
# Repo in which the release will be created.
# Default is extracted from the origin remote URL.
@ -327,7 +327,7 @@ You can also specify a release notes file in markdown format using the
### Snapshot customization
```yml
# goreleaser.yml
# .goreleaser.yml
snapshot:
# Allows you to change the name of the generated snapshot
# releases. The following variables are available:
@ -344,7 +344,7 @@ The brew section specifies how the formula should be created.
Check [the Homebrew documentation](https://github.com/Homebrew/brew/blob/master/docs/How-to-Create-and-Maintain-a-Tap.md) and the [formula cookbook](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md) for details.
```yml
# goreleaser.yml
# .goreleaser.yml
brew:
# Reporitory to push the tap to.
github:
@ -416,7 +416,7 @@ GoReleaser can be wired to [fpm]() to generate `.deb`, `.rpm` and other archives
[fpm]: https://github.com/jordansissel/fpm
```yml
# goreleaser.yml
# .goreleaser.yml
fpm:
# Your app's vendor
# Default is empty

View File

@ -121,6 +121,7 @@ func Load(file string) (config Project, err error) {
if err != nil {
return
}
log.WithField("file", file).Info("loading config file")
return LoadReader(f)
}

View File

@ -45,7 +45,7 @@ type Flags interface {
// Release runs the release process with the given flags
func Release(flags Flags) error {
var file = flags.String("config")
var file = getConfigFile(flags)
var notes = flags.String("release-notes")
if flags.Bool("debug") {
log.SetLevel(log.DebugLevel)
@ -58,7 +58,7 @@ func Release(flags Flags) error {
if !os.IsNotExist(statErr) || flags.IsSet("config") {
return err
}
log.WithField("file", file).Warn("could not load config")
log.WithField("file", file).Warn("could not load config, using defaults")
}
var ctx = context.New(cfg)
ctx.Validate = !flags.Bool("skip-validate")
@ -108,3 +108,17 @@ func InitProject(filename string) error {
return ioutil.WriteFile(filename, out, 0644)
}
func getConfigFile(flags Flags) string {
var config = flags.String("config")
if flags.IsSet("config") {
return config
}
for _, f := range []string{".goreleaser.yml", "goreleaser.yml"} {
_, ferr := os.Stat(f)
if ferr == nil || os.IsExist(ferr) {
return f
}
}
return config
}

View File

@ -52,6 +52,20 @@ func TestConfigFileIsSetAndDontExist(t *testing.T) {
assert.Error(Release(flags))
}
func TestConfigFlagNotSetButExists(t *testing.T) {
var assert = assert.New(t)
folder, back := setup(t)
defer back()
os.Rename(
filepath.Join(folder, "goreleaser.yml"),
filepath.Join(folder, ".goreleaser.yml"),
)
var flags = fakeFlags{
flags: map[string]string{},
}
assert.Equal(".goreleaser.yml", getConfigFile(flags))
}
func TestReleaseNotesFileDontExist(t *testing.T) {
var assert = assert.New(t)
var flags = fakeFlags{

View File

@ -29,7 +29,7 @@ func main() {
cli.StringFlag{
Name: "config, file, c, f",
Usage: "Load configuration from `FILE`",
Value: "goreleaser.yml",
Value: ".goreleaser.yml",
},
cli.StringFlag{
Name: "release-notes",
@ -59,7 +59,7 @@ func main() {
app.Action = func(c *cli.Context) error {
log.Infof("running goreleaser %v", version)
if err := goreleaserlib.Release(c); err != nil {
log.WithError(err).Error("pipe failed")
log.WithError(err).Error("release failed")
return cli.NewExitError("\n", 1)
}
return nil
@ -68,9 +68,9 @@ func main() {
{
Name: "init",
Aliases: []string{"i"},
Usage: "generate goreleaser.yml",
Usage: "generate .goreleaser.yml",
Action: func(c *cli.Context) error {
var filename = "goreleaser.yml"
var filename = ".goreleaser.yml"
if err := goreleaserlib.InitProject(filename); err != nil {
log.WithError(err).Error("failed to init project")
return cli.NewExitError("\n", 1)