github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/gomod/gomod.go (about) 1 package gomod 2 3 import ( 4 "fmt" 5 "os/exec" 6 "strings" 7 8 "github.com/goreleaser/goreleaser/internal/pipe" 9 "github.com/goreleaser/goreleaser/pkg/context" 10 ) 11 12 const ( 13 go115NotAGoModuleError = "go list -m: not using modules" 14 go116NotAGoModuleError = "command-line-arguments" 15 ) 16 17 // Pipe for gomod. 18 type Pipe struct{} 19 20 func (Pipe) String() string { return "loading go mod information" } 21 22 // Default sets the pipe defaults. 23 func (Pipe) Default(ctx *context.Context) error { 24 if ctx.Config.GoMod.GoBinary == "" { 25 ctx.Config.GoMod.GoBinary = "go" 26 } 27 return nil 28 } 29 30 // Run the pipe. 31 func (Pipe) Run(ctx *context.Context) error { 32 out, err := exec.CommandContext(ctx, ctx.Config.GoMod.GoBinary, "list", "-m").CombinedOutput() 33 result := strings.TrimSpace(string(out)) 34 if result == go115NotAGoModuleError || result == go116NotAGoModuleError { 35 return pipe.Skip("not a go module") 36 } 37 if err != nil { 38 return fmt.Errorf("failed to get module path: %w: %s", err, string(out)) 39 } 40 41 ctx.ModulePath = result 42 return nil 43 }