From 71748f2a4f0c0cb956a1ec0aaf32e31c7c19e3f6 Mon Sep 17 00:00:00 2001 From: ikopke23 Date: Tue, 24 Nov 2026 20:57:13 -0500 Subject: [PATCH 1/4] Ported a Makefile that I have been using, includes build, run, test, vet, fmt, tidy-check, check, lint, and coverage --- Makefile | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1be023c --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +BINARY := vote +GO := $(shell which go) +LINT := $(shell which golangci-lint) + +# Source packages (mirrors .github/workflows/go.yaml) +PKGS := ./database/ ./logging/ ./sse/ +SRC_DIRS := database logging sse + +ifeq ($(GO),) +$(error Go not found in PATH) +endif + +.PHONY: build run test vet fmt fmt-check lint tidy-check check coverage clean + +build: + $(GO) build -o bin/$(BINARY) . + +run: + $(GO) run . + +test: + $(GO) test -count=1 ./database + +vet: + $(GO) vet $(PKGS) + $(GO) vet *.go + +fmt: + gofmt -s -w $(SRC_DIRS) *.go + +fmt-check: + @out="$$(gofmt -s -l $(SRC_DIRS) *.go)"; \ + if [ -n "$$out" ]; then \ + echo "Files not gofmt -s formatted:"; \ + echo "$$out"; \ + exit 1; \ + fi + +lint: +ifeq ($(LINT),) + $(error golangci-lint not found in PATH) +endif + $(LINT) run + +tidy-check: + $(GO) mod tidy -diff + +# Runs the same checks as CI +check: tidy-check fmt-check vet test + +coverage: + $(GO) test -coverprofile=coverage.out ./database + $(GO) tool cover -html=coverage.out + +clean: + rm -rf bin/ coverage.out From 851ee04e20b9bccdd883ba333eb25f6b3fcc44d0 Mon Sep 17 00:00:00 2001 From: ikopke23 Date: Tue, 24 Nov 2026 21:00:00 -0500 Subject: [PATCH 2/4] removing lint because we don't have golangci-lint config and it currently doesn't do anything --- Makefile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 1be023c..5f2216f 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ ifeq ($(GO),) $(error Go not found in PATH) endif -.PHONY: build run test vet fmt fmt-check lint tidy-check check coverage clean +.PHONY: build run test vet fmt fmt-check tidy-check check coverage clean build: $(GO) build -o bin/$(BINARY) . @@ -36,12 +36,6 @@ fmt-check: exit 1; \ fi -lint: -ifeq ($(LINT),) - $(error golangci-lint not found in PATH) -endif - $(LINT) run - tidy-check: $(GO) mod tidy -diff From 122798f53e22686dfff0a16bb590c9e1f912a581 Mon Sep 17 00:00:00 2001 From: ikopke23 Date: Tue, 24 Nov 2026 21:52:49 -0500 Subject: [PATCH 3/4] Adjusting Makefile to include lint in accordance with readme, adjusted readme to use makefile commands --- Makefile | 19 +++++-------------- README.md | 7 ++++--- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 5f2216f..b3e24e5 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,15 @@ BINARY := vote GO := $(shell which go) -LINT := $(shell which golangci-lint) +GOFMT := $(shell which gofmt) # Source packages (mirrors .github/workflows/go.yaml) PKGS := ./database/ ./logging/ ./sse/ -SRC_DIRS := database logging sse ifeq ($(GO),) $(error Go not found in PATH) endif -.PHONY: build run test vet fmt fmt-check tidy-check check coverage clean +.PHONY: build run test vet lint tidy-check check coverage clean build: $(GO) build -o bin/$(BINARY) . @@ -25,22 +24,14 @@ vet: $(GO) vet $(PKGS) $(GO) vet *.go -fmt: - gofmt -s -w $(SRC_DIRS) *.go - -fmt-check: - @out="$$(gofmt -s -l $(SRC_DIRS) *.go)"; \ - if [ -n "$$out" ]; then \ - echo "Files not gofmt -s formatted:"; \ - echo "$$out"; \ - exit 1; \ - fi +lint: + $(GOFMT) -w -s *.go logging sse database tidy-check: $(GO) mod tidy -diff # Runs the same checks as CI -check: tidy-check fmt-check vet test +check: tidy-check vet test coverage: $(GO) test -coverprofile=coverage.out ./database 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 From eee7e194309265df89fb69f4ed4cbf2e7395011d Mon Sep 17 00:00:00 2001 From: ikopke23 Date: Tue, 24 Nov 2026 21:59:22 -0500 Subject: [PATCH 4/4] fixes make run, I forgot we run vote in a container --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b3e24e5..a150f81 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,13 @@ ifeq ($(GO),) $(error Go not found in PATH) endif -.PHONY: build run test vet lint tidy-check check coverage clean +.PHONY: build test vet lint tidy-check check coverage clean build: $(GO) build -o bin/$(BINARY) . run: - $(GO) run . + docker-compose up test: $(GO) test -count=1 ./database