Skip to content

Commit 278d08e

Browse files
Prevent go.mod file pollution with development dependencies (#85)
Previously when installing development dependencies through "mage", the `go.mod` file was updated to include the installed packages since this the default behavior of the `go get` command when running in "module" mode. To prevent the pollution of the project's Go module definition the "module" mode has been disabled when installing the dev/build packages. This is a necessary workaround until the Go toolchain is able to install packages globally without updating the module file when the `go get` command is run from within the project root directory. See golang/go#30515 for more details and proposed solutions that might be added to Go's build tools in future versions. Epic GH-33 Resolves GH-82
1 parent 3bb0b89 commit 278d08e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

magefile.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var (
110110
// This is the same tool used by the https://golangci.com service that is also integrated in snowsaw's CI/CD pipeline.
111111
// See https://github.com/golangci/golangci-lint for more details.
112112
lintTool = &buildDependency{
113-
PackageName: "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.17.1",
113+
PackageName: "github.com/golangci/golangci-lint/cmd/golangci-lint",
114114
BinaryName: "golangci-lint",
115115
}
116116

@@ -474,8 +474,16 @@ func validateBuildDependencies() {
474474
continue
475475
}
476476

477+
env := map[string]string{
478+
// Disable module mode to install development dependencies to prevent to pollute the project module file.
479+
// This is a necessary workaround until the Go toolchain is able to install packages globally without
480+
// updating the module file when the "go get" command is run from within the project root directory.
481+
// See https://github.com/golang/go/issues/30515 for more details or more details and proposed solutions
482+
// that might be added to Go's build tools in future versions.
483+
"GO111MODULE": "off"}
484+
477485
prt.Infof("Installing required build dependency: %s", color.CyanString(bd.PackageName))
478-
if err = sh.Run(goExec, "get", "-u", bd.PackageName); err != nil {
486+
if err = sh.RunWith(env, goExec, "get", "-u", bd.PackageName); err != nil {
479487
prt.Errorf("Failed to install required build dependency %s: %v", color.CyanString(bd.PackageName), err)
480488
prt.Warnf("Please install manually: %s", color.CyanString("go get -u %s", bd.PackageName))
481489
os.Exit(1)

0 commit comments

Comments
 (0)