Skip to content

Commit

Permalink
Merge pull request #116 from go-jet/develop
Browse files Browse the repository at this point in the history
Release 2.7.0
  • Loading branch information
go-jet committed Jan 20, 2022
2 parents 23aeb02 + 4f29960 commit 3e802f8
Show file tree
Hide file tree
Showing 106 changed files with 4,368 additions and 865 deletions.
168 changes: 73 additions & 95 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
version: 2.1
orbs:
codecov: codecov/codecov@3.1.1
jobs:
build-postgres-and-mysql:
build_and_tests:
docker:
# specify the version
- image: circleci/golang:1.13

- image: circleci/postgres:10.8-alpine
environment: # environment variables for primary container
- image: circleci/golang:1.16
- image: circleci/postgres:12
environment:
POSTGRES_USER: jet
POSTGRES_PASSWORD: jet
POSTGRES_DB: jetdb
PGPORT: 50901

- image: circleci/mysql:8.0.16
command: [--default-authentication-plugin=mysql_native_password]
- image: circleci/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

working_directory: /go/src/github.com/go-jet/jet
- image: circleci/mariadb:10.3
command: [ '--default-authentication-plugin=mysql_native_password', '--port=50903' ]
environment:
MYSQL_ROOT_PASSWORD: jet
MYSQL_DATABASE: dvds
MYSQL_USER: jet
MYSQL_PASSWORD: jet

environment: # environment variables for the build itself
TEST_RESULTS: /tmp/test-results # path to where test results will be saved
Expand All @@ -32,25 +41,22 @@ jobs:

- run:
name: Submodule init
command: |
git submodule init
git submodule update
cd ./tests/testdata && git fetch && git checkout master
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 dependencies
command: |
cd /go/src/github.com/go-jet/jet
go get github.com/jstemmer/go-junit-report
go build -o /home/circleci/.local/bin/jet ./cmd/jet/
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 5432 && echo Success && exit 0
nc -z localhost 50901 && echo Success && exit 0
echo -n .
sleep 1
done
Expand All @@ -61,109 +67,81 @@ jobs:
command: |
for i in `seq 1 10`;
do
nc -z 127.0.0.1 3306 && echo Success && exit 0
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: Install MySQL CLI;
command: |
sudo apt-get --allow-releaseinfo-change update && sudo apt-get install default-mysql-client
- run:
name: Create MySQL user and databases
name: Create MySQL/MariaDB user and test databases
command: |
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
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';"
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
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_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_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: Init Postgres database
command: |
cd tests
go run ./init/init.go -testsuite all
cd ..
name: Init databases
command: |
cd tests
go run ./init/init.go -testsuite all
# to create test results report
- run:
name: Install go-junit-report
command: go install github.com/jstemmer/go-junit-report@latest

- run: mkdir -p $TEST_RESULTS

# this will run all tests and exclude test files from code coverage report
- 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
- run: |
go test -v ./... \
-covermode=atomic \
-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/... \
-coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml
- run:
name: Upload code coverage
command: bash <(curl -s https://codecov.io/bash)
# run mariaDB tests. No need to collect coverage, because coverage is already included with mysql tests
- run: MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/

- 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
build-mariadb:
docker:
# specify the version
- image: circleci/golang:1.13

- image: circleci/mariadb:10.3
command: [--default-authentication-plugin=mysql_native_password]
environment:
MYSQL_ROOT_PASSWORD: jet
MYSQL_DATABASE: dvds
MYSQL_USER: jet
MYSQL_PASSWORD: jet

working_directory: /go/src/github.com/go-jet/jet

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: |
git submodule init
git submodule update
cd ./tests/testdata && git fetch && git checkout master
- run:
name: Install dependencies
command: |
cd /go/src/github.com/go-jet/jet
go get github.com/jstemmer/go-junit-report
go build -o /home/circleci/.local/bin/jet ./cmd/jet/
- run:
name: Install MySQL CLI;
command: |
sudo apt-get --allow-releaseinfo-change update && sudo apt-get install default-mysql-client
- run:
name: Init MariaDB database
command: |
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
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';"
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
mysql -h 127.0.0.1 -u jet -pjet -e "create database dvds2"
- run:
name: Init MariaDB database
command: |
cd tests
go run ./init/init.go -testsuite MariaDB
cd ..
- run:
name: Run MariaDB tests
command: |
MY_SQL_SOURCE=MariaDB go test -v ./tests/mysql/

workflows:
version: 2
build_and_test:
jobs:
- build-postgres-and-mysql
- build-mariadb
- build_and_tests
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
gen
.gentestdata
.tests/testdata/
.gen
.gen
.docker
.env
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,26 @@ Use the command bellow to add jet as a dependency into `go.mod` project:
$ go get -u github.com/go-jet/jet/v2
```

Jet generator can be installed in the following ways:
Jet generator can be installed in one of the following ways:

1) Install jet generator to GOPATH/bin folder:
1) (Go1.16+) Install jet generator using go install:
```sh
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
go install github.com/go-jet/jet/v2/cmd/jet@latest
```
*Make sure GOPATH/bin folder is added to the PATH environment variable.*

2) Install jet generator into specific folder:

2) Install jet generator to GOPATH/bin folder:
```sh
cd $GOPATH/src/ && GO111MODULE=off go get -u github.com/go-jet/jet/cmd/jet
```

3) Install jet generator into specific folder:
```sh
git clone https://github.com/go-jet/jet.git
cd jet && go build -o dir_path ./cmd/jet
```
*Make sure `dir_path` folder is added to the PATH environment variable.*
*Make sure that the destination folder is added to the PATH environment variable.*


3) (Go1.16+) Install jet generator using go install:
```sh
go install github.com/go-jet/jet/v2/cmd/jet@latest
```
*Jet generator is installed to the directory named by the GOBIN environment variable,
which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set.*

### Quick Start
For this quick start example we will use PostgreSQL sample _'dvd rental'_ database. Full database dump can be found in
Expand Down

0 comments on commit 3e802f8

Please sign in to comment.