From 2eb01148e18a849964d69081a9a215c4e0c45db5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 21 Feb 2020 00:45:36 +0800 Subject: [PATCH] Improve drone --- .drone.yml | 224 +++++++++++++++++++++++++++++++++++++++++++++++------ Makefile | 89 ++++++++++++--------- 2 files changed, 254 insertions(+), 59 deletions(-) diff --git a/.drone.yml b/.drone.yml index a4fb812d..fd1efb34 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,7 +3,6 @@ kind: pipeline name: testing steps: - name: test-vet - pull: default image: golang:1.12 environment: GO111MODULE: "on" @@ -16,44 +15,102 @@ steps: - pull_request - name: test-sqlite - pull: default image: golang:1.12 environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -coverprofile=coverage1-1.txt -covermode=atomic" - - "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic" + - make test-sqlite + when: + event: + - push + - pull_request + +- name: test-sqlite-cache + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_CACHE_ENABLE: true + commands: + - make test-sqlite when: event: - push - pull_request - name: test-mysql - pull: default image: golang:1.12 environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_MYSQL_HOST: mysql + TEST_MYSQL_CHARSET: utf8 + TEST_MYSQL_DBNAME: xorm_test + TEST_MYSQL_USERNAME: root + TEST_MYSQL_PASSWORD: + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -coverprofile=coverage2-1.txt -covermode=atomic" - - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic" + - make test-mysql + when: + event: + - push + - pull_request + +- name: test-mysql-cache + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_MYSQL_HOST: mysql + TEST_MYSQL_CHARSET: utf8 + TEST_MYSQL_DBNAME: xorm_test + TEST_MYSQL_USERNAME: root + TEST_MYSQL_PASSWORD: + TEST_CACHE_ENABLE: true + commands: + - make test-mysql when: event: - push - pull_request - name: test-mysql-utf8mb4 - pull: default image: golang:1.12 depends_on: - test-mysql environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_MYSQL_HOST: mysql + TEST_MYSQL_CHARSET: utf8mb4 + TEST_MYSQL_DBNAME: xorm_test + TEST_MYSQL_USERNAME: root + TEST_MYSQL_PASSWORD: + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -coverprofile=coverage2.1-1.txt -covermode=atomic" - - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -cache=true -coverprofile=coverage2.1-2.txt -covermode=atomic" + - make test-mysql + when: + event: + - push + - pull_request + +- name: test-mysql-utf8mb4-cache + image: golang:1.12 + depends_on: + - test-mysql + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_MYSQL_HOST: mysql + TEST_MYSQL_CHARSET: utf8mb4 + TEST_MYSQL_DBNAME: xorm_test + TEST_MYSQL_USERNAME: root + TEST_MYSQL_PASSWORD: + TEST_CACHE_ENABLE: true + commands: + - make test-mysql when: event: - push @@ -67,9 +124,33 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_MYSQL_HOST: mysql + TEST_MYSQL_DBNAME: xorm_test + TEST_MYSQL_USERNAME: root + TEST_MYSQL_PASSWORD: + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -coverprofile=coverage3-1.txt -covermode=atomic" - - "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic" + - make test-mymysql + when: + event: + - push + - pull_request + +- name: test-mymysql-cache + pull: default + image: golang:1.12 + depends_on: + - test-mysql-utf8mb4 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_MYSQL_HOST: mysql + TEST_MYSQL_DBNAME: xorm_test + TEST_MYSQL_USERNAME: root + TEST_MYSQL_PASSWORD: + TEST_CACHE_ENABLE: true + commands: + - make test-mymysql when: event: - push @@ -81,9 +162,31 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_PGSQL_HOST: pgsql + TEST_PGSQL_DBNAME: xorm_test + TEST_PGSQL_USERNAME: postgres + TEST_PGSQL_PASSWORD: postgres + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -coverprofile=coverage4-1.txt -covermode=atomic" - - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic" + - make test-postgres + when: + event: + - push + - pull_request + +- name: test-postgres-cache + pull: default + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_PGSQL_HOST: pgsql + TEST_PGSQL_DBNAME: xorm_test + TEST_PGSQL_USERNAME: postgres + TEST_PGSQL_PASSWORD: postgres + TEST_CACHE_ENABLE: true + commands: + - make test-postgres when: event: - push @@ -95,9 +198,35 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_PGSQL_HOST: pgsql + TEST_PGSQL_SCHEMA: xorm + TEST_PGSQL_DBNAME: xorm_test + TEST_PGSQL_USERNAME: postgres + TEST_PGSQL_PASSWORD: postgres + TEST_CACHE_ENABLE: false + SCHEMA: xorm commands: - - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic" - - "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic" + - make test-postgres + when: + event: + - push + - pull_request + +- name: test-postgres-schema-cache + pull: default + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_PGSQL_HOST: pgsql + TEST_PGSQL_SCHEMA: xorm + TEST_PGSQL_DBNAME: xorm_test + TEST_PGSQL_USERNAME: postgres + TEST_PGSQL_PASSWORD: postgres + TEST_CACHE_ENABLE: true + SCHEMA: xorm + commands: + - make test-postgres when: event: - push @@ -109,9 +238,31 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_MSSQL_HOST: mssql + TEST_MSSQL_DBNAME: xorm_test + TEST_MSSQL_USERNAME: sa + TEST_MSSQL_PASSWORD: "yourStrong(!)Password" + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -coverprofile=coverage6-1.txt -covermode=atomic" - - "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic" + - make test-mssql + when: + event: + - push + - pull_request + +- name: test-mssql-cache + pull: default + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_MSSQL_HOST: mssql + TEST_MSSQL_DBNAME: xorm_test + TEST_MSSQL_USERNAME: sa + TEST_MSSQL_PASSWORD: "yourStrong(!)Password" + TEST_CACHE_ENABLE: true + commands: + - make test-mssql when: event: - push @@ -123,9 +274,31 @@ steps: environment: GO111MODULE: "on" GOPROXY: "https://goproxy.cn" + TEST_TIDB_HOST: "tidb:4000" + TEST_TIDB_DBNAME: xorm_test + TEST_TIDB_USERNAME: root + TEST_TIDB_PASSWORD: + TEST_CACHE_ENABLE: false commands: - - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(tidb:4000)/xorm_test\" -ignore_select_update=true -coverprofile=coverage7-1.txt -covermode=atomic" - - "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(tidb:4000)/xorm_test\" -ignore_select_update=true -cache=true -coverprofile=coverage7-2.txt -covermode=atomic" + - make test-tidb + when: + event: + - push + - pull_request + +- name: test-tidb-cache + pull: default + image: golang:1.12 + environment: + GO111MODULE: "on" + GOPROXY: "https://goproxy.cn" + TEST_TIDB_HOST: "tidb:4000" + TEST_TIDB_DBNAME: xorm_test + TEST_TIDB_USERNAME: root + TEST_TIDB_PASSWORD: + TEST_CACHE_ENABLE: true + commands: + - make test-tidb when: event: - push @@ -140,16 +313,23 @@ steps: depends_on: - test-vet - test-sqlite + - test-sqlite-cache - test-mysql + - test-mysql-cache - test-mysql-utf8mb4 + - test-mysql-utf8mb4-cache - test-mymysql + - test-mymysql-cache - test-postgres + - test-postgres-cache - test-postgres-schema + - test-postgres-schema-cache - test-mssql + - test-mssql-cache - test-tidb + - test-tidb-cache commands: - - go get github.com/wadey/gocovmerge - - gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt coverage7-1.txt coverage7-2.txt > coverage.txt + - make coverage when: event: - push diff --git a/Makefile b/Makefile index 20a486b1..d6ce2332 100644 --- a/Makefile +++ b/Makefile @@ -16,20 +16,24 @@ TEST_MSSQL_USERNAME ?= sa TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1 TEST_MYSQL_HOST ?= mysql:3306 +TEST_MYSQL_CHARSET ?= utf8 TEST_MYSQL_DBNAME ?= xorm_test TEST_MYSQL_USERNAME ?= root TEST_MYSQL_PASSWORD ?= TEST_PGSQL_HOST ?= pgsql:5432 -TEST_PGSQL_DBNAME ?= testgitea +TEST_PGSQL_SCHEMA ?= +TEST_PGSQL_DBNAME ?= xorm_test TEST_PGSQL_USERNAME ?= postgres -TEST_PGSQL_PASSWORD ?= postgres +TEST_PGSQL_PASSWORD ?= mysecretpassword TEST_TIDB_HOST ?= tidb:4000 TEST_TIDB_DBNAME ?= xorm_test TEST_TIDB_USERNAME ?= root TEST_TIDB_PASSWORD ?= +TEST_CACHE_ENABLE ?= false + .PHONY: all all: build @@ -40,7 +44,14 @@ build: go-check $(GO_SOURCES) .PHONY: clean clean: $(GO) clean -i ./... - rm -rf *.sql *.log test.db + rm -rf *.sql *.log test.db *coverage.out coverage.all + +.PHONY: coverage +coverage: + @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GO) get -u github.com/wadey/gocovmerge; \ + fi + gocovmerge $(shell find . -type f -name "coverage.out") > coverage.all;\ .PHONY: fmt fmt: @@ -106,70 +117,74 @@ test: test-sqlite .PNONY: test-mssql test-mssql: go-check - $(GO) test -race -db=mssql -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" - -.PNONY: test-mssql-cache -test-mssql-cache: go-check - $(GO) test -race -db=mssql -cache=true -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" + $(GO) test -race -db=mssql -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \ + -coverprofile=mssql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic +.PNONY: test-mssql\#% +test-mssql\#%: go-check + $(GO) test -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \ + -coverprofile=mssql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-mymysql test-mymysql: go-check - $(GO) test -race -db=mymysql -conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" + $(GO) test -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \ + -coverprofile=mymysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic -.PNONY: test-mymysql-cache -test-mymysql-cache: go-check - $(GO) test -race -db=mymysql -cache=true -conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" +.PNONY: test-mymysql\#% +test-mymysql\#%: go-check + $(GO) test -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \ + -coverprofile=mymysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-mysql test-mysql: go-check - $(GO) test -race -db=mysql -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)" - -.PNONY: test-mysql-cache -test-mysql-cache: go-check - $(GO) test -race -db=mysql -cache=true -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)" + $(GO) test -race -db=mysql -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \ + -coverprofile=mysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-mysql\#% test-mysql\#%: go-check - $(GO) test -race -run $* -db=mysql -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)" + $(GO) test -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \ + -coverprofile=mysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-postgres test-postgres: go-check - $(GO) test -race -db=postgres -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" - -.PNONY: test-postgres-cache -test-postgres-cache: go-check - $(GO) test -race -db=postgres -cache=true -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" + $(GO) test -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \ + -coverprofile=postgres.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-postgres\#% test-postgres\#%: go-check - $(GO) test -race -run $* -db=postgres -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" + $(GO) test -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \ + -conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \ + -coverprofile=postgres.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-sqlite test-sqlite: go-check - $(GO) test -race -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" - -.PHONY: test-sqlite-cache -test-sqlite-cache: go-check - $(GO) test -race -cache=true -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" + $(GO) test -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \ + -coverprofile=sqlite.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-sqlite\#% test-sqlite\#%: go-check - $(GO) test -race -run $* -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" + $(GO) test -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \ + -coverprofile=sqlite.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PNONY: test-tidb test-tidb: go-check - $(GO) test -race -db=mysql -ignore_select_update=true -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" - -.PNONY: test-tidb-cache -test-tidb-cache: go-check - $(GO) test -race -db=mysql -ignore_select_update=true -cache=true -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" + $(GO) test -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \ + -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \ + -coverprofile=tidb.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic .PHONY: test-tidb\#% test-tidb\#%: go-check - $(GO) test -race -run $* -db=mysql -ignore_select_update=true -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" + $(GO) test -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \ + -conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \ + -coverprofile=tidb.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic -go test -db=mysql -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true .PHONY: vet vet: $(GO) vet $(PACKAGES) \ No newline at end of file