forked from TrueCloudLab/restic
Merge pull request #1992 from restic/add-go-mod-tidy
Run go mod tidy during CI
This commit is contained in:
commit
bd9022962e
1 changed files with 37 additions and 0 deletions
|
@ -366,6 +366,11 @@ func (env *TravisEnvironment) RunTests() error {
|
|||
if err := runGoModVendor(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg("run go mod tidy\n")
|
||||
if err := runGoModTidy(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
msg("Skipping gofmt and module vendor check for %v\n", v)
|
||||
}
|
||||
|
@ -559,6 +564,38 @@ func runGoModVendor() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// run "go mod tidy" so that go.sum and go.mod are updated to reflect all
|
||||
// dependencies for all OS/Arch combinations, see
|
||||
// https://github.com/golang/go/wiki/Modules#why-does-go-mod-tidy-put-so-many-indirect-dependencies-in-my-gomod
|
||||
func runGoModTidy() error {
|
||||
cmd := exec.Command("go", "mod", "tidy")
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Env = updateEnv(os.Environ(), map[string]string{
|
||||
"GO111MODULE": "on",
|
||||
})
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error running 'go mod vendor': %v", err)
|
||||
}
|
||||
|
||||
// check that "git diff" does not return any output
|
||||
cmd = exec.Command("git", "diff", "go.sum", "go.mod")
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
buf, err := cmd.Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error running 'git diff vendor': %v\noutput: %s", err, buf)
|
||||
}
|
||||
|
||||
if len(buf) > 0 {
|
||||
return fmt.Errorf("vendor/ directory was modified:\n%s", buf)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runGlyphcheck() error {
|
||||
cmd := exec.Command("glyphcheck", "./cmd/...", "./internal/...")
|
||||
cmd.Stderr = os.Stderr
|
||||
|
|
Loading…
Reference in a new issue