Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve --single-target (#4442)
closes #4437 closes #4426 --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
168 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/caarlos0/log" | ||
"github.com/goreleaser/goreleaser/pkg/context" | ||
) | ||
|
||
func filter(ctx *context.Context, targets []string) []string { | ||
if !ctx.Partial { | ||
return targets | ||
} | ||
|
||
target := ctx.PartialTarget | ||
log.WithField("match", fmt.Sprintf("target=%s", target)).Infof("partial build") | ||
|
||
var result []string | ||
for _, t := range targets { | ||
if !strings.HasPrefix(t, target) { | ||
continue | ||
} | ||
result = append(result, t) | ||
break | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package build | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/goreleaser/goreleaser/internal/testctx" | ||
"github.com/goreleaser/goreleaser/pkg/context" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var filterTestTargets = []string{ | ||
"linux_amd64_v1", | ||
"linux_arm64", | ||
"linux_riscv64", | ||
"darwin_amd64_v1", | ||
"darwin_amd64_v2", | ||
"darwin_arm64", | ||
} | ||
|
||
func TestFilter(t *testing.T) { | ||
t.Run("none", func(t *testing.T) { | ||
ctx := testctx.New() | ||
require.Equal(t, filterTestTargets, filter(ctx, filterTestTargets)) | ||
}) | ||
|
||
t.Run("target", func(t *testing.T) { | ||
ctx := testctx.New(func(ctx *context.Context) { | ||
ctx.Partial = true | ||
ctx.PartialTarget = "darwin_amd64" | ||
}) | ||
require.Equal(t, []string{ | ||
"darwin_amd64_v1", | ||
}, filter(ctx, filterTestTargets)) | ||
}) | ||
|
||
t.Run("target no match", func(t *testing.T) { | ||
ctx := testctx.New(func(ctx *context.Context) { | ||
ctx.Partial = true | ||
ctx.PartialTarget = "linux_amd64_v1" | ||
}) | ||
require.Empty(t, filter(ctx, []string{"darwin_amd64_v1"})) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package partial | ||
|
||
import ( | ||
"os" | ||
"runtime" | ||
|
||
"github.com/charmbracelet/x/exp/ordered" | ||
"github.com/goreleaser/goreleaser/pkg/context" | ||
) | ||
|
||
type Pipe struct{} | ||
|
||
func (Pipe) String() string { return "partial" } | ||
func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Partial } | ||
|
||
func (Pipe) Run(ctx *context.Context) error { | ||
ctx.PartialTarget = getFilter() | ||
return nil | ||
} | ||
|
||
func getFilter() string { | ||
goos := ordered.First(os.Getenv("GGOOS"), os.Getenv("GOOS"), runtime.GOOS) | ||
goarch := ordered.First(os.Getenv("GGOARCH"), os.Getenv("GOARCH"), runtime.GOARCH) | ||
return goos + "_" + goarch | ||
} |
Oops, something went wrong.