1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-29 21:47:01 +02:00

fix: support dir in gomod ()

closes https://github.com/orgs/goreleaser/discussions/4728
This commit is contained in:
Carlos Alexandro Becker 2024-03-29 10:27:33 -03:00 committed by GitHub
parent 46b53353fc
commit 8cd325eb5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 34 additions and 1 deletions
internal/pipe/gomod
pkg/config
www/docs/customization

@ -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