22set -e # exit when any command fails
33set -x # show all commands being run
44
5- GC=go
5+ GC=go$GO_VERSION
66COMPILE_CHECK_DIR=" internal/cmd/compilecheck"
7- # shellcheck disable=SC2034
8- DEV_MIN_VERSION=1.19
9-
10- # version will flatten a version string of upto 4 components for inequality
11- # comparison.
12- function version {
13- echo " $@ " | awk -F. ' { printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' ;
14- }
157
168# compile_check will attempt to build the internal/test/compilecheck project
179# using the provided Go version. This is to simulate an end-to-end use case.
18- # This check will only run on environments where the Go version is greater than
19- # or equal to the given version.
2010function compile_check {
2111 # Change the directory to the compilecheck test directory.
22- cd ${COMPILE_CHECK_DIR}
12+ pushd ${COMPILE_CHECK_DIR}
2313
24- MACHINE_VERSION=` ${GC} version | { read _ _ v _; echo ${v# go} ; }`
14+ # If a custom Go version is set using the GO_VERSION env var (e.g. "1.18"),
15+ # add the GOPATH bin directory to PATH and then install that Go version.
16+ if [ ! -z " $GO_VERSION " ]; then
17+ PATH=$( go env GOPATH) /bin:$PATH
18+ export PATH
2519
26- # If the version is not 1.13, then run "go mod tidy"
27- if [ " $( version $MACHINE_VERSION ) " -ge " $( version 1.15) " ]; then
28- go mod tidy
20+ go install golang.org/dl/go$GO_VERSION @latest
21+ ${GC} download
2922 fi
3023
24+ ${GC} version
25+ ${GC} mod tidy
26+
3127 # Check simple build.
3228 ${GC} build ./...
3329
3430 # Check build with dynamic linking.
3531 ${GC} build -buildmode=plugin
3632
3733 # Check build with tags.
38- go build $BUILD_TAGS ./...
34+ ${GC} build $BUILD_TAGS ./...
3935
4036 # Check build with various architectures.
4137 GOOS=linux GOARCH=386 ${GC} build ./...
@@ -50,7 +46,7 @@ function compile_check {
5046 rm compilecheck.so
5147
5248 # Change the directory back to the working directory.
53- cd -
49+ popd
5450}
5551
5652compile_check
0 commit comments