refactor(build): enhance Makefile with development targets and update golangci-lint configuration
- Add help, fmt, lint, mocks, check targets to Makefile - Add test-usecase, test-adapter, test-v, test-short targets - Add build-local target for current platform - Organize targets with section headers - Update golangci-lint config for clean architecture
- commit
- 04565617c21120a9e925984433e0900331c056a2
- author
- brice · · 2026-01-12 18:48 UTC
- committer
- brice · · 2026-01-12 20:59 UTC
- parent
- 7efce35
- signature
- unsigned
2 files · +120 -41
M .golangci.yml +48 -14
| @@ -1,35 +1,69 @@ | |||
| 1 | + | version: "2" | |
| 2 | + | ||
| 1 | 3 | run: | |
| 2 | 4 | timeout: 5m | |
| 3 | 5 | tests: true | |
| 4 | 6 | ||
| 5 | 7 | linters: | |
| 6 | 8 | enable: | |
| 7 | - | - gofmt | |
| 8 | 9 | - govet | |
| 9 | 10 | - errcheck | |
| 10 | 11 | - staticcheck | |
| 11 | 12 | - unused | |
| 12 | - | - gosimple | |
| 13 | 13 | - ineffassign | |
| 14 | - | - typecheck | |
| 15 | 14 | - misspell | |
| 16 | 15 | - gosec | |
| 17 | 16 | - unconvert | |
| 18 | 17 | - gocyclo | |
| 18 | + | settings: | |
| 19 | + | gocyclo: | |
| 20 | + | min-complexity: 15 | |
| 21 | + | exclusions: | |
| 22 | + | rules: | |
| 23 | + | - path: _test\.go | |
| 24 | + | linters: | |
| 25 | + | - gocyclo | |
| 26 | + | - errcheck | |
| 27 | + | - dupl | |
| 28 | + | - gosec | |
| 29 | + | - text: "Error return value of `.*Close` is not checked" | |
| 30 | + | linters: | |
| 31 | + | - errcheck | |
| 32 | + | - text: "Error return value of `.*Write` is not checked" | |
| 33 | + | linters: | |
| 34 | + | - errcheck | |
| 35 | + | - text: "Error return value of `os.Remove.*` is not checked" | |
| 36 | + | linters: | |
| 37 | + | - errcheck | |
| 38 | + | - text: "Error return value of `.*Publish` is not checked" | |
| 39 | + | linters: | |
| 40 | + | - errcheck | |
| 41 | + | - text: "Error return value of `.*Stop` is not checked" | |
| 42 | + | linters: | |
| 43 | + | - errcheck | |
| 44 | + | - text: "Error return value of `.*RemoveContainer` is not checked" | |
| 45 | + | linters: | |
| 46 | + | - errcheck | |
| 47 | + | - text: "Error return value of `log.WrapErr` is not checked" | |
| 48 | + | linters: | |
| 49 | + | - errcheck | |
| 50 | + | - text: "Error return value of `log.WrapErrWithFields` is not checked" | |
| 51 | + | linters: | |
| 52 | + | - errcheck | |
| 53 | + | # gosec: file operations with variables are intentional in storage layer | |
| 54 | + | - text: "G304:" | |
| 55 | + | linters: | |
| 56 | + | - gosec | |
| 57 | + | # gosec: G104 duplicates errcheck | |
| 58 | + | - text: "G104:" | |
| 59 | + | linters: | |
| 60 | + | - gosec | |
| 19 | 61 | ||
| 20 | - | linters-settings: | |
| 21 | - | gocyclo: | |
| 22 | - | min-complexity: 15 | |
| 62 | + | formatters: | |
| 63 | + | enable: | |
| 64 | + | - gofmt | |
| 23 | 65 | ||
| 24 | 66 | issues: | |
| 25 | - | exclude-rules: | |
| 26 | - | - path: _test\.go | |
| 27 | - | linters: | |
| 28 | - | - gocyclo | |
| 29 | - | - errcheck | |
| 30 | - | - dupl | |
| 31 | - | - gosec | |
| 32 | - | ||
| 33 | 67 | max-same-issues: 50 | |
| 34 | 68 | ||
| 35 | 69 | severity: | |
| @@ -1,35 +1,69 @@ | |||||
| 1 | + | version: "2" | |||
| 2 | + | ||||
| 1 | run: | 3 | run: | ||
| 2 | timeout: 5m | 4 | timeout: 5m | ||
| 3 | tests: true | 5 | tests: true | ||
| 4 | 6 | ||||
| 5 | linters: | 7 | linters: | ||
| 6 | enable: | 8 | enable: | ||
| 7 | - | - gofmt | |||
| 8 | - govet | 9 | - govet | ||
| 9 | - errcheck | 10 | - errcheck | ||
| 10 | - staticcheck | 11 | - staticcheck | ||
| 11 | - unused | 12 | - unused | ||
| 12 | - | - gosimple | |||
| 13 | - ineffassign | 13 | - ineffassign | ||
| 14 | - | - typecheck | |||
| 15 | - misspell | 14 | - misspell | ||
| 16 | - gosec | 15 | - gosec | ||
| 17 | - unconvert | 16 | - unconvert | ||
| 18 | - gocyclo | 17 | - gocyclo | ||
| 18 | + | settings: | |||
| 19 | + | gocyclo: | |||
| 20 | + | min-complexity: 15 | |||
| 21 | + | exclusions: | |||
| 22 | + | rules: | |||
| 23 | + | - path: _test\.go | |||
| 24 | + | linters: | |||
| 25 | + | - gocyclo | |||
| 26 | + | - errcheck | |||
| 27 | + | - dupl | |||
| 28 | + | - gosec | |||
| 29 | + | - text: "Error return value of `.*Close` is not checked" | |||
| 30 | + | linters: | |||
| 31 | + | - errcheck | |||
| 32 | + | - text: "Error return value of `.*Write` is not checked" | |||
| 33 | + | linters: | |||
| 34 | + | - errcheck | |||
| 35 | + | - text: "Error return value of `os.Remove.*` is not checked" | |||
| 36 | + | linters: | |||
| 37 | + | - errcheck | |||
| 38 | + | - text: "Error return value of `.*Publish` is not checked" | |||
| 39 | + | linters: | |||
| 40 | + | - errcheck | |||
| 41 | + | - text: "Error return value of `.*Stop` is not checked" | |||
| 42 | + | linters: | |||
| 43 | + | - errcheck | |||
| 44 | + | - text: "Error return value of `.*RemoveContainer` is not checked" | |||
| 45 | + | linters: | |||
| 46 | + | - errcheck | |||
| 47 | + | - text: "Error return value of `log.WrapErr` is not checked" | |||
| 48 | + | linters: | |||
| 49 | + | - errcheck | |||
| 50 | + | - text: "Error return value of `log.WrapErrWithFields` is not checked" | |||
| 51 | + | linters: | |||
| 52 | + | - errcheck | |||
| 53 | + | # gosec: file operations with variables are intentional in storage layer | |||
| 54 | + | - text: "G304:" | |||
| 55 | + | linters: | |||
| 56 | + | - gosec | |||
| 57 | + | # gosec: G104 duplicates errcheck | |||
| 58 | + | - text: "G104:" | |||
| 59 | + | linters: | |||
| 60 | + | - gosec | |||
| 19 | 61 | ||||
| 20 | - | linters-settings: | 62 | + | formatters: |
| 21 | - | gocyclo: | 63 | + | enable: |
| 22 | - | min-complexity: 15 | 64 | + | - gofmt |
| 23 | 65 | ||||
| 24 | issues: | 66 | issues: | ||
| 25 | - | exclude-rules: | |||
| 26 | - | - path: _test\.go | |||
| 27 | - | linters: | |||
| 28 | - | - gocyclo | |||
| 29 | - | - errcheck | |||
| 30 | - | - dupl | |||
| 31 | - | - gosec | |||
| 32 | - | ||||
| 33 | max-same-issues: 50 | 67 | max-same-issues: 50 | ||
| 34 | 68 | ||||
| 35 | severity: | 69 | severity: | ||
M Makefile +72 -27
| @@ -21,13 +21,65 @@ LDFLAGS := -s -w \ | |||
| 21 | 21 | ARCHS := amd64 arm64 | |
| 22 | 22 | ||
| 23 | 23 | # Phony targets | |
| 24 | - | .PHONY: all build build-push clean dev-release test test-unit test-coverage test-race clean-test | |
| 24 | + | .PHONY: all build build-push clean dev-release \ | |
| 25 | + | test test-short test-race test-coverage \ | |
| 26 | + | lint fmt check mocks clean-test help | |
| 25 | 27 | ||
| 26 | 28 | # Default target | |
| 27 | 29 | all: build | |
| 28 | 30 | ||
| 29 | - | # Build binaries | |
| 30 | - | build: | |
| 31 | + | ##@ Development | |
| 32 | + | ||
| 33 | + | help: ## Show this help | |
| 34 | + | @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | |
| 35 | + | ||
| 36 | + | fmt: ## Format Go code | |
| 37 | + | @echo "Formatting Go code..." | |
| 38 | + | @go fmt ./... | |
| 39 | + | ||
| 40 | + | lint: ## Run golangci-lint | |
| 41 | + | @echo "Running linter..." | |
| 42 | + | @golangci-lint run ./... | |
| 43 | + | ||
| 44 | + | mocks: ## Generate mocks using mockery | |
| 45 | + | @echo "Generating mocks..." | |
| 46 | + | @mockery | |
| 47 | + | @echo "Mocks generated successfully" | |
| 48 | + | ||
| 49 | + | check: lint test ## Run lint and tests | |
| 50 | + | ||
| 51 | + | ##@ Testing | |
| 52 | + | ||
| 53 | + | test: ## Run all tests | |
| 54 | + | @echo "Running tests..." | |
| 55 | + | @go test ./... | |
| 56 | + | ||
| 57 | + | test-v: ## Run all tests with verbose output | |
| 58 | + | @go test -v ./... | |
| 59 | + | ||
| 60 | + | test-short: ## Run tests (skip long-running tests) | |
| 61 | + | @go test -short ./... | |
| 62 | + | ||
| 63 | + | test-race: ## Run tests with race detector | |
| 64 | + | @echo "Running tests with race detector..." | |
| 65 | + | @go test -race ./... | |
| 66 | + | ||
| 67 | + | test-coverage: ## Run tests with coverage report | |
| 68 | + | @echo "Running tests with coverage..." | |
| 69 | + | @go test -coverprofile=coverage.out ./... | |
| 70 | + | @go tool cover -func=coverage.out | |
| 71 | + | @go tool cover -html=coverage.out -o coverage.html | |
| 72 | + | @echo "Coverage report generated: coverage.html" | |
| 73 | + | ||
| 74 | + | test-usecase: ## Run usecase layer tests only | |
| 75 | + | @go test -v ./internal/usecase/... | |
| 76 | + | ||
| 77 | + | test-adapter: ## Run adapter layer tests only | |
| 78 | + | @go test -v ./internal/adapters/... | |
| 79 | + | ||
| 80 | + | ##@ Build | |
| 81 | + | ||
| 82 | + | build: ## Build binaries for linux (amd64 and arm64) | |
| 31 | 83 | @echo "Building Go binaries..." | |
| 32 | 84 | @mkdir -p $(DIST_DIR) | |
| 33 | 85 | @rm -f $(DIST_DIR)/* | |
| @@ -36,8 +88,14 @@ build: | |||
| 36 | 88 | @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-arm64 ./main.go | |
| 37 | 89 | @echo "Go binaries built successfully" | |
| 38 | 90 | ||
| 39 | - | # Build and push Docker images | |
| 40 | - | build-push: build | |
| 91 | + | build-local: ## Build binary for current platform | |
| 92 | + | @echo "Building for current platform..." | |
| 93 | + | @go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon ./main.go | |
| 94 | + | @echo "Binary built: $(DIST_DIR)/gordon" | |
| 95 | + | ||
| 96 | + | ##@ Release | |
| 97 | + | ||
| 98 | + | build-push: build ## Build and push Docker images | |
| 41 | 99 | @echo "Cleaning up dangling images..." | |
| 42 | 100 | @$(ENGINE) image prune -f | |
| 43 | 101 | ||
| @@ -69,8 +127,7 @@ build-push: build | |||
| 69 | 127 | ||
| 70 | 128 | @echo "Script completed successfully." | |
| 71 | 129 | ||
| 72 | - | # Create dev GitHub release (separate from GoReleaser) | |
| 73 | - | dev-release: build | |
| 130 | + | dev-release: build ## Create dev GitHub release | |
| 74 | 131 | @echo "Creating dev GitHub release..." | |
| 75 | 132 | @if [ -z "$(shell which gh)" ]; then \ | |
| 76 | 133 | echo "Error: GitHub CLI (gh) is not installed. Please install it first."; \ | |
| @@ -92,27 +149,15 @@ dev-release: build | |||
| 92 | 149 | @echo "" | |
| 93 | 150 | @echo "🔗 Release page: https://github.com/bnema/gordon/releases/tag/$(DEV_TAG)" | |
| 94 | 151 | ||
| 95 | - | # Test targets | |
| 96 | - | test: test-unit | |
| 97 | - | ||
| 98 | - | test-unit: | |
| 99 | - | go test -v ./... | |
| 100 | - | ||
| 101 | - | test-race: | |
| 102 | - | go test -race -v ./... | |
| 152 | + | ##@ Cleanup | |
| 103 | 153 | ||
| 104 | - | test-coverage: | |
| 105 | - | go test -coverprofile=coverage.out ./... | |
| 106 | - | go tool cover -html=coverage.out -o coverage.html | |
| 107 | - | @echo "Coverage report generated: coverage.html" | |
| 108 | - | ||
| 109 | - | ||
| 110 | - | clean-test: | |
| 111 | - | rm -f coverage.out coverage.html | |
| 112 | - | ||
| 113 | - | # Clean up | |
| 114 | - | clean: | |
| 154 | + | clean: ## Clean build artifacts | |
| 115 | 155 | @echo "Cleaning up..." | |
| 116 | 156 | @rm -rf $(DIST_DIR) | |
| 157 | + | @echo "Cleanup completed." | |
| 158 | + | ||
| 159 | + | clean-all: clean clean-test ## Clean all artifacts including test files | |
| 117 | 160 | @$(ENGINE) system prune -f | |
| 118 | - | @echo "Cleanup completed."⏎̸ | |
| 161 | + | ||
| 162 | + | clean-test: ## Clean test artifacts | |
| 163 | + | @rm -f coverage.out coverage.html⏎̸ | |
| @@ -21,13 +21,65 @@ LDFLAGS := -s -w \ | |||||
| 21 | ARCHS := amd64 arm64 | 21 | ARCHS := amd64 arm64 | ||
| 22 | 22 | ||||
| 23 | # Phony targets | 23 | # Phony targets | ||
| 24 | - | .PHONY: all build build-push clean dev-release test test-unit test-coverage test-race clean-test | 24 | + | .PHONY: all build build-push clean dev-release \ |
| 25 | + | test test-short test-race test-coverage \ | |||
| 26 | + | lint fmt check mocks clean-test help | |||
| 25 | 27 | ||||
| 26 | # Default target | 28 | # Default target | ||
| 27 | all: build | 29 | all: build | ||
| 28 | 30 | ||||
| 29 | - | # Build binaries | 31 | + | ##@ Development |
| 30 | - | build: | 32 | + | |
| 33 | + | help: ## Show this help | |||
| 34 | + | @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | |||
| 35 | + | ||||
| 36 | + | fmt: ## Format Go code | |||
| 37 | + | @echo "Formatting Go code..." | |||
| 38 | + | @go fmt ./... | |||
| 39 | + | ||||
| 40 | + | lint: ## Run golangci-lint | |||
| 41 | + | @echo "Running linter..." | |||
| 42 | + | @golangci-lint run ./... | |||
| 43 | + | ||||
| 44 | + | mocks: ## Generate mocks using mockery | |||
| 45 | + | @echo "Generating mocks..." | |||
| 46 | + | @mockery | |||
| 47 | + | @echo "Mocks generated successfully" | |||
| 48 | + | ||||
| 49 | + | check: lint test ## Run lint and tests | |||
| 50 | + | ||||
| 51 | + | ##@ Testing | |||
| 52 | + | ||||
| 53 | + | test: ## Run all tests | |||
| 54 | + | @echo "Running tests..." | |||
| 55 | + | @go test ./... | |||
| 56 | + | ||||
| 57 | + | test-v: ## Run all tests with verbose output | |||
| 58 | + | @go test -v ./... | |||
| 59 | + | ||||
| 60 | + | test-short: ## Run tests (skip long-running tests) | |||
| 61 | + | @go test -short ./... | |||
| 62 | + | ||||
| 63 | + | test-race: ## Run tests with race detector | |||
| 64 | + | @echo "Running tests with race detector..." | |||
| 65 | + | @go test -race ./... | |||
| 66 | + | ||||
| 67 | + | test-coverage: ## Run tests with coverage report | |||
| 68 | + | @echo "Running tests with coverage..." | |||
| 69 | + | @go test -coverprofile=coverage.out ./... | |||
| 70 | + | @go tool cover -func=coverage.out | |||
| 71 | + | @go tool cover -html=coverage.out -o coverage.html | |||
| 72 | + | @echo "Coverage report generated: coverage.html" | |||
| 73 | + | ||||
| 74 | + | test-usecase: ## Run usecase layer tests only | |||
| 75 | + | @go test -v ./internal/usecase/... | |||
| 76 | + | ||||
| 77 | + | test-adapter: ## Run adapter layer tests only | |||
| 78 | + | @go test -v ./internal/adapters/... | |||
| 79 | + | ||||
| 80 | + | ##@ Build | |||
| 81 | + | ||||
| 82 | + | build: ## Build binaries for linux (amd64 and arm64) | |||
| 31 | @echo "Building Go binaries..." | 83 | @echo "Building Go binaries..." | ||
| 32 | @mkdir -p $(DIST_DIR) | 84 | @mkdir -p $(DIST_DIR) | ||
| 33 | @rm -f $(DIST_DIR)/* | 85 | @rm -f $(DIST_DIR)/* | ||
| @@ -36,8 +88,14 @@ build: | |||||
| 36 | @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-arm64 ./main.go | 88 | @CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon-linux-arm64 ./main.go | ||
| 37 | @echo "Go binaries built successfully" | 89 | @echo "Go binaries built successfully" | ||
| 38 | 90 | ||||
| 39 | - | # Build and push Docker images | 91 | + | build-local: ## Build binary for current platform |
| 40 | - | build-push: build | 92 | + | @echo "Building for current platform..." |
| 93 | + | @go build -ldflags="$(LDFLAGS)" -o $(DIST_DIR)/gordon ./main.go | |||
| 94 | + | @echo "Binary built: $(DIST_DIR)/gordon" | |||
| 95 | + | ||||
| 96 | + | ##@ Release | |||
| 97 | + | ||||
| 98 | + | build-push: build ## Build and push Docker images | |||
| 41 | @echo "Cleaning up dangling images..." | 99 | @echo "Cleaning up dangling images..." | ||
| 42 | @$(ENGINE) image prune -f | 100 | @$(ENGINE) image prune -f | ||
| 43 | 101 | ||||
| @@ -69,8 +127,7 @@ build-push: build | |||||
| 69 | 127 | ||||
| 70 | @echo "Script completed successfully." | 128 | @echo "Script completed successfully." | ||
| 71 | 129 | ||||
| 72 | - | # Create dev GitHub release (separate from GoReleaser) | 130 | + | dev-release: build ## Create dev GitHub release |
| 73 | - | dev-release: build | |||
| 74 | @echo "Creating dev GitHub release..." | 131 | @echo "Creating dev GitHub release..." | ||
| 75 | @if [ -z "$(shell which gh)" ]; then \ | 132 | @if [ -z "$(shell which gh)" ]; then \ | ||
| 76 | echo "Error: GitHub CLI (gh) is not installed. Please install it first."; \ | 133 | echo "Error: GitHub CLI (gh) is not installed. Please install it first."; \ | ||
| @@ -92,27 +149,15 @@ dev-release: build | |||||
| 92 | @echo "" | 149 | @echo "" | ||
| 93 | @echo "🔗 Release page: https://github.com/bnema/gordon/releases/tag/$(DEV_TAG)" | 150 | @echo "🔗 Release page: https://github.com/bnema/gordon/releases/tag/$(DEV_TAG)" | ||
| 94 | 151 | ||||
| 95 | - | # Test targets | 152 | + | ##@ Cleanup |
| 96 | - | test: test-unit | |||
| 97 | - | ||||
| 98 | - | test-unit: | |||
| 99 | - | go test -v ./... | |||
| 100 | - | ||||
| 101 | - | test-race: | |||
| 102 | - | go test -race -v ./... | |||
| 103 | 153 | ||||
| 104 | - | test-coverage: | 154 | + | clean: ## Clean build artifacts |
| 105 | - | go test -coverprofile=coverage.out ./... | |||
| 106 | - | go tool cover -html=coverage.out -o coverage.html | |||
| 107 | - | @echo "Coverage report generated: coverage.html" | |||
| 108 | - | ||||
| 109 | - | ||||
| 110 | - | clean-test: | |||
| 111 | - | rm -f coverage.out coverage.html | |||
| 112 | - | ||||
| 113 | - | # Clean up | |||
| 114 | - | clean: | |||
| 115 | @echo "Cleaning up..." | 155 | @echo "Cleaning up..." | ||
| 116 | @rm -rf $(DIST_DIR) | 156 | @rm -rf $(DIST_DIR) | ||
| 157 | + | @echo "Cleanup completed." | |||
| 158 | + | ||||
| 159 | + | clean-all: clean clean-test ## Clean all artifacts including test files | |||
| 117 | @$(ENGINE) system prune -f | 160 | @$(ENGINE) system prune -f | ||
| 118 | - | @echo "Cleanup completed."⏎̸ | 161 | + | |
| 162 | + | clean-test: ## Clean test artifacts | |||
| 163 | + | @rm -f coverage.out coverage.html⏎̸ | |||