feat: builds. no_unique_dist_dir (#2280)

* Implemented build option output_path

* feat: output path renamed to dist_path

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: CR

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* fix: binary name

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

Co-authored-by: Thomas Meckel <tmeckel@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2021-06-06 19:44:24 -03:00
committed by GitHub
co-authored by Thomas Meckel
parent 73348acd96
commit c49c771220
4 changed files with 65 additions and 26 deletions
+6 -2
View File
@@ -186,10 +186,14 @@ func buildOptionsForTarget(ctx *context.Context, build config.Build, target stri
build.Binary = binary
name := build.Binary + ext
dir := fmt.Sprintf("%s_%s", build.ID, target)
if build.NoUniqueDistDir {
dir = ""
}
path, err := filepath.Abs(
filepath.Join(
ctx.Config.Dist,
fmt.Sprintf("%s_%s", build.ID, target),
dir,
name,
),
)
@@ -198,7 +202,7 @@ func buildOptionsForTarget(ctx *context.Context, build config.Build, target stri
}
log.WithField("binary", path).Info("building")
buildOpts.Name = name
buildOpts.Name = filepath.Base(name)
buildOpts.Path = path
return &buildOpts, nil
}
+28 -3
View File
@@ -140,6 +140,7 @@ func TestRunFullPipe(t *testing.T) {
}
ctx := context.New(config)
ctx.Git.CurrentTag = "2.4.5"
require.NoError(t, Pipe{}.Default(ctx))
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
Name: "testing",
@@ -712,6 +713,7 @@ func TestBuildOptionsForTarget(t *testing.T) {
name string
build config.Build
expectedOpts *api.Options
expectedErr string
}{
{
name: "simple options for target",
@@ -747,6 +749,24 @@ func TestBuildOptionsForTarget(t *testing.T) {
Arch: "amd64",
},
},
{
name: "overriding dist path",
build: config.Build{
ID: "testid",
Binary: "distpath/{{.Os}}/{{.Arch}}/testbinary_{{.Os}}_{{.Arch}}",
Targets: []string{
"linux_amd64",
},
NoUniqueDistDir: true,
},
expectedOpts: &api.Options{
Name: "testbinary_linux_amd64",
Path: filepath.Join(tmpDir, "distpath", "linux", "amd64", "testbinary_linux_amd64"),
Target: "linux_amd64",
Os: "linux",
Arch: "amd64",
},
},
}
for _, tc := range testCases {
@@ -755,9 +775,14 @@ func TestBuildOptionsForTarget(t *testing.T) {
Dist: tmpDir,
Builds: []config.Build{tc.build},
})
opts, err := buildOptionsForTarget(ctx, tc.build, tc.build.Targets[0])
require.NoError(t, err)
require.Equal(t, tc.expectedOpts, opts)
require.NoError(t, Pipe{}.Default(ctx))
opts, err := buildOptionsForTarget(ctx, ctx.Config.Builds[0], ctx.Config.Builds[0].Targets[0])
if tc.expectedErr == "" {
require.NoError(t, err)
require.Equal(t, tc.expectedOpts, opts)
} else {
require.EqualError(t, err, tc.expectedErr)
}
})
}
}
+22 -21
View File
@@ -183,27 +183,28 @@ func (a *FlagArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Build contains the build configuration section.
type Build struct {
ID string `yaml:",omitempty"`
Goos []string `yaml:",omitempty"`
Goarch []string `yaml:",omitempty"`
Goarm []string `yaml:",omitempty"`
Gomips []string `yaml:",omitempty"`
Targets []string `yaml:",omitempty"`
Ignore []IgnoredBuild `yaml:",omitempty"`
Dir string `yaml:",omitempty"`
Main string `yaml:",omitempty"`
Ldflags StringArray `yaml:",omitempty"`
Tags FlagArray `yaml:",omitempty"`
Flags FlagArray `yaml:",omitempty"`
Binary string `yaml:",omitempty"`
Hooks HookConfig `yaml:",omitempty"`
Env []string `yaml:",omitempty"`
Lang string `yaml:",omitempty"`
Asmflags StringArray `yaml:",omitempty"`
Gcflags StringArray `yaml:",omitempty"`
ModTimestamp string `yaml:"mod_timestamp,omitempty"`
Skip bool `yaml:",omitempty"`
GoBinary string `yaml:",omitempty"`
ID string `yaml:",omitempty"`
Goos []string `yaml:",omitempty"`
Goarch []string `yaml:",omitempty"`
Goarm []string `yaml:",omitempty"`
Gomips []string `yaml:",omitempty"`
Targets []string `yaml:",omitempty"`
Ignore []IgnoredBuild `yaml:",omitempty"`
Dir string `yaml:",omitempty"`
Main string `yaml:",omitempty"`
Ldflags StringArray `yaml:",omitempty"`
Tags FlagArray `yaml:",omitempty"`
Flags FlagArray `yaml:",omitempty"`
Binary string `yaml:",omitempty"`
Hooks HookConfig `yaml:",omitempty"`
Env []string `yaml:",omitempty"`
Lang string `yaml:",omitempty"`
Asmflags StringArray `yaml:",omitempty"`
Gcflags StringArray `yaml:",omitempty"`
ModTimestamp string `yaml:"mod_timestamp,omitempty"`
Skip bool `yaml:",omitempty"`
GoBinary string `yaml:",omitempty"`
NoUniqueDistDir bool `yaml:"no_unique_dist_dir,omitempty"`
}
type HookConfig struct {
+9
View File
@@ -134,6 +134,15 @@ builds:
# Useful for library projects.
# Default is false
skip: false
# By default, GoRelaser will create your binaries inside `dist/${BuildID}_${BuildTarget}`, which is an unique directory per build target in the matrix.
# You are able to set subdirs within that folder using the `binary` property.
#
# However, if for some reason you don't want that unique directory to be created, you can set this property.
# If you do, you are responsible of keeping different builds from overriding each other.
#
# Defaults to `false`.
no_unique_dist_dir: true
```
!!! tip