11SHELL := /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
1720install-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
1930install-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+
2150install-pre-commit-hooks :
2251 @pre-commit install --install-hooks
2352 @pre-commit install --hook-type commit-msg --install-hooks
2453
2554gofmt :
2655 @go fmt ./...
2756
28-
2957golangci :
3058 @golangci-lint run --config=.golangci.yaml ./...
3159
3260yamllint :
3361 @pre-commit run yamllint --all-files
3462
35-
3663govet :
3764 @go vet ./...
3865
@@ -47,7 +74,6 @@ gofull:
4774gosec :
4875 @gosec ./...
4976
50- .PHONY : gost-report
5177test-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
6388test : # # Run all tests
6489 @go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
6590
6691lint : # # 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