mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-29 01:44:39 +02:00
fix: support dir in gomod (#4729)
closes https://github.com/orgs/goreleaser/discussions/4728
This commit is contained in:
parent
46b53353fc
commit
8cd325eb5a
@ -36,6 +36,9 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, ctx.Config.GoMod.GoBinary, flags...)
|
||||
cmd.Env = append(ctx.Env.Strings(), ctx.Config.GoMod.Env...)
|
||||
if dir := ctx.Config.GoMod.Dir; dir != "" {
|
||||
cmd.Dir = dir
|
||||
}
|
||||
out, err := cmd.CombinedOutput()
|
||||
result := strings.TrimSpace(string(out))
|
||||
if strings.HasPrefix(result, goPreModulesError) {
|
||||
|
@ -75,6 +75,29 @@ func TestCustomEnv(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
}
|
||||
|
||||
func TestRunCustomDir(t *testing.T) {
|
||||
dir := testlib.Mktmp(t)
|
||||
require.NoError(t, os.MkdirAll(filepath.Join(dir, "src"), 0o755))
|
||||
require.NoError(t, os.WriteFile(
|
||||
filepath.Join(dir, "src/main.go"),
|
||||
[]byte("package main\nfunc main() {println(0)}"),
|
||||
0o666,
|
||||
))
|
||||
require.NoError(t, os.WriteFile(
|
||||
filepath.Join(dir, "src/go.mod"),
|
||||
[]byte("module foo"),
|
||||
0o666,
|
||||
))
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
GoMod: config.GoMod{
|
||||
Dir: filepath.Join(dir, "src"),
|
||||
},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "foo", ctx.ModulePath)
|
||||
}
|
||||
|
||||
func TestRunOutsideGoModule(t *testing.T) {
|
||||
dir := testlib.Mktmp(t)
|
||||
require.NoError(t, os.WriteFile(
|
||||
|
@ -1247,6 +1247,7 @@ type GoMod struct {
|
||||
Env []string `yaml:"env,omitempty" json:"env,omitempty"`
|
||||
GoBinary string `yaml:"gobinary,omitempty" json:"gobinary,omitempty"`
|
||||
Mod string `yaml:"mod,omitempty" json:"mod,omitempty"`
|
||||
Dir string `yaml:"dir,omitempty" json:"dir,omitempty"`
|
||||
}
|
||||
|
||||
type Announce struct {
|
||||
|
@ -37,6 +37,12 @@ gomod:
|
||||
#
|
||||
# Default: `go`.
|
||||
gobinary: go1.17
|
||||
|
||||
# Directory in which the go.mod file is.
|
||||
#
|
||||
# Default: ''
|
||||
# Since: v1.25
|
||||
dir: ./src
|
||||
```
|
||||
|
||||
!!! tip
|
||||
@ -49,7 +55,7 @@ gomod:
|
||||
VCS Info will not be embedded in the binary, as in practice it is not being
|
||||
built from the source, but from the Go Mod Proxy.
|
||||
|
||||
!!! warning
|
||||
!!! warning
|
||||
|
||||
If you have a `go.work` file, make sure to run `go work sync`, so the main
|
||||
module (`.`) is the first line inside the `use` block.
|
||||
|
Loading…
Reference in New Issue
Block a user