...
1#!/usr/bin/env bash
2set -e # exit when any command fails
3set -x # show all commands being run
4
5GC=go
6COMPILE_CHECK_DIR="internal/test/compilecheck"
7DEV_MIN_VERSION=1.19
8
9# version will flatten a version string of upto 4 components for inequality
10# comparison.
11function version {
12 echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
13}
14
15# compile_check will attempt to build the the internal/test/compilecheck project
16# using the provided Go version. This is to simulate an end-to-end use case.
17# This check will only run on environments where the Go version is greater than
18# or equal to the given version.
19function compile_check {
20 # Change the directory to the compilecheck test directory.
21 cd ${COMPILE_CHECK_DIR}
22
23 # Test vendoring
24 go mod vendor
25 ${GC} build -mod=vendor
26
27 rm -rf vendor
28
29 MACHINE_VERSION=`${GC} version | { read _ _ v _; echo ${v#go}; }`
30
31 # If the version is not 1.13, then run "go mod tidy"
32 if [ $(version $MACHINE_VERSION) -ge $(version 1.15) ]; then
33 go mod tidy
34 fi
35
36 # Check simple build.
37 ${GC} build ./...
38
39 # Check build with dynamic linking.
40 ${GC} build -buildmode=plugin
41
42 # Check build with tags.
43 ${GC} build $BUILD_TAGS ./...
44
45 # Check build with various architectures.
46 GOOS=linux GOARCH=386 ${GC} build ./...
47 GOOS=linux GOARCH=arm ${GC} build ./...
48 GOOS=linux GOARCH=arm64 ${GC} build ./...
49 GOOS=linux GOARCH=amd64 ${GC} build ./...
50 GOOS=linux GOARCH=ppc64le ${GC} build ./...
51 GOOS=linux GOARCH=s390x ${GC} build ./...
52
53 # Remove the binaries.
54 rm compilecheck
55 rm compilecheck.so
56
57 # Change the directory back to the working directory.
58 cd -
59}
60
61compile_check
View as plain text