1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

fix: brew tests/multiple darwin builds/gh enterprise

This commit is contained in:
Carlos Alexandro Becker 2017-12-17 20:14:41 -02:00
parent 9dcfcd4db6
commit f433bcb59c
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
4 changed files with 129 additions and 27 deletions

View File

@ -1,5 +1,3 @@
// Package brew implements the Pipe, providing formula generation and
// uploading it to a configured repo.
package brew
import (
@ -10,13 +8,12 @@ import (
"strings"
"text/template"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/checksum"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/pipeline"
)
@ -106,14 +103,14 @@ func doRun(ctx *context.Context, client client.Client) error {
artifact.And(
artifact.ByGoos("darwin"),
artifact.ByGoarch("amd64"),
artifact.ByGoarch(""),
artifact.ByGoarm(""),
artifact.ByType(artifact.UploadableArchive),
),
).List()
if len(archives) == 0 {
return ErrNoDarwin64Build
}
if len(archives) > 0 {
if len(archives) > 1 {
return ErrTooManyDarwin64Builds
}
var path = filepath.Join(ctx.Config.Brew.Folder, ctx.Config.ProjectName+".rb")
@ -145,8 +142,7 @@ func doBuildFormula(data templateData) (out bytes.Buffer, err error) {
}
func dataFor(ctx *context.Context, client client.Client, artifact artifact.Artifact) (result templateData, err error) {
var file = artifact.Path
sum, err := checksum.SHA256(file)
sum, err := checksum.SHA256(artifact.Path)
if err != nil {
return
}
@ -163,7 +159,7 @@ func dataFor(ctx *context.Context, client client.Client, artifact artifact.Artif
Tag: ctx.Git.CurrentTag,
Version: ctx.Version,
Caveats: ctx.Config.Brew.Caveats,
File: file,
File: artifact.Name,
SHA256: sum,
Dependencies: ctx.Config.Brew.Dependencies,
Conflicts: ctx.Config.Brew.Conflicts,

View File

@ -9,6 +9,7 @@ import (
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/stretchr/testify/assert"
)
@ -93,7 +94,8 @@ func TestRunPipe(t *testing.T) {
Git: context.GitInfo{
CurrentTag: "v1.0.1",
},
Version: "1.0.1",
Version: "1.0.1",
Artifacts: artifact.New(),
Config: config.Project{
Dist: folder,
ProjectName: "run-pipe",
@ -124,31 +126,53 @@ func TestRunPipe(t *testing.T) {
Publish: true,
}
var path = filepath.Join(folder, "bin.tar.gz")
ctx.AddBinary("darwinamd64", "bin", "bin", path)
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin.tar.gz",
Path: path,
Goos: "darwin",
Goarch: "amd64",
Type: artifact.UploadableArchive,
})
client := &DummyClient{}
assert.Error(t, doRun(ctx, client))
assert.False(t, client.CreatedFile)
_, err = os.Create(path)
assert.NoError(t, err)
assert.NoError(t, doRun(ctx, client))
assert.True(t, client.CreatedFile)
bts, err := ioutil.ReadFile("testdata/run_pipe.rb")
assert.NoError(t, err)
// ioutil.WriteFile("testdata/run_pipe.rb", []byte(client.Content), 0644)
t.Run("default git url", func(tt *testing.T) {
assert.NoError(tt, doRun(ctx, client))
assert.True(tt, client.CreatedFile)
assert.Equal(t, string(bts), client.Content)
bts, err := ioutil.ReadFile("testdata/run_pipe.rb")
assert.NoError(tt, err)
// TODO: make writing this file toggleable somehow?
// ioutil.WriteFile("testdata/run_pipe.rb", []byte(client.Content), 0644)
assert.Equal(tt, string(bts), client.Content)
})
t.Run("github enterprise url", func(tt *testing.T) {
ctx.Config.GitHubURLs.Download = "http://github.example.org"
assert.NoError(tt, doRun(ctx, client))
assert.True(tt, client.CreatedFile)
bts, err := ioutil.ReadFile("testdata/run_pipe_enterprise.rb")
assert.NoError(tt, err)
// TODO: make writing this file toggleable somehow?
// ioutil.WriteFile("testdata/run_pipe_enterprise.rb", []byte(client.Content), 0644)
assert.Equal(tt, string(bts), client.Content)
})
}
// TODO: this test is irrelevant and can probavly be removed
func TestRunPipeFormatOverride(t *testing.T) {
folder, err := ioutil.TempDir("", "goreleasertest")
assert.NoError(t, err)
var path = filepath.Join(folder, "bin.zip")
_, err = os.Create(path)
assert.NoError(t, err)
var ctx = &context.Context{
Config: config.Project{
var ctx = context.New(
config.Project{
Dist: folder,
Archive: config.Archive{
Format: "tar.gz",
@ -166,9 +190,15 @@ func TestRunPipeFormatOverride(t *testing.T) {
},
},
},
Publish: true,
}
ctx.AddBinary("darwinamd64", "bin", "bin", path)
)
ctx.Publish = true
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin.zip",
Path: path,
Goos: "darwin",
Goarch: "amd64",
Type: artifact.UploadableArchive,
})
client := &DummyClient{}
assert.NoError(t, doRun(ctx, client))
assert.True(t, client.CreatedFile)
@ -195,6 +225,40 @@ func TestRunPipeNoDarwin64Build(t *testing.T) {
assert.False(t, client.CreatedFile)
}
func TestRunPipeMultipleDarwin64Build(t *testing.T) {
var ctx = context.New(
config.Project{
Archive: config.Archive{
Format: "tar.gz",
},
Brew: config.Homebrew{
GitHub: config.Repo{
Owner: "test",
Name: "test",
},
},
},
)
ctx.Publish = true
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin1",
Path: "doesnt mather",
Goos: "darwin",
Goarch: "amd64",
Type: artifact.UploadableArchive,
})
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin2",
Path: "doesnt mather",
Goos: "darwin",
Goarch: "amd64",
Type: artifact.UploadableArchive,
})
client := &DummyClient{}
assert.Equal(t, ErrTooManyDarwin64Builds, doRun(ctx, client))
assert.False(t, client.CreatedFile)
}
func TestRunPipeBrewNotSetup(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{},
@ -206,9 +270,8 @@ func TestRunPipeBrewNotSetup(t *testing.T) {
}
func TestRunPipeBinaryRelease(t *testing.T) {
var ctx = &context.Context{
Publish: true,
Config: config.Project{
var ctx = context.New(
config.Project{
Archive: config.Archive{
Format: "binary",
},
@ -219,8 +282,15 @@ func TestRunPipeBinaryRelease(t *testing.T) {
},
},
},
}
ctx.AddBinary("darwinamd64", "foo", "bar", "baz")
)
ctx.Publish = true
ctx.Artifacts.Add(artifact.Artifact{
Name: "bin",
Path: "doesnt mather",
Goos: "darwin",
Goarch: "amd64",
Type: artifact.Binary,
})
client := &DummyClient{}
testlib.AssertSkipped(t, doRun(ctx, client))
assert.False(t, client.CreatedFile)

3
pipeline/brew/doc.go Normal file
View File

@ -0,0 +1,3 @@
// Package brew implements the Pipe, providing formula generation and
// uploading it to a configured repo.
package brew

View File

@ -0,0 +1,33 @@
class RunPipe < Formula
desc "A run pipe test formula"
homepage "https://github.com/goreleaser"
url "http://github.example.org/test/test/releases/download/v1.0.1/bin.tar.gz"
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
"don't do this"
end
plist_options :startup => false
def plist; <<-EOS.undent
<xml>whatever</xml>
EOS
end
test do
system "true"
system "#{bin}/foo -h"
end
end