From 38366ba801063650742ccda186231b19821003c9 Mon Sep 17 00:00:00 2001 From: Artem Baskal Date: Wed, 15 Jul 2020 12:49:08 +0300 Subject: [PATCH] Setup pre-commit lint hook Squashed commit of the following: commit 02591b74c184faf7f7156e95cf05a78fb0ea22a7 Merge: 4057c8ae a32c1f2e Author: ArtemBaskal Date: Wed Jul 15 12:36:20 2020 +0300 Merge branch 'master' into feature/git-hooks commit 4057c8ae117dfb5de493769dbf1577c8d59035a4 Author: ArtemBaskal Date: Tue Jul 14 20:04:38 2020 +0300 Review changes commit 2400ab77d9e0e3f7b62b0ffd64aeccf369ff84cd Author: ArtemBaskal Date: Tue Jul 14 16:27:14 2020 +0300 Add lint-js and lint-go to .PHONY commit 8a4efc2cb4f2d53ebea4b88b8182e4c1eb7812eb Author: ArtemBaskal Date: Tue Jul 14 15:47:14 2020 +0300 Run linter only if corresponding file extension is changed commit 8e2e110e9c9c3f865503cf3c0cd3e31dd4579b71 Author: ArtemBaskal Date: Mon Jul 13 19:07:42 2020 +0300 Setup pre-commit lint hooks --- .githooks/pre-commit | 12 ++++++++++++ Makefile | 18 +++++++++++++----- README.md | 5 ++++- 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100755 .githooks/pre-commit 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: