11# Golang CircleCI 2.0 configuration file
22#
33# Check https://circleci.com/docs/2.0/language-go/ for more details
4- version : 2
4+ version : 2.1
5+ orbs :
6+ codecov :
codecov/[email protected] 57jobs :
6- build-postgres-and-mysql :
8+ build_and_tests :
79 docker :
810 # specify the version
9- - image : circleci/golang:1.13
10-
11- - image : circleci/postgres:10.8-alpine
12- environment : # environment variables for primary container
11+ - image : circleci/golang:1.16
12+ - image : circleci/postgres:12
13+ environment :
1314 POSTGRES_USER : jet
1415 POSTGRES_PASSWORD : jet
1516 POSTGRES_DB : jetdb
17+ PGPORT : 50901
1618
17- - image : circleci/mysql:8.0.16
18- command : [--default-authentication-plugin=mysql_native_password]
19+ - image : circleci/mysql:8.0.27
20+ command : [ --default-authentication-plugin=mysql_native_password ]
1921 environment :
2022 MYSQL_ROOT_PASSWORD : jet
2123 MYSQL_DATABASE : dvds
2224 MYSQL_USER : jet
2325 MYSQL_PASSWORD : jet
26+ MYSQL_TCP_PORT : 50902
2427
25- working_directory : /go/src/github.com/go-jet/jet
28+ - image : circleci/mariadb:10.3
29+ command : [ '--default-authentication-plugin=mysql_native_password', '--port=50903' ]
30+ environment :
31+ MYSQL_ROOT_PASSWORD : jet
32+ MYSQL_DATABASE : dvds
33+ MYSQL_USER : jet
34+ MYSQL_PASSWORD : jet
2635
2736 environment : # environment variables for the build itself
2837 TEST_RESULTS : /tmp/test-results # path to where test results will be saved
@@ -32,25 +41,22 @@ jobs:
3241
3342 - run :
3443 name : Submodule init
35- command : |
36- git submodule init
37- git submodule update
38- cd ./tests/testdata && git fetch && git checkout master
44+ command : cd tests && make checkout-testdata
3945
46+ - restore_cache : # restores saved cache if no changes are detected since last run
47+ keys :
48+ - go-mod-v4-{{ checksum "go.sum" }}
4049
4150 - run :
42- name : Install dependencies
43- command : |
44- cd /go/src/github.com/go-jet/jet
45- go get github.com/jstemmer/go-junit-report
46- go build -o /home/circleci/.local/bin/jet ./cmd/jet/
51+ name : Install jet generator
52+ command : cd tests && make install-jet-gen
4753
4854 - run :
4955 name : Waiting for Postgres to be ready
5056 command : |
5157 for i in `seq 1 10`;
5258 do
53- nc -z localhost 5432 && echo Success && exit 0
59+ nc -z localhost 50901 && echo Success && exit 0
5460 echo -n .
5561 sleep 1
5662 done
@@ -61,109 +67,81 @@ jobs:
6167 command : |
6268 for i in `seq 1 10`;
6369 do
64- nc -z 127.0.0.1 3306 && echo Success && exit 0
70+ nc -z 127.0.0.1 50902 && echo Success && exit 0
6571 echo -n .
6672 sleep 1
6773 done
6874 echo Failed waiting for MySQL && exit 1
75+
76+ - run :
77+ name : Waiting for MariaDB to be ready
78+ command : |
79+ for i in `seq 1 10`;
80+ do
81+ nc -z 127.0.0.1 50903 && echo Success && exit 0
82+ echo -n .
83+ sleep 1
84+ done
85+ echo Failed waiting for MySQL && exit 1
86+
6987 - run :
7088 name : Install MySQL CLI;
7189 command : |
7290 sudo apt-get --allow-releaseinfo-change update && sudo apt-get install default-mysql-client
7391
7492 - run :
75- name : Create MySQL user and databases
93+ name : Create MySQL/MariaDB user and test databases
7694 command : |
77- mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
78- mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
79- mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
80- mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
95+ mysql -h 127.0.0.1 -P 50902 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
96+ mysql -h 127.0.0.1 -P 50902 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
97+ mysql -h 127.0.0.1 -P 50902 -u jet -pjet -e "create database test_sample"
98+ mysql -h 127.0.0.1 -P 50902 -u jet -pjet -e "create database dvds2"
99+
100+ mysql -h 127.0.0.1 -P 50903 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
101+ mysql -h 127.0.0.1 -P 50903 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
102+ mysql -h 127.0.0.1 -P 50903 -u jet -pjet -e "create database test_sample"
103+ mysql -h 127.0.0.1 -P 50903 -u jet -pjet -e "create database dvds2"
81104
82105 - run :
83- name : Init Postgres database
84- command : |
85- cd tests
86- go run ./init/init.go -testsuite all
87- cd ..
106+ name : Init databases
107+ command : |
108+ cd tests
109+ go run ./init/init.go -testsuite all
88110
111+ # to create test results report
112+ - run :
113+ name : Install go-junit-report
114+ command : go install github.com/jstemmer/go-junit-report@latest
89115
90116 - run : mkdir -p $TEST_RESULTS
117+
91118 # this will run all tests and exclude test files from code coverage report
92- - run : MY_SQL_SOURCE=MySQL go test -v ./... -covermode=atomic -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/jet/mysql/...,github.com/go-jet/jet/sqlite/...,github.com/go-jet/jet/qrm/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml
119+ - run : |
120+ go test -v ./... \
121+ -covermode=atomic \
122+ -coverpkg=github.com/go-jet/jet/v2/postgres/...,github.com/go-jet/jet/v2/mysql/...,github.com/go-jet/jet/v2/sqlite/...,github.com/go-jet/jet/v2/qrm/...,github.com/go-jet/jet/v2/generator/...,github.com/go-jet/jet/v2/internal/... \
123+ -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml
93124
94- - run :
95- name : Upload code coverage
96- command : bash <(curl -s https://codecov.io/bash)
125+ # run mariaDB tests. No need to collect coverage, because coverage is already included with mysql tests
126+ - run : MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/
127+
128+ - save_cache :
129+ key : go-mod-v4-{{ checksum "go.sum" }}
130+ paths :
131+ - " /go/pkg/mod"
132+
133+ - codecov/upload :
134+ file : cover.out
97135
98136 - store_artifacts : # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
99137 path : /tmp/test-results
100138 destination : raw-test-output
101139
102140 - store_test_results : # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
103141 path : /tmp/test-results
104- build-mariadb :
105- docker :
106- # specify the version
107- - image : circleci/golang:1.13
108-
109- - image : circleci/mariadb:10.3
110- command : [--default-authentication-plugin=mysql_native_password]
111- environment :
112- MYSQL_ROOT_PASSWORD : jet
113- MYSQL_DATABASE : dvds
114- MYSQL_USER : jet
115- MYSQL_PASSWORD : jet
116-
117- working_directory : /go/src/github.com/go-jet/jet
118-
119- environment : # environment variables for the build itself
120- TEST_RESULTS : /tmp/test-results # path to where test results will be saved
121-
122- steps :
123- - checkout
124-
125- - run :
126- name : Submodule init
127- command : |
128- git submodule init
129- git submodule update
130- cd ./tests/testdata && git fetch && git checkout master
131-
132- - run :
133- name : Install dependencies
134- command : |
135- cd /go/src/github.com/go-jet/jet
136- go get github.com/jstemmer/go-junit-report
137- go build -o /home/circleci/.local/bin/jet ./cmd/jet/
138-
139- - run :
140- name : Install MySQL CLI;
141- command : |
142- sudo apt-get --allow-releaseinfo-change update && sudo apt-get install default-mysql-client
143-
144- - run :
145- name : Init MariaDB database
146- command : |
147- mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
148- mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
149- mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
150- mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
151-
152- - run :
153- name : Init MariaDB database
154- command : |
155- cd tests
156- go run ./init/init.go -testsuite MariaDB
157- cd ..
158-
159- - run :
160- name : Run MariaDB tests
161- command : |
162- MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/
163142
164143workflows :
165144 version : 2
166145 build_and_test :
167146 jobs :
168- - build-postgres-and-mysql
169- - build-mariadb
147+ - build_and_tests
0 commit comments