ci config
This commit is contained in:
parent
c6a7618651
commit
f2e94e4fea
30
Makefile
30
Makefile
@ -3,10 +3,36 @@ PKG := "gitlab.lehouerou.net/laurent/$(PROJECT_NAME)"
|
||||
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
|
||||
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
|
||||
|
||||
.PHONY: all dep build clean test coverage coverhtml lint
|
||||
|
||||
all: build
|
||||
|
||||
lint: ## Lint the files
|
||||
@golint -set_exit_status ${PKG_LIST}
|
||||
|
||||
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}
|
||||
|
||||
coverage: ## Generate global code coverage report
|
||||
./tools/coverage.sh;
|
||||
|
||||
coverhtml: ## Generate global code coverage report in HTML
|
||||
./tools/coverage.sh html;
|
||||
|
||||
dep: ## Get the dependencies
|
||||
@go get -v -d ./...
|
||||
@go get -v -d ./...
|
||||
|
||||
build: dep ## Build the binary file
|
||||
@go build -i -v $(PKG)
|
||||
@go build -i -v $(PKG)
|
||||
|
||||
clean: ## Remove previous build
|
||||
@rm -f $(PROJECT_NAME)
|
||||
|
||||
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}'
|
29
tools/coverage.sh
Normal file
29
tools/coverage.sh
Normal file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Code coverage generation
|
||||
|
||||
COVERAGE_DIR="${COVERAGE_DIR:-coverage}"
|
||||
PKG_LIST=$(go list ./... | grep -v /vendor/)
|
||||
|
||||
# Create the coverage files directory
|
||||
mkdir -p "$COVERAGE_DIR";
|
||||
|
||||
# Create a coverage file for each package
|
||||
for package in ${PKG_LIST}; do
|
||||
go test -covermode=count -coverprofile "${COVERAGE_DIR}/${package##*/}.cov" "$package" ;
|
||||
done ;
|
||||
|
||||
# Merge the coverage profile files
|
||||
echo 'mode: count' > "${COVERAGE_DIR}"/coverage.cov ;
|
||||
tail -q -n +2 "${COVERAGE_DIR}"/*.cov >> "${COVERAGE_DIR}"/coverage.cov ;
|
||||
|
||||
# Display the global code coverage
|
||||
go tool cover -func="${COVERAGE_DIR}"/coverage.cov ;
|
||||
|
||||
# If needed, generate HTML report
|
||||
if [ "$1" == "html" ]; then
|
||||
go tool cover -html="${COVERAGE_DIR}"/coverage.cov -o coverage.html ;
|
||||
fi
|
||||
|
||||
# Remove the coverage files directory
|
||||
rm -rf "$COVERAGE_DIR";
|
Loading…
Reference in New Issue
Block a user