1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-26 04:22:05 +02:00

Merge pull request #202 from goreleaser/brew-fpm-alike

make brew and fpm config more alike
This commit is contained in:
Carlos Alexandro Becker 2017-04-21 17:17:59 -03:00 committed by GitHub
commit 8d914d129a
10 changed files with 61 additions and 88 deletions

View File

@ -288,6 +288,14 @@ brew:
# Default is empty. # Default is empty.
caveats: "How to use this binary" caveats: "How to use this binary"
# Your app's homepage
# Default is empty
homepage: "https://example.com/"
# Your app's description
# Default is empty
description: "Software to create fast and easy drum rolls."
# Dependencies of your package # Dependencies of your package
dependencies: dependencies:
- git - git
@ -339,13 +347,25 @@ GoReleaser can be wired to [fpm]() to generate `.deb`, `.rpm` and other archives
```yml ```yml
# goreleaser.yml # goreleaser.yml
fpm: fpm:
# Options used in deb control file etc. # Your app's vendor
options: # Default is empty
vendor: "Drum Roll Inc." vendor: Drum Roll Inc.
url: "https://example.com/" # Your app's homepage
maintainer: "<Drummer drum-roll@example.com>" # Default is empty
description: "Software to create fast and easy drum rolls." homepage: https://example.com/
license: "Apache 2.0"
# Your app's maintainer (probably you)
# Default is empty
maintainer: <Drummer drum-roll@example.com>
# Your app's description
# Default is empty
description: Software to create fast and easy drum rolls.
# Your app's license
# Default is empty
license: Apache 2.0
# Formats to generate as output # Formats to generate as output
formats: formats:
- deb - deb

View File

@ -17,7 +17,6 @@ type Info struct {
// Client interface // Client interface
type Client interface { type Client interface {
GetInfo(ctx *context.Context) (info Info, err error)
CreateRelease(ctx *context.Context, body string) (releaseID int, err error) CreateRelease(ctx *context.Context, body string) (releaseID int, err error)
CreateFile(ctx *context.Context, content bytes.Buffer, path string) (err error) CreateFile(ctx *context.Context, content bytes.Buffer, path string) (err error)
Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error) Upload(ctx *context.Context, releaseID int, name string, file *os.File) (err error)

View File

@ -67,21 +67,6 @@ func (c *githubClient) CreateFile(
return return
} }
func (c *githubClient) GetInfo(ctx *context.Context) (info Info, err error) {
rep, _, err := c.client.Repositories.Get(
ctx,
ctx.Config.Release.GitHub.Owner,
ctx.Config.Release.GitHub.Name,
)
if err != nil {
return
}
info.Homepage = rep.GetHomepage()
info.URL = rep.GetHTMLURL()
info.Description = rep.GetDescription()
return
}
func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) { func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
data := &github.RepositoryRelease{ data := &github.RepositoryRelease{
Name: github.String(ctx.Git.CurrentTag), Name: github.String(ctx.Git.CurrentTag),

View File

@ -28,6 +28,8 @@ type Homebrew struct {
Install string Install string
Dependencies []string Dependencies []string
Conflicts []string Conflicts []string
Description string
URL string
} }
// Hooks define actions to run before and/or after something // Hooks define actions to run before and/or after something
@ -72,16 +74,11 @@ type FPM struct {
Formats []string Formats []string
Dependencies []string Dependencies []string
Conflicts []string Conflicts []string
Options FPMOptions Vendor string
} Homepage string
Maintainer string
// FPMOptions config options Description string
type FPMOptions struct { License string
Vendor string
URL string
Maintainer string
Description string
License string
} }
// Project includes all project configuration // Project includes all project configuration

View File

@ -1,3 +1,5 @@
homepage: &homepage http://goreleaser.github.io
description: &description Deliver Go binaries as fast and easily as possible
build: build:
main: ./cmd/goreleaser/main.go main: ./cmd/goreleaser/main.go
goos: goos:
@ -18,9 +20,16 @@ brew:
owner: goreleaser owner: goreleaser
name: homebrew-tap name: homebrew-tap
folder: Formula folder: Formula
homepage: *homepage
description: *description
dependencies: dependencies:
- git - git
fpm: fpm:
homepage: *homepage
description: *description
maintainer: Carlos Alexandro Becker <root@carlosbecker.com>
license: MIT
vendor: GoReleaser
formats: formats:
- deb - deb
dependencies: dependencies:

View File

@ -143,21 +143,17 @@ func dataFor(ctx *context.Context, client client.Client) (result templateData, e
if err != nil { if err != nil {
return return
} }
homepage, description, err := getInfo(ctx, client)
if err != nil {
return
}
return templateData{ return templateData{
Name: formulaNameFor(ctx.Config.Build.Binary), Name: formulaNameFor(ctx.Config.Build.Binary),
Desc: description, Desc: ctx.Config.Brew.Description,
Homepage: homepage, Homepage: ctx.Config.Brew.URL,
Repo: ctx.Config.Release.GitHub, Repo: ctx.Config.Release.GitHub,
Tag: ctx.Git.CurrentTag, Tag: ctx.Git.CurrentTag,
Version: ctx.Version, Version: ctx.Version,
Binary: ctx.Config.Build.Binary, Binary: ctx.Config.Build.Binary,
Caveats: ctx.Config.Brew.Caveats, Caveats: ctx.Config.Brew.Caveats,
File: file, File: file,
Format: ctx.Config.Archive.Format, Format: ctx.Config.Archive.Format, // TODO this can be broken by format_overrides
SHA256: sum, SHA256: sum,
Dependencies: ctx.Config.Brew.Dependencies, Dependencies: ctx.Config.Brew.Dependencies,
Conflicts: ctx.Config.Brew.Conflicts, Conflicts: ctx.Config.Brew.Conflicts,
@ -166,27 +162,6 @@ func dataFor(ctx *context.Context, client client.Client) (result templateData, e
}, err }, err
} }
func getInfo(
ctx *context.Context,
client client.Client,
) (homepage string, description string, err error) {
info, err := client.GetInfo(ctx)
if err != nil {
return
}
if info.Homepage == "" {
homepage = info.URL
} else {
homepage = info.Homepage
}
if info.Description == "" {
description = "TODO"
} else {
description = info.Description
}
return
}
func formulaNameFor(name string) string { func formulaNameFor(name string) string {
name = strings.Replace(name, "-", " ", -1) name = strings.Replace(name, "-", " ", -1)
name = strings.Replace(name, "_", " ", -1) name = strings.Replace(name, "_", " ", -1)

View File

@ -7,7 +7,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/goreleaser/goreleaser/client"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -170,10 +169,6 @@ type DummyClient struct {
CreatedFile bool CreatedFile bool
} }
func (client *DummyClient) GetInfo(ctx *context.Context) (info client.Info, err error) {
return
}
func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) { func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
return return
} }

View File

@ -71,20 +71,20 @@ func create(ctx *context.Context, format, archive, arch string) error {
"--force", "--force",
} }
if ctx.Config.FPM.Options.Vendor != "" { if ctx.Config.FPM.Vendor != "" {
options = append(options, "--vendor", ctx.Config.FPM.Options.Vendor) options = append(options, "--vendor", ctx.Config.FPM.Vendor)
} }
if ctx.Config.FPM.Options.URL != "" { if ctx.Config.FPM.Homepage != "" {
options = append(options, "--url", ctx.Config.FPM.Options.URL) options = append(options, "--url", ctx.Config.FPM.Homepage)
} }
if ctx.Config.FPM.Options.Maintainer != "" { if ctx.Config.FPM.Maintainer != "" {
options = append(options, "--maintainer", ctx.Config.FPM.Options.Maintainer) options = append(options, "--maintainer", ctx.Config.FPM.Maintainer)
} }
if ctx.Config.FPM.Options.Description != "" { if ctx.Config.FPM.Description != "" {
options = append(options, "--description", ctx.Config.FPM.Options.Description) options = append(options, "--description", ctx.Config.FPM.Description)
} }
if ctx.Config.FPM.Options.License != "" { if ctx.Config.FPM.License != "" {
options = append(options, "--license", ctx.Config.FPM.Options.License) options = append(options, "--license", ctx.Config.FPM.License)
} }
for _, dep := range ctx.Config.FPM.Dependencies { for _, dep := range ctx.Config.FPM.Dependencies {
options = append(options, "--depends", dep) options = append(options, "--depends", dep)

View File

@ -49,13 +49,11 @@ func TestRunPipe(t *testing.T) {
Formats: []string{"deb"}, Formats: []string{"deb"},
Dependencies: []string{"make"}, Dependencies: []string{"make"},
Conflicts: []string{"git"}, Conflicts: []string{"git"},
Options: config.FPMOptions{ Description: "Some description",
Description: "Some description", License: "MIT",
License: "MIT", Maintainer: "me@me",
Maintainer: "me@me", Vendor: "asdf",
Vendor: "asdf", Homepage: "https://goreleaser.github.io",
URL: "https://goreleaser.github.io",
},
}, },
}, },
} }

View File

@ -8,7 +8,6 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/goreleaser/goreleaser/client"
"github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -144,10 +143,6 @@ type DummyClient struct {
UploadedFile bool UploadedFile bool
} }
func (client *DummyClient) GetInfo(ctx *context.Context) (info client.Info, err error) {
return
}
func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) { func (client *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
if client.FailToCreateRelease { if client.FailToCreateRelease {
return 0, errors.New("release failed") return 0, errors.New("release failed")