Skip to content

Commit

Permalink
TER-305 Add option to use existing binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
dshelley66 committed Oct 11, 2023
1 parent 6b00bb9 commit 3a29186
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 39 deletions.
14 changes: 8 additions & 6 deletions internal/builders/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
a.Extra["testEnvs"] = testEnvs
}

cmd, err := buildGoBuildLine(ctx, build, details, options, a, env)
if err != nil {
return err
}
if !options.PreBuilt {
cmd, err := buildGoBuildLine(ctx, build, details, options, a, env)
if err != nil {
return err
}

if err := run(ctx, cmd, env, build.Dir); err != nil {
return fmt.Errorf("failed to build for %s: %w", options.Target, err)
if err := run(ctx, cmd, env, build.Dir); err != nil {
return fmt.Errorf("failed to build for %s: %w", options.Target, err)
}
}

modTimestamp, err := tmpl.New(ctx).WithEnvS(env).WithArtifact(a).Apply(build.ModTimestamp)
Expand Down
8 changes: 7 additions & 1 deletion internal/pipe/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ func buildOptionsForTarget(ctx *context.Context, build config.Build, target stri
if build.NoUniqueDistDir {
dir = ""
}
relpath := filepath.Join(ctx.Config.Dist, dir, name)

basePath := ctx.Config.Dist
if build.PreBuiltBinaryDir != "" {
basePath = build.PreBuiltBinaryDir
buildOpts.PreBuilt = true
}
relpath := filepath.Join(basePath, dir, name)
path, err := filepath.Abs(relpath)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/release/scm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestSetupGitea(t *testing.T) {
t.Run("no repo", func(t *testing.T) {
ctx := testctx.New()
require.NoError(t, setupGitea(ctx))
require.Equal(t, "goreleaser", ctx.Config.Release.Gitea.Owner)
require.Equal(t, "cldcvr", ctx.Config.Release.Gitea.Owner)
require.Equal(t, "goreleaser", ctx.Config.Release.Gitea.Name)
})

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestSetupGitHub(t *testing.T) {
t.Run("no repo", func(t *testing.T) {
ctx := testctx.New()
require.NoError(t, setupGitHub(ctx))
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
require.Equal(t, "cldcvr", ctx.Config.Release.GitHub.Owner)
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
})

Expand Down
19 changes: 10 additions & 9 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ func For(name string) Builder {

// Options to be passed down to a builder.
type Options struct {
Name string
Path string
Ext string
Target string
Goos string
Goarch string
Goamd64 string
Goarm string
Gomips string
Name string
Path string
Ext string
Target string
Goos string
Goarch string
Goamd64 string
Goarm string
Gomips string
PreBuilt bool
}

// Builder defines a builder.
Expand Down
43 changes: 22 additions & 21 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,27 +493,28 @@ func (a FlagArray) JSONSchema() *jsonschema.Schema {

// Build contains the build configuration section.
type Build struct {
ID string `yaml:"id,omitempty" json:"id,omitempty"`
Goos []string `yaml:"goos,omitempty" json:"goos,omitempty"`
Goarch []string `yaml:"goarch,omitempty" json:"goarch,omitempty"`
Goarm []string `yaml:"goarm,omitempty" json:"goarm,omitempty"`
Gomips []string `yaml:"gomips,omitempty" json:"gomips,omitempty"`
Goamd64 []string `yaml:"goamd64,omitempty" json:"goamd64,omitempty"`
Targets []string `yaml:"targets,omitempty" json:"targets,omitempty"`
Ignore []IgnoredBuild `yaml:"ignore,omitempty" json:"ignore,omitempty"`
Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
Main string `yaml:"main,omitempty" json:"main,omitempty"`
Binary string `yaml:"binary,omitempty" json:"binary,omitempty"`
Hooks BuildHookConfig `yaml:"hooks,omitempty" json:"hooks,omitempty"`
Builder string `yaml:"builder,omitempty" json:"builder,omitempty"`
ModTimestamp string `yaml:"mod_timestamp,omitempty" json:"mod_timestamp,omitempty"`
Skip bool `yaml:"skip,omitempty" json:"skip,omitempty"`
GoBinary string `yaml:"gobinary,omitempty" json:"gobinary,omitempty"`
Command string `yaml:"command,omitempty" json:"command,omitempty"`
NoUniqueDistDir bool `yaml:"no_unique_dist_dir,omitempty" json:"no_unique_dist_dir,omitempty"`
NoMainCheck bool `yaml:"no_main_check,omitempty" json:"no_main_check,omitempty"`
UnproxiedMain string `yaml:"-" json:"-"` // used by gomod.proxy
UnproxiedDir string `yaml:"-" json:"-"` // used by gomod.proxy
ID string `yaml:"id,omitempty" json:"id,omitempty"`
Goos []string `yaml:"goos,omitempty" json:"goos,omitempty"`
Goarch []string `yaml:"goarch,omitempty" json:"goarch,omitempty"`
Goarm []string `yaml:"goarm,omitempty" json:"goarm,omitempty"`
Gomips []string `yaml:"gomips,omitempty" json:"gomips,omitempty"`
Goamd64 []string `yaml:"goamd64,omitempty" json:"goamd64,omitempty"`
Targets []string `yaml:"targets,omitempty" json:"targets,omitempty"`
Ignore []IgnoredBuild `yaml:"ignore,omitempty" json:"ignore,omitempty"`
Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
Main string `yaml:"main,omitempty" json:"main,omitempty"`
Binary string `yaml:"binary,omitempty" json:"binary,omitempty"`
Hooks BuildHookConfig `yaml:"hooks,omitempty" json:"hooks,omitempty"`
Builder string `yaml:"builder,omitempty" json:"builder,omitempty"`
ModTimestamp string `yaml:"mod_timestamp,omitempty" json:"mod_timestamp,omitempty"`
Skip bool `yaml:"skip,omitempty" json:"skip,omitempty"`
GoBinary string `yaml:"gobinary,omitempty" json:"gobinary,omitempty"`
Command string `yaml:"command,omitempty" json:"command,omitempty"`
NoUniqueDistDir bool `yaml:"no_unique_dist_dir,omitempty" json:"no_unique_dist_dir,omitempty"`
NoMainCheck bool `yaml:"no_main_check,omitempty" json:"no_main_check,omitempty"`
PreBuiltBinaryDir string `yaml:"prebuilt_binary_dir,omitempty" json:"prebuilt_binary_dir,omitempty"`
UnproxiedMain string `yaml:"-" json:"-"` // used by gomod.proxy
UnproxiedDir string `yaml:"-" json:"-"` // used by gomod.proxy

BuildDetails `yaml:",inline" json:",inline"` // nolint: tagliatelle
BuildDetailsOverrides []BuildDetailsOverride `yaml:"overrides,omitempty" json:"overrides,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions www/docs/static/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3a29186

Please sign in to comment.