# Golang CircleCI 2.0 configuration file # # Check https://circleci.com/docs/2.0/language-go/ for more details version: 2.1 orbs: codecov: codecov/codecov@3.1.1 jobs: build_and_tests: docker: # specify the version - image: cimg/go:1.24.8 # Please keep the version in sync with test/docker-compose.yaml - image: cimg/postgres:14.1 environment: POSTGRES_USER: jet POSTGRES_PASSWORD: jet POSTGRES_DB: jetdb PGPORT: 50901 # Please keep the version in sync with test/docker-compose.yaml - image: cimg/mysql:8.0.27 command: [ --default-authentication-plugin=mysql_native_password ] environment: MYSQL_ROOT_PASSWORD: jet MYSQL_DATABASE: dvds MYSQL_USER: jet MYSQL_PASSWORD: jet MYSQL_TCP_PORT: 50902 # Please keep the version in sync with test/docker-compose.yaml - image: cimg/mariadb:11.4 command: [ '--default-authentication-plugin=mysql_native_password', '--port=50903' ] environment: MYSQL_ROOT_PASSWORD: jet MYSQL_DATABASE: dvds MYSQL_USER: jet MYSQL_PASSWORD: jet # Please keep the version in sync with test/docker-compose.yaml - image: cockroachdb/cockroach-unstable:v23.1.0-rc.2 command: ['start-single-node', '--accept-sql-without-tls'] environment: COCKROACH_USER: jet COCKROACH_PASSWORD: jet COCKROACH_DATABASE: jetdb environment: # environment variables for the build itself TEST_RESULTS: /tmp/test-results # path to where test results will be saved steps: - checkout - run: name: Submodule init command: cd tests && make checkout-testdata - restore_cache: # restores saved cache if no changes are detected since last run keys: - go-mod-v4-{{ checksum "go.sum" }} - run: name: Install jet generator command: cd tests && make install-jet-gen - run: name: Waiting for Postgres to be ready command: | for i in `seq 1 10`; do nc -z localhost 50901 && echo Success && exit 0 echo -n . sleep 1 done echo Failed waiting for Postgres && exit 1 - run: name: Waiting for MySQL to be ready command: | for i in `seq 1 10`; do nc -z 127.0.0.1 50902 && echo Success && exit 0 echo -n . sleep 1 done echo Failed waiting for MySQL && exit 1 - run: name: Waiting for MariaDB to be ready command: | for i in `seq 1 10`; do nc -z 127.0.0.1 50903 && echo Success && exit 0 echo -n . sleep 1 done echo Failed waiting for MySQL && exit 1 - run: name: Waiting for Cockroach to be ready command: | for i in `seq 1 10`; do nc -z localhost 26257 && echo Success && exit 0 echo -n . sleep 1 done echo Failed waiting for Cockroach && exit 1 - run: name: Install MySQL CLI; command: | sudo apt-get --allow-releaseinfo-change update && sudo apt-get install default-mysql-client - run: name: Create MySQL/MariaDB user and test databases command: | mysql -h 127.0.0.1 -P 50902 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';" mysql -h 127.0.0.1 -P 50902 -u root -pjet -e "set global sql_mode = 'STRICT_ALL_TABLES,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';" mysql -h 127.0.0.1 -P 50902 -u jet -pjet -e "create database test_sample" mysql -h 127.0.0.1 -P 50902 -u jet -pjet -e "create database dvds2" mysql -h 127.0.0.1 -P 50903 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';" mysql -h 127.0.0.1 -P 50903 -u root -pjet -e "set global sql_mode = 'STRICT_ALL_TABLES,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';" mysql -h 127.0.0.1 -P 50903 -u jet -pjet -e "create database test_sample" mysql -h 127.0.0.1 -P 50903 -u jet -pjet -e "create database dvds2" - run: name: Install gotestsum command: go install gotest.tools/gotestsum@latest - run: name: Init databases (postgres, mysql, sqlite) and generate jet files command: | cd tests go run ./init/init.go -testsuite postgres go run ./init/init.go -testsuite mysql go run ./init/init.go -testsuite sqlite # to create test results report - run: mkdir -p $TEST_RESULTS - run: name: Running tests command: | 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/...,github.com/go-jet/jet/v2/stmtcache/..." gotestsum --junitfile $TEST_RESULTS/root-report.xml --format testname -- \ -coverprofile=root-cover.out \ -covermode=atomic \ -coverpkg="$COVERPKG" \ ./... cd tests gotestsum --junitfile $TEST_RESULTS/integration-report.xml --format testname -- \ -tags postgres \ -coverprofile=../integration-cover.out \ -covermode=atomic \ -coverpkg="$COVERPKG" \ ./... cd - head -n 1 root-cover.out > cover.out tail -n +2 root-cover.out >> cover.out tail -n +2 integration-cover.out >> cover.out - run: name: Running tests with statement caching enabled command: cd tests && JET_TESTS_WITH_STMT_CACHE=true go test -v ./... && cd - - run: name: Init databases (mariadb, cockroachdb) and generate jet files command: | cd tests go run ./init/init.go -testsuite mariadb go run ./init/init.go -testsuite cockroach # run mariaDB and cockroachdb tests. No need to collect coverage, because coverage is already included with mysql and postgres tests - run: cd tests && MY_SQL_SOURCE=MariaDB go test -v ./mysql/ - run: cd tests && PG_SOURCE=COCKROACH_DB go test -v ./postgres/ - save_cache: key: go-mod-v4-{{ checksum "go.sum" }} paths: - "/go/pkg/mod" - codecov/upload: file: cover.out - store_artifacts: # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/ path: /tmp/test-results destination: raw-test-output - store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/ path: /tmp/test-results workflows: version: 2 build_and_test: jobs: - build_and_tests