From 46be7638cecf3471c93b4b3e98306b365cd97270 Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:58:56 -0700 Subject: [PATCH] Use a local Go 1.18 installation to check for minimum version support. --- .evergreen/config.yml | 7 +------ Taskfile.yml | 18 ++++++++++++++++-- etc/compile_check.sh | 23 +++++------------------ 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 55217b80cc..ca0e69db1b 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -1362,19 +1362,14 @@ tasks: vars: MONGO_GO_DRIVER_COMPRESSOR: "snappy" - # Build with the oldest supported version of Go. - - name: go1.18-build + - name: build-compile-check tags: ["compile-check"] commands: - command: subprocess.exec params: binary: bash - env: - GOROOT: /opt/golang/go1.18 - add_to_path: [/opt/golang/go1.18/bin] args: [*task-runner, build-compile-check] - # Build with the same Go version that we're using for tests. - name: build tags: ["compile-check"] commands: diff --git a/Taskfile.yml b/Taskfile.yml index 206b31db9f..1fb90c28e2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -18,14 +18,22 @@ tasks: check-license: bash etc/check_license.sh build: - deps: [cross-compile, build-tests, build-compile-check, install-libmongocrypt] + deps: [install-libmongocrypt] cmds: - go build ./... - go build ${BUILD_TAGS} ./... + - task: cross-compile + - task: build-tests build-tests: go test -short ${BUILD_TAGS} -run ^$$ ./... - build-compile-check: bash etc/compile_check.sh + # Build the compilecheck submodule, both with the system version of Go and + # with the minimum supported version of Go (Go 1.18). + build-compile-check: + deps: [install-go118] + cmds: + - bash etc/compile_check.sh + - PATH=$(go1.18 env GOROOT)/bin:$PATH GOROOT=$(go1.18 env GOROOT) bash etc/compile_check.sh build-aws-ecs-test: go build ${BUILD_TAGS} ./internal/cmd/testaws/main.go @@ -210,3 +218,9 @@ tasks: internal: true cmds: - go install github.com/walle/lll/...@latest + + install-go118: + internal: true + cmds: + - go install golang.org/dl/go1.18@latest + - go1.18 download diff --git a/etc/compile_check.sh b/etc/compile_check.sh index 69e4395a12..72fd0aea00 100755 --- a/etc/compile_check.sh +++ b/etc/compile_check.sh @@ -5,28 +5,15 @@ set -x # show all commands being run GC=go COMPILE_CHECK_DIR="internal/cmd/compilecheck" # shellcheck disable=SC2034 -DEV_MIN_VERSION=1.19 - -# version will flatten a version string of upto 4 components for inequality -# comparison. -function version { - echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; -} # compile_check will attempt to build the internal/test/compilecheck project # using the provided Go version. This is to simulate an end-to-end use case. -# This check will only run on environments where the Go version is greater than -# or equal to the given version. function compile_check { # Change the directory to the compilecheck test directory. - cd ${COMPILE_CHECK_DIR} - - MACHINE_VERSION=`${GC} version | { read _ _ v _; echo ${v#go}; }` + pushd ${COMPILE_CHECK_DIR} - # If the version is not 1.13, then run "go mod tidy" - if [ "$(version $MACHINE_VERSION)" -ge "$(version 1.15)" ]; then - go mod tidy - fi + ${GC} version + ${GC} mod tidy # Check simple build. ${GC} build ./... @@ -35,7 +22,7 @@ function compile_check { ${GC} build -buildmode=plugin # Check build with tags. - go build $BUILD_TAGS ./... + ${GC} build $BUILD_TAGS ./... # Check build with various architectures. GOOS=linux GOARCH=386 ${GC} build ./... @@ -50,7 +37,7 @@ function compile_check { rm compilecheck.so # Change the directory back to the working directory. - cd - + popd } compile_check