1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package main
// recreates the go.mod and go.sum files
import (
"fmt"
"os"
"github.com/go-cmd/cmd"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// remove every go.mod and go.sum
// testing to see where this stuff is coming from
func eraseGoMod(repo *gitpb.Repo) {
// unset the go development ENV var to generate release files
if _, err := repo.RunQuiet([]string{"rm", "-f", "go.mod", "go.sum"}); err != nil {
log.Warn(repo.GetGoPath(), "rm go.mod go.sum failed", err)
}
}
// sets the required golang version in go.mod
func setGoVersion(repo *gitpb.Repo, version string) error {
if _, err := repo.RunQuiet([]string{"go", "mod", "edit", "-go=" + version}); err != nil {
log.Warn(repo.GetGoPath(), "go mod edit failed", err)
return err
}
return nil
}
func goTidy(fullpath string) (cmd.Status, error) {
if result, err := runVerbose(fullpath, []string{"go", "mod", "tidy"}); err == nil {
return result, nil
} else {
return result, err
}
}
// wrapper around 'go mod init' and 'go mod tidy'
func redoGoMod(repo *gitpb.Repo) error {
// unset the go development ENV var to generate release files
os.Unsetenv("GO111MODULE")
if _, err := repo.RunQuiet([]string{"rm", "-f", "go.mod", "go.sum"}); err != nil {
log.Warn("rm go.mod go.sum failed", err)
return err
}
if _, err := repo.RunQuiet([]string{"go", "mod", "init", repo.GetGoPath()}); err != nil {
log.Warn("go mod init failed", err)
return err
}
// parse the go.mod and go.sum files
if repo.ParseGoSum() {
return nil
}
return fmt.Errorf("check.ParseGoSum() failed")
}
|