@@ -50,24 +50,47 @@ function e2e() {
5050 e2e_ci
5151}
5252
53+ # e2e_ci - Run end-to-end integration tests in the CI system.
54+ # This assumes that the secrets in the env vars are already set.
5355function e2e_ci() {
5456 go test -v -race -cover ./e2e_mysql_test.go ./e2e_postgres_test.go ./e2e_sqlserver_test.go | tee test_results.txt
5557}
5658
59+ # Download a tool using `go install`
60+ function get_golang_tool() {
61+ name=" $1 "
62+ github_repo=" $2 "
63+ package=$3
64+
65+ # Download goimports tool
66+ version=$( curl -s " https://api.github.com/repos/$github_repo /tags" | jq -r ' .[].name' | head -n 1)
67+ mkdir -p " $SCRIPT_DIR /.tools"
68+ cmd=" $SCRIPT_DIR /.tools/$name "
69+ versioned_cmd=" $SCRIPT_DIR /.tools/$name -$version "
70+ if [[ ! -f " $versioned_cmd " ]] ; then
71+ GOBIN=" $SCRIPT_DIR /.tools" go install " $package @$version "
72+ mv " $cmd " " $versioned_cmd "
73+ if [[ -f " $cmd " ]] ; then
74+ unlink " $cmd "
75+ fi
76+ ln -s " $versioned_cmd " " $cmd "
77+ fi
78+ }
79+
5780# # fix - Fixes code format.
5881function fix() {
82+ # run code formatting
83+ get_golang_tool ' goimports' ' golang/tools' ' golang.org/x/tools/cmd/goimports'
84+ " .tools/goimports" -w .
5985 go mod tidy
6086 go fmt ./...
6187}
6288
6389# # lint - runs the linters
6490function lint() {
65- # run golangci-lint
66- mkdir -p " $SCRIPT_DIR /.tools"
67- if [[ ! -f " $SCRIPT_DIR /.tools/golangci-lint" ]] ; then
68- GOBIN=
" $SCRIPT_DIR /.tools" go install github.com/golangci/golangci-lint/cmd/
[email protected] 69- fi
70- " $SCRIPT_DIR /.tools/golangci-lint" run --timeout 3m
91+ # run lint checks
92+ get_golang_tool ' golangci-lint' ' golangci/golangci-lint' ' github.com/golangci/golangci-lint/v2/cmd/golangci-lint'
93+ " .tools/golangci-lint" run --timeout 3m
7194
7295 # Check the commit includes a go.mod that is fully
7396 # up to date.
@@ -77,10 +100,15 @@ function lint() {
77100 fi
78101}
79102
103+ # lint_ci runs lint in the CI build job
104+ function lint_ci() {
105+ fix # run code format cleanup
106+ git diff --exit-code # fail if anything changed
107+ lint # run lint
108+ }
80109
81110# write_e2e_env - Loads secrets from the gcloud project and writes
82111# them to target/e2e.env to run e2e tests.
83- #
84112function write_e2e_env(){
85113 # All secrets used by the e2e tests in the form <env_name>=<secret_name>
86114 secret_vars=(
0 commit comments