mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
Go: Add shared TidyModule function
This commit is contained in:
@@ -226,8 +226,7 @@ func tryUpdateGoModAndGoSum(buildInfo project.BuildInfo) {
|
||||
beforeGoSumFileInfo, beforeGoSumErr := os.Stat(goSumPath)
|
||||
|
||||
// run `go mod tidy -e`
|
||||
cmd := exec.Command("go", "mod", "tidy", "-e")
|
||||
cmd.Dir = buildInfo.BaseDir
|
||||
cmd := toolchain.TidyModule(buildInfo.BaseDir)
|
||||
res := util.RunCmd(cmd)
|
||||
|
||||
if !res {
|
||||
@@ -443,9 +442,7 @@ func initGoModForLegacyProject(buildInfo project.BuildInfo) {
|
||||
return
|
||||
}
|
||||
|
||||
modTidy := exec.Command("go", "mod", "tidy")
|
||||
modTidy.Dir = buildInfo.BaseDir
|
||||
|
||||
modTidy := toolchain.TidyModule(buildInfo.BaseDir)
|
||||
out, err := modTidy.CombinedOutput()
|
||||
log.Println(string(out))
|
||||
|
||||
|
||||
@@ -71,3 +71,10 @@ func parseGoVersion(data string) string {
|
||||
func SupportsWorkspaces() bool {
|
||||
return semver.Compare(GetEnvGoSemVer(), "v1.18.0") >= 0
|
||||
}
|
||||
|
||||
// Run `go mod tidy -e` in the directory given by `path`.
|
||||
func TidyModule(path string) *exec.Cmd {
|
||||
cmd := exec.Command("go", "mod", "tidy", "-e")
|
||||
cmd.Dir = path
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user