Skip to content

Commit 9da6b51

Browse files
committed
feat: Add OS-aware pre-commit installation, include gosec in all target, and refine .PHONY declarations.
1 parent 9c08ed6 commit 9da6b51

1 file changed

Lines changed: 45 additions & 20 deletions

File tree

Makefile

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,65 @@
11
SHELL := /usr/bin/env bash
22

3-
.PHONY: all
4-
all: install-pre-commit-mac \
5-
install-pre-commit-linux \
6-
install-pre-commit-hooks \
7-
golangci \
8-
yamllint \
9-
govet \
10-
goerrcheck \
11-
gofull \
12-
test-report \
13-
test \
14-
lint
3+
# OS detection variable (Darwin for macOS, Linux for Linux)
4+
UNAME_S := $(shell uname -s)
155

6+
.PHONY: all install-pre-commit-mac install-pre-commit-linux install-pre-commit install-pre-commit-hooks gofmt golangci yamllint govet goerrcheck gofull gosec test-report test lint
167

8+
all: install-pre-commit \
9+
install-pre-commit-hooks \
10+
golangci \
11+
yamllint \
12+
govet \
13+
goerrcheck \
14+
gofull \
15+
test-report \
16+
test \
17+
lint
18+
19+
# Runs only on macOS
1720
install-pre-commit-mac:
18-
@brew install pre-commit
21+
@echo "Checking pre-commit on macOS..."
22+
@if ! command -v pre-commit &> /dev/null; then \
23+
echo "pre-commit not found, installing via brew..."; \
24+
brew install pre-commit; \
25+
else \
26+
echo "pre-commit is already installed."; \
27+
fi
28+
29+
# Runs only on Linux
1930
install-pre-commit-linux:
20-
@sudo apt install pre-commit
31+
@echo "Checking pre-commit on Linux..."
32+
@if ! command -v pre-commit &> /dev/null; then \
33+
echo "pre-commit not found, installing via apt..."; \
34+
sudo apt update && sudo apt install -y pre-commit; \
35+
else \
36+
echo "pre-commit is already installed."; \
37+
fi
38+
39+
# Selects the correct installer based on the operating system
40+
install-pre-commit:
41+
ifeq ($(UNAME_S), Darwin)
42+
@$(MAKE) install-pre-commit-mac
43+
else ifeq ($(UNAME_S), Linux)
44+
@$(MAKE) install-pre-commit-linux
45+
else
46+
@echo "Unsupported OS: $(UNAME_S). Please install pre-commit manually."
47+
@exit 1
48+
endif
49+
2150
install-pre-commit-hooks:
2251
@pre-commit install --install-hooks
2352
@pre-commit install --hook-type commit-msg --install-hooks
2453

2554
gofmt:
2655
@go fmt ./...
2756

28-
2957
golangci:
3058
@golangci-lint run --config=.golangci.yaml ./...
3159

3260
yamllint:
3361
@pre-commit run yamllint --all-files
3462

35-
3663
govet:
3764
@go vet ./...
3865

@@ -47,7 +74,6 @@ gofull:
4774
gosec:
4875
@gosec ./...
4976

50-
.PHONY: gost-report
5177
test-report:
5278
@echo "Running tests and generating coverage report..."
5379
@go test -coverprofile=coverage.out -covermode=atomic -race -v ./... || (echo "\nTests failed. Check test output above."; exit 1)
@@ -59,13 +85,12 @@ test-report:
5985
@go tool cover -func=coverage.out | grep total:
6086
@echo "\nHTML report: file://$(shell pwd)/coverage.html"
6187

62-
.PHONY: lint
6388
test: ## Run all tests
6489
@go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
6590

6691
lint: ## Run all linters
6792
@echo "Running linters..."
68-
make yamllint
93+
@$(MAKE) yamllint
6994
@$(MAKE) golangci
7095
@$(MAKE) goerrcheck
71-
@$(MAKE) govet
96+
@$(MAKE) govet

0 commit comments

Comments
 (0)