Repository: kubernetes/minikube
Pull request #11027 (2021-04-08 19:04:16)

Detect if go.sum changed after running go mod tidy
Currently, we run `go mod tidy` in `make test` and check if the go.mod changed and fail if it did. However, we don't check if the go.sum changed.

This becomes a problem when we go to release, `go mod tidy` is ran which will correct the go.sum, but makes the commit dirty and we have to make a PR to update the go.sum and run the release again.

This will detect if the go.sum should be updated during the PR unit test check in GitHub and will notify us, preventing the above issue.

Also updated workflow so PR tests are run if the go.mod file is updated. This will prevent some issues where packages are updated, new docs need to be generated, but the linting job isn't run, so we're left unaware until later.


Patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6bb2a09b6..051fcac8a 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -4,6 +4,7 @@ on:
     branches:
       - master
     paths:
+      - "go.mod"
       - "**.go"
       - "Makefile"
       - "!deploy/kicbase/**"
diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml
index dae32426b..2e526ca83 100644
--- a/.github/workflows/master.yml
+++ b/.github/workflows/master.yml
@@ -4,6 +4,7 @@ on:
     branches:
       - master
     paths:
+      - "go.mod"
       - "**.go"
       - "**.yml"
       - "**.yaml"
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index cb03e3c23..1b1bdb1e4 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -2,6 +2,7 @@ name: PR
 on:
   pull_request:
     paths:
+      - "go.mod"
       - "**.go"
       - "**.yml"
       - "**.yaml"
diff --git a/.github/workflows/pr_verified.yaml b/.github/workflows/pr_verified.yaml
index f156c3e10..8503dd2bf 100644
--- a/.github/workflows/pr_verified.yaml
+++ b/.github/workflows/pr_verified.yaml
@@ -2,6 +2,7 @@ name: PR_Verified
 on:
   pull_request:
     paths:
+      - "go.mod"
       - "**.go"
       - "**.yml"
       - "**.yaml"
diff --git a/pkg/minikube/perf/binary.go b/pkg/minikube/perf/binary.go
index 22fa26583..3b85c927c 100644
--- a/pkg/minikube/perf/binary.go
+++ b/pkg/minikube/perf/binary.go
@@ -59,7 +59,7 @@ func NewBinary(b string) (*Binary, error) {
 // Name returns the name of the binary
 func (b *Binary) Name() string {
 	if b.pr != 0 {
-		return fmt.Sprintf("minikube (PR %d)", b.pr)
+		return fmt.Sprintf("Minikube (PR %d)", b.pr)
 	}
 	return filepath.Base(b.path)
 }
diff --git a/pkg/minikube/perf/result.go b/pkg/minikube/perf/result.go
index 1cb44e87e..fdfb41cae 100644
--- a/pkg/minikube/perf/result.go
+++ b/pkg/minikube/perf/result.go
@@ -16,10 +16,6 @@ limitations under the License.
 
 package perf
 
-type resultWrapper struct {
-	results map[string][]*result
-}
-
 type result struct {
 	logs      []string
 	timedLogs map[string]float64
diff --git a/pkg/minikube/perf/result_manager.go b/pkg/minikube/perf/result_manager.go
index e28da835e..06f3a71ba 100644
--- a/pkg/minikube/perf/result_manager.go
+++ b/pkg/minikube/perf/result_manager.go
@@ -25,33 +25,27 @@ import (
 )
 
 type resultManager struct {
-	results map[*Binary]resultWrapper
+	results map[*Binary][]*result
 }
 
 func newResultManager() *resultManager {
 	return &resultManager{
-		results: map[*Binary]resultWrapper{},
+		results: map[*Binary][]*result{},
 	}
 }
 
-func (rm *resultManager) addResult(binary *Binary, test string, r result) {
-	a, ok := rm.results[binary]
+func (rm *resultManager) addResult(binary *Binary, r *result) {
+	_, ok := rm.results[binary]
 	if !ok {
-		r := map[string][]*result{test: []*result{&r}}
-		rm.results[binary] = resultWrapper{r}
+		rm.results[binary] = []*result{r}
 		return
 	}
-	b, ok := a.results[test]
-	if !ok {
-		a.results[test] = []*result{&r}
-		return
-	}
-	a.results[test] = append(b, &r)
+	rm.results[binary] = append(rm.results[binary], r)
 }
 
-func (rm *resultManager) totalTimes(binary *Binary, t string) []float64 {
+func (rm *resultManager) totalTimes(binary *Binary) []float64 {
 	var totals []float64
-	results, ok := rm.results[binary].results[t]
+	results, ok := rm.results[binary]
 	if !ok {
 		return nil
 	}
@@ -65,18 +59,20 @@ func (rm *resultManager) totalTimes(binary *Binary, t string) []float64 {
 	return totals
 }
 
+func (rm *resultManager) averageTime(binary *Binary) float64 {
+	times := rm.totalTimes(binary)
+	return average(times)
+}
+
 func (rm *resultManager) summarizeResults(binaries []*Binary) {
 	// print total and average times
 	for _, b := range binaries {
-		for t := range rm.results[b].results {
-			fmt.Printf("Times for %s %s: ", b.Name(), t)
-			totalTimes := rm.totalTimes(b, t)
-			for _, tt := range totalTimes {
-				fmt.Printf("%.1fs ", tt)
-			}
-			fmt.Println()
-			fmt.Printf("Average time for %s %s: %.1fs\n\n", b.Name(), t, average(totalTimes))
+		fmt.Printf("Times for %s: ", b.Name())
+		for _, tt := range rm.totalTimes(b) {
+			fmt.Printf("%.1fs ", tt)
 		}
+		fmt.Println()
+		fmt.Printf("Average time for %s: %.1fs\n\n", b.Name(), rm.averageTime(b))
 	}
 
 	// print out summary per log
@@ -85,7 +81,7 @@ func (rm *resultManager) summarizeResults(binaries []*Binary) {
 
 func (rm *resultManager) summarizeTimesPerLog(binaries []*Binary) {
 	results := rm.results[binaries[0]]
-	logs := results.results["start"][0].logs
+	logs := results[0].logs
 
 	table := make([][]string, len(logs))
 	for i := range table {
@@ -98,7 +94,7 @@ func (rm *resultManager) summarizeTimesPerLog(binaries []*Binary) {
 
 	for i, b := range binaries {
 		results := rm.results[b]
-		averageTimeForLog := averageTimePerLog(results.results["start"])
+		averageTimeForLog := averageTimePerLog(results)
 		for log, time := range averageTimeForLog {
 			index := indexForLog(logs, log)
 			if index == -1 {
diff --git a/pkg/minikube/perf/start.go b/pkg/minikube/perf/start.go
index af7bdcb96..a694b98ee 100644
--- a/pkg/minikube/perf/start.go
+++ b/pkg/minikube/perf/start.go
@@ -65,13 +65,13 @@ func collectResults(ctx context.Context, binaries []*Binary, driver string) (*re
 			if err != nil {
 				return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name())
 			}
-			rm.addResult(binary, "start", *r)
+			rm.addResult(binary, r)
 			if runtime.GOOS != "darwin" {
 				r, err = timeEnableIngress(ctx, binary)
 				if err != nil {
 					return nil, errors.Wrapf(err, "timing run %d with %s", run, binary.Name())
 				}
-				rm.addResult(binary, "ingress", *r)
+				rm.addResult(binary, r)
 			}
 			deleteCmd := exec.CommandContext(ctx, binary.path, "delete")
 			if err := deleteCmd.Run(); err != nil {


Test patch:
diff --git a/pkg/minikube/perf/binary_test.go b/pkg/minikube/perf/binary_test.go
index d6e270b3c..8a6c651f6 100644
--- a/pkg/minikube/perf/binary_test.go
+++ b/pkg/minikube/perf/binary_test.go
@@ -31,7 +31,7 @@ func TestBinaryName(t *testing.T) {
 			binary:   Binary{path: "foo", pr: 0},
 		},
 		{
-			expected: "minikube (PR 1)",
+			expected: "Minikube (PR 1)",
 			binary:   Binary{path: "bar", pr: 1},
 		},
 	}
diff --git a/test.sh b/test.sh
index 82b3cb2bf..b2f00f758 100755
--- a/test.sh
+++ b/test.sh
@@ -25,7 +25,7 @@ then
     make -s lint-ci && echo ok || ((exitcode += 4))
     echo "= go mod ================================================================"
     go mod download 2>&1 | grep -v "go: finding" || true
-    go mod tidy -v && echo ok || ((exitcode += 2))
+    go mod tidy -v && git diff --quiet && echo ok || (((exitcode += 2)) && echo ERROR: Please run go mod tidy)
 fi