# ABOUTME: Makefile for forgejo-runner-resource-collector project. # ABOUTME: Provides targets for building, formatting, linting, and testing. BINARY_NAME := resource-collector CMD_PATH := ./cmd/collector GO := go GOLANGCI_LINT := $(GO) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.2 GITLEAKS := $(GO) run github.com/zricethezav/gitleaks/v8@v8.30.0 # Build flags LDFLAGS := -s -w BUILD_FLAGS := -ldflags "$(LDFLAGS)" default: run .PHONY: all build clean fmt format lint gitleaks test run help vet tidy install-hooks # Default target all: fmt vet lint build ## Build targets build: ## Build the binary $(GO) build $(BUILD_FLAGS) -o $(BINARY_NAME) $(CMD_PATH) clean: ## Remove build artifacts rm -f $(BINARY_NAME) coverage.out coverage.html $(GO) clean ## Code quality targets fmt: ## Format code using go fmt $(GO) fmt ./... format: fmt ## Alias for fmt vet: ## Run go vet $(GO) vet ./... lint: ## Run golangci-lint $(GOLANGCI_LINT) run ./... gitleaks: ## Check for secrets in git history $(GITLEAKS) git --staged gitleaks-all: ## Check for secrets in git history $(GITLEAKS) git . ## Dependency management tidy: ## Tidy go modules $(GO) mod tidy ## Testing targets test: ## Run tests $(GO) test -v ./... test-coverage: ## Run tests with coverage $(GO) test -v -coverprofile=coverage.out ./... $(GO) tool cover -html=coverage.out -o coverage.html ## Run targets run: build ## Build and run with default settings ./$(BINARY_NAME) run-text: build ## Build and run with text output format ./$(BINARY_NAME) --log-format text --interval 2s ## Git hooks install-hooks: ## Install git hooks cp scripts/hooks/pre-commit .git/hooks/pre-commit cp scripts/hooks/commit-msg .git/hooks/commit-msg chmod +x .git/hooks/pre-commit chmod +x .git/hooks/commit-msg @echo "Git hooks installed successfully" ## Help help: ## Show this help @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'