mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-06-06 23:46:42 +02:00
feat: templates in upx.enabled (#4269)
refs https://github.com/orgs/goreleaser/discussions/4268
This commit is contained in:
parent
983cc3755d
commit
62cc45aa50
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe"
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||||
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
)
|
)
|
||||||
@ -32,7 +33,11 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
g := semerrgroup.NewSkipAware(semerrgroup.New(ctx.Parallelism))
|
g := semerrgroup.NewSkipAware(semerrgroup.New(ctx.Parallelism))
|
||||||
for _, upx := range ctx.Config.UPXs {
|
for _, upx := range ctx.Config.UPXs {
|
||||||
upx := upx
|
upx := upx
|
||||||
if !upx.Enabled {
|
enabled, err := tmpl.New(ctx).Bool(upx.Enabled)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !enabled {
|
||||||
return pipe.Skip("upx is not enabled")
|
return pipe.Skip("upx is not enabled")
|
||||||
}
|
}
|
||||||
if _, err := exec.LookPath(upx.Binary); err != nil {
|
if _, err := exec.LookPath(upx.Binary); err != nil {
|
||||||
|
@ -50,32 +50,32 @@ func TestRun(t *testing.T) {
|
|||||||
ctx := testctx.NewWithCfg(config.Project{
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
UPXs: []config.UPX{
|
UPXs: []config.UPX{
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: "true",
|
||||||
IDs: []string{"1"},
|
IDs: []string{"1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: "true",
|
||||||
IDs: []string{"2"},
|
IDs: []string{"2"},
|
||||||
Compress: "best",
|
Compress: "best",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: "true",
|
||||||
IDs: []string{"3"},
|
IDs: []string{"3"},
|
||||||
Compress: "9",
|
Compress: "9",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: "true",
|
||||||
IDs: []string{"4"},
|
IDs: []string{"4"},
|
||||||
Compress: "8",
|
Compress: "8",
|
||||||
LZMA: true,
|
LZMA: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: `{{ eq .Env.UPX "1" }}`,
|
||||||
IDs: []string{"5"},
|
IDs: []string{"5"},
|
||||||
Brute: true,
|
Brute: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
}, testctx.WithEnv(map[string]string{"UPX": "1"}))
|
||||||
|
|
||||||
tmp := t.TempDir()
|
tmp := t.TempDir()
|
||||||
main := filepath.Join(tmp, "main.go")
|
main := filepath.Join(tmp, "main.go")
|
||||||
@ -119,20 +119,42 @@ func TestRun(t *testing.T) {
|
|||||||
require.NoError(t, Pipe{}.Run(ctx))
|
require.NoError(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDisabled(t *testing.T) {
|
func TestEnabled(t *testing.T) {
|
||||||
|
t.Run("no config", func(t *testing.T) {
|
||||||
ctx := testctx.NewWithCfg(config.Project{
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
UPXs: []config.UPX{
|
UPXs: []config.UPX{
|
||||||
{},
|
{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||||
|
})
|
||||||
|
t.Run("tmpl", func(t *testing.T) {
|
||||||
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
|
UPXs: []config.UPX{
|
||||||
|
{
|
||||||
|
Enabled: `{{ printf "false" }}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
|
||||||
|
})
|
||||||
|
t.Run("invalid template", func(t *testing.T) {
|
||||||
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
|
UPXs: []config.UPX{
|
||||||
|
{
|
||||||
|
Enabled: `{{ .Foo }}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpxNotInstalled(t *testing.T) {
|
func TestUpxNotInstalled(t *testing.T) {
|
||||||
ctx := testctx.NewWithCfg(config.Project{
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
UPXs: []config.UPX{
|
UPXs: []config.UPX{
|
||||||
{
|
{
|
||||||
Enabled: true,
|
Enabled: "true",
|
||||||
Binary: "fakeupx",
|
Binary: "fakeupx",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -682,7 +682,7 @@ type UniversalBinary struct {
|
|||||||
|
|
||||||
// UPX allows to compress binaries with `upx`.
|
// UPX allows to compress binaries with `upx`.
|
||||||
type UPX struct {
|
type UPX struct {
|
||||||
Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
|
Enabled string `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"oneof_type=string;boolean"`
|
||||||
IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"`
|
IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"`
|
||||||
Goos []string `yaml:"goos,omitempty" json:"goos,omitempty"`
|
Goos []string `yaml:"goos,omitempty" json:"goos,omitempty"`
|
||||||
Goarch []string `yaml:"goarch,omitempty" json:"goarch,omitempty"`
|
Goarch []string `yaml:"goarch,omitempty" json:"goarch,omitempty"`
|
||||||
|
@ -12,44 +12,43 @@ the _de facto_ tool for the job.
|
|||||||
GoReleaser has been able to integrate with it via custom [build hooks][bhooks],
|
GoReleaser has been able to integrate with it via custom [build hooks][bhooks],
|
||||||
and now UPX has its own configuration section:
|
and now UPX has its own configuration section:
|
||||||
|
|
||||||
!!! warning
|
!!! warning "Compatibility"
|
||||||
|
|
||||||
`upx` does not support all platforms! Make sure to check
|
`upx` does not support all platforms! Make sure to check
|
||||||
[their issues][upx-issues] and to test your packed binaries first.
|
[their issues][upx-issues] and to test your packed binaries.
|
||||||
|
|
||||||
Namely, _macOS Ventura_ is not supported at the moment.
|
Namely, _macOS Ventura_ is not supported at the moment.
|
||||||
|
|
||||||
Future GoReleaser releases will add more filters so you can cherry-pick
|
|
||||||
which platforms you want to pack or not.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yaml
|
# .goreleaser.yaml
|
||||||
upx:
|
upx:
|
||||||
-
|
- # Whether to enable it or not.
|
||||||
# Whether to enable it or not.
|
#
|
||||||
|
# Templates: allowed (since v1.21).
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
||||||
# Filter by build ID.
|
# Filter by build ID.
|
||||||
ids: [ build1, build2 ]
|
ids: [build1, build2]
|
||||||
|
|
||||||
# Filter by GOOS.
|
# Filter by GOOS.
|
||||||
#
|
#
|
||||||
# Since: v1.19
|
# Since: v1.19
|
||||||
goos: [ linux , darwin ]
|
goos: [linux, darwin]
|
||||||
|
|
||||||
# Filter by GOARCH.
|
# Filter by GOARCH.
|
||||||
#
|
#
|
||||||
# Since: v1.19
|
# Since: v1.19
|
||||||
goarch: [ arm, amd64 ]
|
goarch: [arm, amd64]
|
||||||
|
|
||||||
# Filter by GOARM.
|
# Filter by GOARM.
|
||||||
#
|
#
|
||||||
# Since: v1.19
|
# Since: v1.19
|
||||||
goarm: [ 8 ]
|
goarm: [8]
|
||||||
|
|
||||||
# Filter by GOAMD64.
|
# Filter by GOAMD64.
|
||||||
#
|
#
|
||||||
# Since: v1.19
|
# Since: v1.19
|
||||||
goamd64: [ v1 ]
|
goamd64: [v1]
|
||||||
|
|
||||||
# Compress argument.
|
# Compress argument.
|
||||||
# Valid options are from '1' (faster) to '9' (better), and 'best'.
|
# Valid options are from '1' (faster) to '9' (better), and 'best'.
|
||||||
@ -62,12 +61,17 @@ upx:
|
|||||||
brute: true
|
brute: true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!!! info
|
||||||
|
|
||||||
|
If `upx` is not in `$PATH`, GoReleaser will automatically avoid running it.
|
||||||
|
|
||||||
Notice you can define multiple `upx` definitions, filtering by various fields.
|
Notice you can define multiple `upx` definitions, filtering by various fields.
|
||||||
You can use that to have different compression options depending on the target
|
You can use that to have different compression options depending on the target
|
||||||
OS, for instance - or even to run it only on a few selected platforms.
|
OS, for instance - or even to run it only on a few selected platforms.
|
||||||
|
|
||||||
!!! info
|
!!! tip
|
||||||
If `upx` is not in `$PATH`, GoReleaser will automatically avoid running it.
|
|
||||||
|
Learn more about the [name template engine](templates.md).
|
||||||
|
|
||||||
[upx]: https://upx.github.io/
|
[upx]: https://upx.github.io/
|
||||||
[upx-issues]: https://github.com/upx/upx/issues
|
[upx-issues]: https://github.com/upx/upx/issues
|
||||||
|
Loading…
x
Reference in New Issue
Block a user