From 23b2a0278ed54a9fc0a7f6dc9087575a33d7ce21 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Mon, 20 Aug 2018 10:07:55 +0800 Subject: [PATCH 1/2] module/apmgorm: require Go 1.9+ https://github.com/jinzhu/gorm/pull/2022 introduced use of sync.Map, which was introduced by Go 1.9. --- module/apmgorm/apmgorm_test.go | 2 ++ module/apmgorm/context.go | 2 ++ module/apmgorm/doc.go | 2 ++ module/apmgorm/open.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/module/apmgorm/apmgorm_test.go b/module/apmgorm/apmgorm_test.go index 99413f5d1..5add7c5ba 100644 --- a/module/apmgorm/apmgorm_test.go +++ b/module/apmgorm/apmgorm_test.go @@ -1,3 +1,5 @@ +// +build go1.9 + package apmgorm_test import ( diff --git a/module/apmgorm/context.go b/module/apmgorm/context.go index 8dee7af66..98a4c7f4c 100644 --- a/module/apmgorm/context.go +++ b/module/apmgorm/context.go @@ -1,3 +1,5 @@ +// +build go1.9 + package apmgorm import ( diff --git a/module/apmgorm/doc.go b/module/apmgorm/doc.go index 9203be4ee..1968b1866 100644 --- a/module/apmgorm/doc.go +++ b/module/apmgorm/doc.go @@ -1,2 +1,4 @@ +// +build go1.9 + // Package apmgorm provides wrappers for tracing GORM operations. package apmgorm diff --git a/module/apmgorm/open.go b/module/apmgorm/open.go index 90fe7c06e..79ece3ac1 100644 --- a/module/apmgorm/open.go +++ b/module/apmgorm/open.go @@ -1,3 +1,5 @@ +// +build go1.9 + package apmgorm import ( From bccfb96426d57e37e85c5dd6659a108e4cdefbe0 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Mon, 20 Aug 2018 11:39:04 +0800 Subject: [PATCH 2/2] Only run Dockerfile precheck on Go 1.9+ --- Makefile | 2 ++ scripts/mingoversion.go | 75 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 scripts/mingoversion.go diff --git a/Makefile b/Makefile index f3deaffcc..7a1116114 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,9 @@ check-goimports: .PHONY: check-dockerfile-testing check-dockerfile-testing: +ifeq ($(shell go run ./scripts/mingoversion.go -print 1.9),true) go run ./scripts/gendockerfile.go -d +endif .PHONY: check-lint check-lint: diff --git a/scripts/mingoversion.go b/scripts/mingoversion.go new file mode 100644 index 000000000..e20102920 --- /dev/null +++ b/scripts/mingoversion.go @@ -0,0 +1,75 @@ +// +build ignore + +package main + +import ( + "flag" + "fmt" + "os" + "regexp" + "runtime" + "strconv" +) + +var ( + printFlag = flag.Bool("print", false, "Print true or false, and always exit with 0 except in case of usage errors") +) + +func main() { + flag.Parse() + if flag.NArg() == 0 { + fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args) + os.Exit(2) + } + + re := regexp.MustCompile(`^(?:go)?(\d+).(\d+)(?:\.(\d+))?$`) + arg := flag.Arg(0) + argSubmatch := re.FindStringSubmatch(arg) + if argSubmatch == nil { + fmt.Fprintln(os.Stderr, "Invalid minimum-version: expected x.y or x.y.z") + os.Exit(2) + } + + runtimeVersion := runtime.Version() + goSubmatch := re.FindStringSubmatch(runtimeVersion) + if goSubmatch == nil { + fmt.Fprintln(os.Stderr, "Failed to parse runtime.Version(%s)", runtimeVersion) + os.Exit(3) + } + + result := true + minVersion := makeInts(argSubmatch[1:]) + goVersion := makeInts(goSubmatch[1:]) + for i := range minVersion { + n := goVersion[i] - minVersion[i] + if n < 0 { + if *printFlag { + result = false + } else { + fmt.Fprintf(os.Stderr, "%s < %s\n", runtimeVersion, arg) + os.Exit(1) + } + } + if n > 0 { + break + } + } + if *printFlag { + fmt.Println(result) + } +} + +func makeInts(s []string) []int { + ints := make([]int, len(s)) + for i, s := range s { + if s == "" { + s = "0" + } + n, err := strconv.Atoi(s) + if err != nil { + panic(err) + } + ints[i] = n + } + return ints +}