mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
refactor: fixed brew pipe
This commit is contained in:
parent
574b2942b3
commit
248810535e
@ -1,7 +1,10 @@
|
||||
// Package artifact provides the core artifact storage for goreleaser
|
||||
package artifact
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Type defines the type of an artifact
|
||||
type Type int
|
||||
@ -104,12 +107,22 @@ func ByType(t Type) Filter {
|
||||
// Filter filters the artifact list, returning a new instance.
|
||||
// There are some pre-defined filters but anything of the Type Filter
|
||||
// is accepted.
|
||||
func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
|
||||
func (artifacts *Artifacts) Filter(filters ...Filter) Artifacts {
|
||||
var result = New()
|
||||
for _, a := range artifacts.items {
|
||||
if filter(a) {
|
||||
if apply(a, filters) {
|
||||
fmt.Println("add", a)
|
||||
result.Add(a)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func apply(a Artifact, filters []Filter) bool {
|
||||
for _, filter := range filters {
|
||||
if !filter(a) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func TestAdd(t *testing.T) {
|
||||
for _, a := range []Artifact{
|
||||
{
|
||||
Name: "foo",
|
||||
Type: Archive,
|
||||
Type: UploadableArchive,
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
@ -56,11 +56,16 @@ func TestFilter(t *testing.T) {
|
||||
Name: "check",
|
||||
Type: Checksum,
|
||||
},
|
||||
{
|
||||
Name: "checkzumm",
|
||||
Type: Checksum,
|
||||
},
|
||||
}
|
||||
var artifacts = New()
|
||||
for _, a := range data {
|
||||
artifacts.Add(a)
|
||||
}
|
||||
|
||||
assert.Len(t, artifacts.Filter(ByGoos("linux")).items, 1)
|
||||
assert.Len(t, artifacts.Filter(ByGoos("darwin")).items, 0)
|
||||
|
||||
@ -70,8 +75,12 @@ func TestFilter(t *testing.T) {
|
||||
assert.Len(t, artifacts.Filter(ByGoarm("6")).items, 1)
|
||||
assert.Len(t, artifacts.Filter(ByGoarm("7")).items, 0)
|
||||
|
||||
assert.Len(t, artifacts.Filter(ByType(Checksum)).items, 1)
|
||||
assert.Len(t, artifacts.Filter(ByType(Checksum)).items, 2)
|
||||
assert.Len(t, artifacts.Filter(ByType(Binary)).items, 0)
|
||||
|
||||
assert.Len(t, artifacts.Filter(ByType(Checksum), func(a Artifact) bool {
|
||||
return a.Name == "checkzumm"
|
||||
}).List(), 1)
|
||||
}
|
||||
|
||||
func TestGroupByPlatform(t *testing.T) {
|
||||
|
@ -10,18 +10,22 @@ 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/archiveformat"
|
||||
"github.com/goreleaser/goreleaser/internal/client"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
)
|
||||
|
||||
// ErrNoDarwin64Build when there is no build for darwin_amd64 (goos doesn't
|
||||
// contain darwin and/or goarch doesn't contain amd64)
|
||||
var ErrNoDarwin64Build = errors.New("brew tap requires a darwin amd64 build")
|
||||
// ErrNoDarwin64Build when there is no build for darwin_amd64
|
||||
var ErrNoDarwin64Build = errors.New("brew tap requires one darwin amd64 build")
|
||||
|
||||
// ErrTooManyDarwin64Builds when there are too many builds for darwin_amd64
|
||||
var ErrTooManyDarwin64Builds = errors.New("brew tap requires at most one darwin amd64 build")
|
||||
|
||||
const platform = "darwinamd64"
|
||||
|
||||
@ -98,28 +102,31 @@ func doRun(ctx *context.Context, client client.Client) error {
|
||||
return pipeline.Skip("archive format is binary")
|
||||
}
|
||||
|
||||
var group = ctx.Binaries["darwinamd64"]
|
||||
if group == nil {
|
||||
var archives = ctx.Artifacts.Filter(
|
||||
artifact.ByGoos("darwin"),
|
||||
artifact.ByGoarch("amd64"),
|
||||
artifact.ByGoarch(""),
|
||||
artifact.ByType(artifact.UploadableArchive),
|
||||
).List()
|
||||
if len(archives) == 0 {
|
||||
return ErrNoDarwin64Build
|
||||
}
|
||||
var folder string
|
||||
for f := range group {
|
||||
folder = f
|
||||
break
|
||||
if len(archives) > 0 {
|
||||
return ErrTooManyDarwin64Builds
|
||||
}
|
||||
var path = filepath.Join(ctx.Config.Brew.Folder, ctx.Config.ProjectName+".rb")
|
||||
log.WithField("formula", path).
|
||||
WithField("repo", ctx.Config.Brew.GitHub.String()).
|
||||
Info("pushing")
|
||||
content, err := buildFormula(ctx, client, folder)
|
||||
content, err := buildFormula(ctx, client, archives[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.CreateFile(ctx, content, path)
|
||||
}
|
||||
|
||||
func buildFormula(ctx *context.Context, client client.Client, folder string) (bytes.Buffer, error) {
|
||||
data, err := dataFor(ctx, client, folder)
|
||||
func buildFormula(ctx *context.Context, client client.Client, artifact artifact.Artifact) (bytes.Buffer, error) {
|
||||
data, err := dataFor(ctx, client, artifact)
|
||||
if err != nil {
|
||||
return bytes.Buffer{}, err
|
||||
}
|
||||
@ -135,9 +142,9 @@ func doBuildFormula(data templateData) (out bytes.Buffer, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func dataFor(ctx *context.Context, client client.Client, folder string) (result templateData, err error) {
|
||||
var file = folder + "." + archiveformat.For(ctx, platform)
|
||||
sum, err := checksum.SHA256(filepath.Join(ctx.Config.Dist, file))
|
||||
func dataFor(ctx *context.Context, client client.Client, artifact artifact.Artifact) (result templateData, err error) {
|
||||
var file = artifact.Path
|
||||
sum, err := checksum.SHA256(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user