diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a150f81 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +BINARY := vote +GO := $(shell which go) +GOFMT := $(shell which gofmt) + +# Source packages (mirrors .github/workflows/go.yaml) +PKGS := ./database/ ./logging/ ./sse/ + +ifeq ($(GO),) +$(error Go not found in PATH) +endif + +.PHONY: build test vet lint tidy-check check coverage clean + +build: + $(GO) build -o bin/$(BINARY) . + +run: + docker-compose up + +test: + $(GO) test -count=1 ./database + +vet: + $(GO) vet $(PKGS) + $(GO) vet *.go + +lint: + $(GOFMT) -w -s *.go logging sse database + +tidy-check: + $(GO) mod tidy -diff + +# Runs the same checks as CI +check: tidy-check vet test + +coverage: + $(GO) test -coverprofile=coverage.out ./database + $(GO) tool cover -html=coverage.out + +clean: + rm -rf bin/ coverage.out diff --git a/README.md b/README.md index a692756..5e6a43b 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,18 @@ These will be checked by CI ``` # tidy dependencies +make tidy-check go mod tidy # format all code according to go standards +make lint gofmt -w -s *.go logging sse database # run tests (database is the first place we've defined tests) -go test ./database +make test # run heuristic validation -go vet ./database/ ./logging/ ./sse/ -go vet *.go +make vet ``` ## To-Dos