1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-13 13:48:40 +02:00

Merge pull request #721 from goreleaser/brew-format-override

Brew: consider format override
This commit is contained in:
Carlos Alexandro Becker 2018-07-11 00:53:37 -07:00 committed by GitHub
commit 0e078fdc19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 4 deletions

View File

@ -91,7 +91,7 @@ func doRun(ctx *context.Context, client client.Client) error {
if ctx.Config.Brew.GitHub.Name == "" {
return pipeline.Skip("brew section is not configured")
}
if ctx.Config.Archive.Format == "binary" {
if getFormat(ctx) == "binary" {
return pipeline.Skip("archive format is binary")
}
@ -141,6 +141,15 @@ func doRun(ctx *context.Context, client client.Client) error {
return client.CreateFile(ctx, ctx.Config.Brew.CommitAuthor, ctx.Config.Brew.GitHub, content, path, msg)
}
func getFormat(ctx *context.Context) string {
for _, override := range ctx.Config.Archive.FormatOverrides {
if strings.HasPrefix("darwin", override.Goos) {
return override.Format
}
}
return ctx.Config.Archive.Format
}
func buildFormula(ctx *context.Context, artifact artifact.Artifact) (bytes.Buffer, error) {
data, err := dataFor(ctx, artifact)
if err != nil {

View File

@ -107,6 +107,15 @@ func TestRunPipe(t *testing.T) {
"custom_download_strategy": func(ctx *context.Context) {
ctx.Config.Brew.DownloadStrategy = "GitHubPrivateRepositoryReleaseDownloadStrategy"
},
"binary_overriden": func(ctx *context.Context) {
ctx.Config.Archive.Format = "binary"
ctx.Config.Archive.FormatOverrides = []config.FormatOverride{
{
Goos: "darwin",
Format: "zip",
},
}
},
} {
t.Run(name, func(t *testing.T) {
folder, err := ioutil.TempDir("", "goreleasertest")
@ -150,9 +159,10 @@ func TestRunPipe(t *testing.T) {
},
}
fn(ctx)
var path = filepath.Join(folder, "bin.tar.gz")
var format = getFormat(ctx)
var path = filepath.Join(folder, "bin."+format)
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin.tar.gz",
Name: "bin." + format,
Path: path,
Goos: "darwin",
Goarch: "amd64",
@ -168,7 +178,7 @@ func TestRunPipe(t *testing.T) {
assert.True(t, client.CreatedFile)
var golden = fmt.Sprintf("testdata/%s.rb.golden", name)
if *update {
ioutil.WriteFile(golden, []byte(client.Content), 0655)
assert.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655))
}
bts, err := ioutil.ReadFile(golden)
assert.NoError(t, err)

View File

@ -0,0 +1,34 @@
class BinaryOverriden < Formula
desc "A run pipe test formula"
homepage "https://github.com/goreleaser"
url "https://github.com/test/test/releases/download/v1.0.1/bin.zip"
version "1.0.1"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
depends_on "zsh"
depends_on "bash"
conflicts_with "gtk+"
conflicts_with "qt"
def install
bin.install "foo"
end
def caveats; <<~EOS
don't do this
EOS
end
plist_options :startup => false
def plist; <<~EOS
<xml>whatever</xml>
EOS
end
test do
system "true"
system "#{bin}/foo -h"
end
end