Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add make command #5

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions doc/LICENSEHEADER.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2022 CECTC, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2018 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
76 changes: 71 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,83 @@
unit-test:
PKG := "github.com/cectc/dbpack"
PKG_LIST := $(shell go list ${PKG}/... | grep /pkg/)
GO_FILES := $(shell find . -name '*.go' | grep /pkg/ | grep -v _test.go)

.DEFAULT_GOAL := build
.PHONY: all test lint fmt fmtcheck cmt errcheck license

all: fmt errcheck lint build
default: fmt errcheck

########################################################
fmt: ## Format the files
@gofmt -l -w $(GO_FILES)

########################################################
fmtcheck: ## Check and format the files
@gofmt -l -s $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed for:"; gofmt -l -s $(GO_FILES); fi

########################################################
lint: ## lint check
@hash revive 2>&- || go get -u github.com/mgechev/revive
@revive -formatter stylish pkg/...

########################################################
cmt: ## auto comment exported Function
@hash gocmt 2>&- || go get -u github.com/Gnouc/gocmt
@gocmt -d pkg -i

########################################################
errcheck: ## check error
@hash errcheck 2>&- || go get -u github.com/kisielk/errcheck
@errcheck pkg/...

########################################################
test: ## Run unittests
@go test -short ${PKG_LIST}

########################################################
race: dep ## Run data race detector
@go test -race -short ${PKG_LIST}

########################################################
msan: dep ## Run memory sanitizer
@go test -msan -short ${PKG_LIST}

########################################################
dep: ## Get the dependencies
@go get -v -d ./...

########################################################
version: ## Print git revision info
@echo $(expr substr $(git rev-parse HEAD) 1 8)

########################################################
unit-test: ## run unit test
go test ./pkg/... -coverprofile=coverage.txt -covermode=atomic

build:
########################################################
build: ## build dbpack cli, and put in dist dir
@mkdir -p dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./dist/dbpack ./cmd

docker-build: build
########################################################
docker-build: build ## build docker image
docker build -f docker/Dockerfile -t dbpack:latest .

########################################################
integration-test: build docker-build
sh test/cmd/test_single_db.sh
sh test/cmd/test_read_write_splitting.sh

clean:
########################################################
clean: ## clean temporary build dir
@rm -rf coverage.txt
@rm -rf dist
@rm -rf dist

########################################################
license: ## Add license header for all code files
@find . -name \*.go -exec sh -c "if ! grep -q 'LICENSE' '{}'; then mv '{}' tmp && cp doc/LICENSEHEADER.txt '{}' && cat tmp >> '{}' && rm tmp; fi" \;

########################################################
help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2 changes: 1 addition & 1 deletion pkg/executor/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"regexp"
"strconv"

"github.com/go-errors/errors"
"github.com/pkg/errors"

"github.com/cectc/dbpack/pkg/lb"
"github.com/cectc/dbpack/pkg/proto"
Expand Down