diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 00000000..d933e462 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,12 @@ +#!/bin/bash +set -e; +git diff --cached --name-only | grep -q '.js$' && make lint-js; + +found=0 +git diff --cached --name-only | grep -q '.go$' && found=1 +if [ $found == 1 ]; then + make lint-go || exit 1 + go test ./... || exit 1 +fi + +exit 0; diff --git a/Makefile b/Makefile index 7c3faeaf..73567b91 100644 --- a/Makefile +++ b/Makefile @@ -88,9 +88,12 @@ ifndef DOCKER_IMAGE_NAME $(error DOCKER_IMAGE_NAME value is not set) endif -.PHONY: all build client client-watch docker lint test dependencies clean release docker-multi-arch +.PHONY: all build client client-watch docker lint lint-js lint-go test dependencies clean release docker-multi-arch all: build +init: + git config core.hooksPath .githooks + build: dependencies client PATH=$(GOPATH)/bin:$(PATH) go generate ./... CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=$(VERSION) -X main.channel=$(CHANNEL) -X main.goarm=$(GOARM)" @@ -116,11 +119,16 @@ docker: @echo Now you can run the docker image: @echo docker run --name "adguard-home" -p 53:53/tcp -p 53:53/udp -p 80:80/tcp -p 443:443/tcp -p 853:853/tcp -p 3000:3000/tcp $(DOCKER_IMAGE_NAME) -lint: - @echo Running linters - golangci-lint run ./... +lint: lint-js lint-go + +lint-js: + @echo Running js linter npm --prefix client run lint +lint-go: + @echo Running go linter + golangci-lint run + test: @echo Running unit-tests go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./... @@ -223,4 +231,4 @@ define write_version_file # Finish echo "}" >> $(DIST_DIR)/version.json -endef \ No newline at end of file +endef diff --git a/README.md b/README.md index 17421a5d..ae6d0730 100644 --- a/README.md +++ b/README.md @@ -150,11 +150,14 @@ Is there a chance to handle this in the future? DNS will never be enough to do t ### Prerequisites +Run `make init` to prepare the development environment. + You will need this to build AdGuard Home: * [go](https://golang.org/dl/) v1.14 or later. * [node.js](https://nodejs.org/en/download/) v10 or later. - + * [golangci-lint](https://github.com/golangci/golangci-lint) + ### Building Open Terminal and execute these commands: