2
2
set -e # exit when any command fails
3
3
set -x # show all commands being run
4
4
5
- GC=go
5
+ # Default to Go 1.18 if GO_VERSION is not set.
6
+ #
7
+ # Use the "=" operator (instead of the more common ":-" operator) so that it
8
+ # allows setting GO_VERSION="" to use the Go installation in the PATH, and it
9
+ # sets the GO_VERSION variable if the default is used.
10
+ GC=go${GO_VERSION=" 1.18" }
6
11
COMPILE_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
- }
15
12
16
13
# compile_check will attempt to build the internal/test/compilecheck project
17
14
# 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.
20
15
function compile_check {
21
16
# Change the directory to the compilecheck test directory.
22
- cd ${COMPILE_CHECK_DIR}
17
+ pushd ${COMPILE_CHECK_DIR}
23
18
24
- MACHINE_VERSION=` ${GC} version | { read _ _ v _; echo ${v# go} ; }`
19
+ # If a custom Go version is set using the GO_VERSION env var (e.g. "1.18"),
20
+ # add the GOPATH bin directory to PATH and then install that Go version.
21
+ if [ ! -z " $GO_VERSION " ]; then
22
+ PATH=$( go env GOPATH) /bin:$PATH
23
+ export PATH
25
24
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
25
+ go install golang.org/dl/go$GO_VERSION @latest
26
+ ${GC} download
29
27
fi
30
28
29
+ ${GC} version
30
+ ${GC} mod tidy
31
+
31
32
# Check simple build.
32
33
${GC} build ./...
33
34
34
35
# Check build with dynamic linking.
35
36
${GC} build -buildmode=plugin
36
37
37
38
# Check build with tags.
38
- go build $BUILD_TAGS ./...
39
+ ${GC} build $BUILD_TAGS ./...
39
40
40
41
# Check build with various architectures.
41
42
GOOS=linux GOARCH=386 ${GC} build ./...
@@ -50,7 +51,7 @@ function compile_check {
50
51
rm compilecheck.so
51
52
52
53
# Change the directory back to the working directory.
53
- cd -
54
+ popd
54
55
}
55
56
56
57
compile_check
0 commit comments