-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Text files have auto line endings | ||
* text=auto | ||
|
||
# Go source files always have LF line endings | ||
*.go text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
PROJECT_NAME := go-modbus-client | ||
PKG := "github.com/aldas/$(PROJECT_NAME)" | ||
PKG_LIST := $(shell go list ${PKG}/...) | ||
|
||
.PHONY: init lint test coverage coverhtml | ||
|
||
.DEFAULT_GOAL := check | ||
|
||
check: lint vet race ## check project | ||
|
||
init: | ||
git config core.hooksPath ./scripts/.githooks | ||
@go get -u golang.org/x/lint/golint | ||
|
||
lint: ## Lint the files | ||
@golint -set_exit_status ${PKG_LIST} | ||
|
||
vet: ## Vet the files | ||
@go vet ${PKG_LIST} | ||
|
||
test: ## Run unittests | ||
@go test -short ${PKG_LIST} | ||
|
||
goversion ?= "1.16" | ||
test_version: ## Run tests inside Docker with given version (defaults to 1.16 oldest supported). Example: make test_version goversion=1.16 | ||
@docker run --rm -it -v $(shell pwd):/project golang:$(goversion) /bin/sh -c "cd /project && make init check" | ||
|
||
race: ## Run data race detector | ||
@go test -race -short ${PKG_LIST} | ||
|
||
benchmark: ## Run benchmarks | ||
@go test -run="-" -bench=".*" ${PKG_LIST} | ||
|
||
coverage: ## Generate global code coverage report | ||
./scripts/coverage.sh; | ||
|
||
coverhtml: ## Generate global code coverage report in HTML | ||
./scripts/coverage.sh html; | ||
|
||
|
||
help: ## Display this help screen | ||
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/aldas/go-modbus-client | ||
|
||
go 1.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -z "$(which golint)" ]]; then | ||
echo "golint not found, executing: go get github.com/golang/lint/golint" | ||
go get github.com/golang/lint/golint | ||
fi | ||
|
||
STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$") | ||
|
||
if [[ "$STAGED_GO_FILES" = "" ]]; then | ||
exit 0 | ||
fi | ||
|
||
# can not check only changed files as if it references structs etc in same package | ||
# but in different file it reports that as 'route.go:18:11: undefined: Service' | ||
go vet ./... | ||
if [[ $? != 0 ]]; then | ||
printf "go vet FAILED\n" | ||
exit 1 | ||
fi | ||
|
||
PASS=true | ||
|
||
for FILE in ${STAGED_GO_FILES} | ||
do | ||
if [[ ! -f ${FILE} ]]; then | ||
continue | ||
fi | ||
|
||
golint -set_exit_status ${FILE} | ||
if [[ $? != 0 ]]; then | ||
PASS=false | ||
fi | ||
done | ||
|
||
if ! ${PASS}; then | ||
printf "COMMIT FAILED\n" | ||
exit 1 | ||
else | ||
printf "COMMIT SUCCEEDED\n" | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Code coverage generation | ||
|
||
COVERAGE_DIR="${COVERAGE_DIR:-coverage}" | ||
PKG_LIST=$(go list ./...) | ||
|
||
# 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.xcov ; | ||
tail -q -n +2 "${COVERAGE_DIR}"/*.cov >> "${COVERAGE_DIR}"/coverage.xcov ; | ||
|
||
# Display the global code coverage | ||
go tool cover -func="${COVERAGE_DIR}"/coverage.xcov ; | ||
|
||
# If needed, generate HTML report | ||
if [[ "$1" == "html" ]]; then | ||
go tool cover -html="${COVERAGE_DIR}"/coverage.xcov -o coverage.html ; | ||
fi | ||
|
||
# Remove the coverage files directory | ||
rm -rf "$COVERAGE_DIR"; |