github.com/kaptinlin/jsonschema@v0.4.6/Makefile (about)

     1  # JSON Schema Validation Library for Go
     2  # Set up GOBIN so that our binaries are installed to ./bin instead of $GOPATH/bin.
     3  PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
     4  export GOBIN = $(PROJECT_ROOT)/bin
     5  
     6  GOLANGCI_LINT_VERSION := $(shell $(GOBIN)/golangci-lint version --format short 2>/dev/null)
     7  REQUIRED_GOLANGCI_LINT_VERSION := $(shell cat .golangci.version)
     8  
     9  # Directories containing independent Go modules.
    10  MODULE_DIRS = .
    11  
    12  .PHONY: all
    13  all: lint test
    14  
    15  .PHONY: help
    16  help: ## Show this help message
    17  	@echo "JSON Schema Validation Library for Go"
    18  	@echo "Available targets:"
    19  	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "  %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
    20  
    21  .PHONY: clean
    22  clean: ## Clean build artifacts and caches
    23  	@echo "[clean] Cleaning build artifacts..."
    24  	@rm -rf $(GOBIN)
    25  	@go clean -cache -testcache
    26  
    27  .PHONY: deps
    28  deps: ## Download Go module dependencies
    29  	@echo "[deps] Downloading dependencies..."
    30  	@go mod download
    31  	@go mod tidy
    32  
    33  .PHONY: test
    34  test: ## Run all tests with race detection
    35  	@echo "[test] Running all tests..."
    36  	@$(foreach mod,$(MODULE_DIRS),(cd $(mod) && go test -race ./...) &&) true
    37  
    38  .PHONY: test-unit
    39  test-unit: ## Run unit tests only
    40  	@echo "[test] Running unit tests..."
    41  	@go test -race ./...
    42  
    43  .PHONY: test-coverage
    44  test-coverage: ## Run tests with coverage report
    45  	@echo "[test] Running tests with coverage..."
    46  	@go test -race -coverprofile=coverage.out ./...
    47  	@go tool cover -html=coverage.out -o coverage.html
    48  	@echo "[test] Coverage report generated: coverage.html"
    49  
    50  .PHONY: test-verbose
    51  test-verbose: ## Run tests with verbose output
    52  	@echo "[test] Running tests with verbose output..."
    53  	@go test -race -v ./...
    54  
    55  .PHONY: bench
    56  bench: ## Run benchmarks
    57  	@echo "[bench] Running benchmarks..."
    58  	@go test -bench=. -benchmem ./...
    59  
    60  .PHONY: lint
    61  lint: golangci-lint tidy-lint ## Run all linters
    62  
    63  # Install golangci-lint with the required version in GOBIN if it is not already installed.
    64  .PHONY: install-golangci-lint
    65  install-golangci-lint:
    66      ifneq ($(GOLANGCI_LINT_VERSION),$(REQUIRED_GOLANGCI_LINT_VERSION))
    67  		@echo "[lint] installing golangci-lint v$(REQUIRED_GOLANGCI_LINT_VERSION) since current version is \"$(GOLANGCI_LINT_VERSION)\""
    68  		@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v$(REQUIRED_GOLANGCI_LINT_VERSION)
    69      endif
    70  
    71  .PHONY: golangci-lint
    72  golangci-lint: install-golangci-lint ## Run golangci-lint
    73  	@echo "[lint] $(shell $(GOBIN)/golangci-lint version)"
    74  	@$(foreach mod,$(MODULE_DIRS), \
    75  		(cd $(mod) && \
    76  		echo "[lint] golangci-lint: $(mod)" && \
    77  		$(GOBIN)/golangci-lint run --timeout=10m --path-prefix $(mod)) &&) true
    78  
    79  .PHONY: tidy-lint
    80  tidy-lint: ## Check if go.mod and go.sum are tidy
    81  	@$(foreach mod,$(MODULE_DIRS), \
    82  		(cd $(mod) && \
    83  		echo "[lint] mod tidy: $(mod)" && \
    84  		go mod tidy && \
    85  		git diff --exit-code -- go.mod go.sum) &&) true
    86  
    87  .PHONY: fmt
    88  fmt: ## Format Go code
    89  	@echo "[fmt] Formatting Go code..."
    90  	@go fmt ./...
    91  
    92  .PHONY: vet
    93  vet: ## Run go vet
    94  	@echo "[vet] Running go vet..."
    95  	@go vet ./...
    96  
    97  .PHONY: verify
    98  verify: deps fmt vet lint test ## Run all verification steps (deps, format, vet, lint, test)
    99  	@echo "[verify] All verification steps completed successfully ✅"