You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-03 00:57:43 +02:00
allow ignoring specific builds
This commit is contained in:
@ -38,11 +38,17 @@ type Hooks struct {
|
|||||||
Post string
|
Post string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IgnoredBuild represents a build ignored by the user
|
||||||
|
type IgnoredBuild struct {
|
||||||
|
Goos, Goarch, Goarm string
|
||||||
|
}
|
||||||
|
|
||||||
// Build contains the build configuration section
|
// Build contains the build configuration section
|
||||||
type Build struct {
|
type Build struct {
|
||||||
Goos []string
|
Goos []string
|
||||||
Goarch []string
|
Goarch []string
|
||||||
Goarm []string
|
Goarm []string
|
||||||
|
Ignore []IgnoredBuild
|
||||||
Main string
|
Main string
|
||||||
Ldflags string
|
Ldflags string
|
||||||
Flags string
|
Flags string
|
||||||
|
@ -29,7 +29,7 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
}
|
}
|
||||||
sem := make(chan bool, 4)
|
sem := make(chan bool, 4)
|
||||||
var g errgroup.Group
|
var g errgroup.Group
|
||||||
for _, target := range allBuildTargets(ctx) {
|
for _, target := range buildTargets(ctx) {
|
||||||
name, err := nameFor(ctx, target)
|
name, err := nameFor(ctx, target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/config"
|
"github.com/goreleaser/goreleaser/config"
|
||||||
@ -50,7 +51,7 @@ func TestInvalidNameTemplate(t *testing.T) {
|
|||||||
|
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Archive: config.Archive{
|
Archive: config.Archive{
|
||||||
NameTemplate: "{{.Binaryyy}}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
NameTemplate: "{{.Binary}_{{.Os}}_{{.Arch}}_{{.Version}}",
|
||||||
},
|
},
|
||||||
Build: config.Build{
|
Build: config.Build{
|
||||||
Binary: "test",
|
Binary: "test",
|
||||||
@ -64,6 +65,7 @@ func TestInvalidNameTemplate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err := nameFor(ctx, buildTarget{"darwin", "amd64", ""})
|
_, err := nameFor(ctx, buildTarget{"darwin", "amd64", ""})
|
||||||
|
log.Println(err.Error())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,24 @@ func (t buildTarget) String() string {
|
|||||||
return fmt.Sprintf("%v%v%v", t.goos, t.goarch, t.goarm)
|
return fmt.Sprintf("%v%v%v", t.goos, t.goarch, t.goarm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildTargets(ctx *context.Context) (targets []buildTarget) {
|
||||||
|
for _, target := range allBuildTargets(ctx) {
|
||||||
|
if !valid(target) {
|
||||||
|
log.Println("Skipped invalid build target:", target)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ignored(ctx, target) {
|
||||||
|
log.Println("Skipped ignored build target:", target)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
targets = append(targets, target)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func allBuildTargets(ctx *context.Context) (targets []buildTarget) {
|
func allBuildTargets(ctx *context.Context) (targets []buildTarget) {
|
||||||
for _, goos := range ctx.Config.Build.Goos {
|
for _, goos := range ctx.Config.Build.Goos {
|
||||||
for _, goarch := range ctx.Config.Build.Goarch {
|
for _, goarch := range ctx.Config.Build.Goarch {
|
||||||
if !valid(goos, goarch) {
|
|
||||||
log.Printf("Skipped build for %v/%v\n", goos, goarch)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if goarch == "arm" {
|
if goarch == "arm" {
|
||||||
for _, goarm := range ctx.Config.Build.Goarm {
|
for _, goarm := range ctx.Config.Build.Goarm {
|
||||||
targets = append(targets, buildTarget{goos, goarch, goarm})
|
targets = append(targets, buildTarget{goos, goarch, goarm})
|
||||||
@ -37,3 +48,23 @@ func allBuildTargets(ctx *context.Context) (targets []buildTarget) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ignored(ctx *context.Context, target buildTarget) bool {
|
||||||
|
for _, ig := range ctx.Config.Build.Ignore {
|
||||||
|
var ignored = buildTarget{ig.Goos, ig.Goarch, ig.Goarm}
|
||||||
|
if ignored == target {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func valid(target buildTarget) bool {
|
||||||
|
var s = target.goos + target.goarch
|
||||||
|
for _, a := range valids {
|
||||||
|
if a == s {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
112
pipeline/build/target_test.go
Normal file
112
pipeline/build/target_test.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/config"
|
||||||
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAllBuildTargets(t *testing.T) {
|
||||||
|
var assert = assert.New(t)
|
||||||
|
var ctx = &context.Context{
|
||||||
|
Config: config.Project{
|
||||||
|
Build: config.Build{
|
||||||
|
Goos: []string{
|
||||||
|
"linux",
|
||||||
|
"darwin",
|
||||||
|
"freebsd",
|
||||||
|
},
|
||||||
|
Goarch: []string{
|
||||||
|
"386",
|
||||||
|
"amd64",
|
||||||
|
"arm",
|
||||||
|
"arm64",
|
||||||
|
},
|
||||||
|
Goarm: []string{
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
},
|
||||||
|
Ignore: []config.IgnoredBuild{
|
||||||
|
{
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "386",
|
||||||
|
}, {
|
||||||
|
Goos: "linux",
|
||||||
|
Goarch: "arm",
|
||||||
|
Goarm: "7",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.Equal([]buildTarget{
|
||||||
|
buildTarget{"linux", "386", ""},
|
||||||
|
buildTarget{"linux", "amd64", ""},
|
||||||
|
buildTarget{"linux", "arm", "6"},
|
||||||
|
buildTarget{"linux", "arm64", ""},
|
||||||
|
buildTarget{"darwin", "amd64", ""},
|
||||||
|
buildTarget{"freebsd", "386", ""},
|
||||||
|
buildTarget{"freebsd", "amd64", ""},
|
||||||
|
buildTarget{"freebsd", "arm", "6"},
|
||||||
|
buildTarget{"freebsd", "arm", "7"},
|
||||||
|
}, buildTargets(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidGoosGoarchCombos(t *testing.T) {
|
||||||
|
var platforms = []struct {
|
||||||
|
os, arch string
|
||||||
|
}{
|
||||||
|
{"android", "arm"},
|
||||||
|
{"darwin", "386"},
|
||||||
|
{"darwin", "amd64"},
|
||||||
|
{"dragonfly", "amd64"},
|
||||||
|
{"freebsd", "386"},
|
||||||
|
{"freebsd", "amd64"},
|
||||||
|
{"freebsd", "arm"},
|
||||||
|
{"linux", "386"},
|
||||||
|
{"linux", "amd64"},
|
||||||
|
{"linux", "arm"},
|
||||||
|
{"linux", "arm64"},
|
||||||
|
{"linux", "mips"},
|
||||||
|
{"linux", "mipsle"},
|
||||||
|
{"linux", "mips64"},
|
||||||
|
{"linux", "mips64le"},
|
||||||
|
{"netbsd", "386"},
|
||||||
|
{"netbsd", "amd64"},
|
||||||
|
{"netbsd", "arm"},
|
||||||
|
{"openbsd", "386"},
|
||||||
|
{"openbsd", "amd64"},
|
||||||
|
{"plan9", "386"},
|
||||||
|
{"plan9", "amd64"},
|
||||||
|
{"solaris", "amd64"},
|
||||||
|
{"windows", "386"},
|
||||||
|
{"windows", "amd64"},
|
||||||
|
}
|
||||||
|
for _, p := range platforms {
|
||||||
|
t.Run(fmt.Sprintf("%v %v is valid", p.os, p.arch), func(t *testing.T) {
|
||||||
|
assert.True(t, valid(buildTarget{p.os, p.arch, ""}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvalidGoosGoarchCombos(t *testing.T) {
|
||||||
|
var platforms = []struct {
|
||||||
|
os, arch string
|
||||||
|
}{
|
||||||
|
{"darwin", "arm"},
|
||||||
|
{"darwin", "arm64"},
|
||||||
|
{"windows", "arm"},
|
||||||
|
{"windows", "arm64"},
|
||||||
|
{"linux", "ppc64"},
|
||||||
|
{"linux", "ppc64le"},
|
||||||
|
{"openbsd", "arm"},
|
||||||
|
}
|
||||||
|
for _, p := range platforms {
|
||||||
|
t.Run(fmt.Sprintf("%v %v is invalid", p.os, p.arch), func(t *testing.T) {
|
||||||
|
assert.False(t, valid(buildTarget{p.os, p.arch, ""}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -33,13 +33,3 @@ var valids = []string{
|
|||||||
"windows386",
|
"windows386",
|
||||||
"windowsamd64",
|
"windowsamd64",
|
||||||
}
|
}
|
||||||
|
|
||||||
func valid(goos, goarch string) bool {
|
|
||||||
var s = goos + goarch
|
|
||||||
for _, a := range valids {
|
|
||||||
if a == s {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
package build
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestValid(t *testing.T) {
|
|
||||||
var platforms = []struct {
|
|
||||||
os, arch string
|
|
||||||
}{
|
|
||||||
{"android", "arm"},
|
|
||||||
{"darwin", "386"},
|
|
||||||
{"darwin", "amd64"},
|
|
||||||
{"dragonfly", "amd64"},
|
|
||||||
{"freebsd", "386"},
|
|
||||||
{"freebsd", "amd64"},
|
|
||||||
{"freebsd", "arm"},
|
|
||||||
{"linux", "386"},
|
|
||||||
{"linux", "amd64"},
|
|
||||||
{"linux", "arm"},
|
|
||||||
{"linux", "arm64"},
|
|
||||||
{"linux", "mips"},
|
|
||||||
{"linux", "mipsle"},
|
|
||||||
{"linux", "mips64"},
|
|
||||||
{"linux", "mips64le"},
|
|
||||||
{"netbsd", "386"},
|
|
||||||
{"netbsd", "amd64"},
|
|
||||||
{"netbsd", "arm"},
|
|
||||||
{"openbsd", "386"},
|
|
||||||
{"openbsd", "amd64"},
|
|
||||||
{"plan9", "386"},
|
|
||||||
{"plan9", "amd64"},
|
|
||||||
{"solaris", "amd64"},
|
|
||||||
{"windows", "386"},
|
|
||||||
{"windows", "amd64"},
|
|
||||||
}
|
|
||||||
for _, p := range platforms {
|
|
||||||
t.Run(fmt.Sprintf("%v %v is valid", p.os, p.arch), func(t *testing.T) {
|
|
||||||
assert.True(t, valid(p.os, p.arch))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInvalid(t *testing.T) {
|
|
||||||
var platforms = []struct {
|
|
||||||
os, arch string
|
|
||||||
}{
|
|
||||||
{"darwin", "arm"},
|
|
||||||
{"darwin", "arm64"},
|
|
||||||
{"windows", "arm"},
|
|
||||||
{"windows", "arm64"},
|
|
||||||
{"linux", "ppc64"},
|
|
||||||
{"linux", "ppc64le"},
|
|
||||||
{"openbsd", "arm"},
|
|
||||||
}
|
|
||||||
for _, p := range platforms {
|
|
||||||
t.Run(fmt.Sprintf("%v %v is invalid", p.os, p.arch), func(t *testing.T) {
|
|
||||||
assert.False(t, valid(p.os, p.arch))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user