From bcbf30a333b85ef8aaf375b3a63c6e63266d1064 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 20 Oct 2022 09:08:20 -0400 Subject: [PATCH] ci: make go compatibility check parallel Change-Id: I40162548305dcd181cfb702f72830d2c0a887cf4 --- Jenkinsfile.premerge | 10 +-- Jenkinsfile.public | 10 +-- scripts/go-version-compatibility/main.go | 94 ++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 scripts/go-version-compatibility/main.go diff --git a/Jenkinsfile.premerge b/Jenkinsfile.premerge index 3e71f76b8..c6b86e089 100644 --- a/Jenkinsfile.premerge +++ b/Jenkinsfile.premerge @@ -129,15 +129,7 @@ pipeline { steps { // verify most of the commands, we cannot check everything since some of them // have a C dependency and we don't have cross-compilation in storj/ci image - sh 'GOOS=linux GOARCH=386 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=linux GOARCH=amd64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=linux GOARCH=arm go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=linux GOARCH=arm64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=windows GOARCH=386 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=windows GOARCH=amd64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=windows GOARCH=arm64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=darwin GOARCH=amd64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=darwin GOARCH=arm64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' + sh 'go run ./scripts/go-version-compatibility -parallel 4' } } diff --git a/Jenkinsfile.public b/Jenkinsfile.public index 1ec8026b7..d63b1cfbb 100644 --- a/Jenkinsfile.public +++ b/Jenkinsfile.public @@ -151,15 +151,7 @@ pipeline { steps { // verify most of the commands, we cannot check everything since some of them // have a C dependency and we don't have cross-compilation in storj/ci image - sh 'GOOS=linux GOARCH=386 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=linux GOARCH=amd64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=linux GOARCH=arm go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=linux GOARCH=arm64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=windows GOARCH=386 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=windows GOARCH=amd64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=windows GOARCH=arm64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=darwin GOARCH=amd64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' - sh 'GOOS=darwin GOARCH=arm64 go vet ./cmd/uplink ./cmd/satellite ./cmd/storagenode-updater ./cmd/storj-sim' + sh 'go run ./scripts/go-version-compatibility -parallel 4' } } stage('Tests') { diff --git a/scripts/go-version-compatibility/main.go b/scripts/go-version-compatibility/main.go new file mode 100644 index 000000000..5b0d88e01 --- /dev/null +++ b/scripts/go-version-compatibility/main.go @@ -0,0 +1,94 @@ +// Copyright (C) 2022 Storj Labs, Inc. +// See LICENSE for copying information. + +package main + +import ( + "context" + "flag" + "fmt" + "os" + "os/exec" + "runtime" + "strings" + + "storj.io/common/sync2" +) + +func main() { + parallel := flag.Int("parallel", runtime.GOMAXPROCS(0), "number of compiles to run in parallel") + flag.Parse() + + ctx := context.Background() + + type testcase struct { + compiler string + os string + arch string + } + + test := func(compiler, os, arch string) testcase { + return testcase{ + compiler: compiler, + os: os, + arch: arch, + } + } + + tests := []testcase{ + test("go", "linux", "amd64"), + test("go", "linux", "386"), + test("go", "linux", "arm64"), + test("go", "linux", "arm"), + test("go", "windows", "amd64"), + test("go", "windows", "386"), + test("go", "windows", "arm64"), + test("go", "darwin", "amd64"), + test("go", "darwin", "arm64"), + } + + type result struct { + title string + out string + err error + } + results := make([]result, len(tests)) + + lim := sync2.NewLimiter(*parallel) + for i, test := range tests { + i, test := i, test + lim.Go(ctx, func() { + cmd := exec.Command(test.compiler, "vet", + "storj.io/storj/cmd/uplink", + "storj.io/storj/cmd/satellite", + "storj.io/storj/cmd/storagenode-updater", + "storj.io/storj/cmd/storj-sim", + ) + cmd.Env = append(os.Environ(), + "GOOS="+test.os, + "GOARCH="+test.arch, + ) + + data, err := cmd.CombinedOutput() + results[i] = result{ + title: test.compiler + "/" + test.os + "/" + test.arch, + out: strings.TrimSpace(string(data)), + err: err, + } + }) + } + lim.Wait() + + exit := 0 + for _, r := range results { + if r.err == nil { + fmt.Println("#", r.title, "SUCCESS") + } else { + fmt.Println("#", r.title, "FAILED", r.err) + fmt.Println(r.out) + fmt.Println() + exit = 1 + } + } + os.Exit(exit) +}