mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-03-11 05:59:35 +00:00
280 lines
12 KiB
Makefile
280 lines
12 KiB
Makefile
.PHONY: help test test-quick test-coverage test-coverage-html test-coverage-check \
|
|
test-mutation test-mutation-parser test-mutation-validation \
|
|
test-property test-property-validation test-property-parser \
|
|
lint build run example clean readme config-verify security vulncheck audit trivy gitleaks \
|
|
editorconfig editorconfig-fix format devtools pre-commit-install pre-commit-update \
|
|
deps-check deps-update deps-update-all
|
|
|
|
all: help
|
|
|
|
# Coverage threshold (align with SonarCloud)
|
|
# Note: SonarCloud checks NEW code coverage (≥80%), this checks overall coverage
|
|
# Current overall coverage: 72.9% - working towards 80% target
|
|
COVERAGE_THRESHOLD := 72.0
|
|
|
|
help: ## Show this help message
|
|
@echo "GitHub Action README Generator - Available Make Targets:"
|
|
@echo ""
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
|
|
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
|
@echo ""
|
|
@echo "Common workflows:"
|
|
@echo " make devtools # Install all development tools"
|
|
@echo " make pre-commit-install # Install pre-commit hooks (run once)"
|
|
@echo " make build # Build the application binary"
|
|
@echo " make test lint # Run tests and all linters via pre-commit"
|
|
@echo " make test-coverage # Run tests with coverage analysis"
|
|
@echo " make pre-commit-update # Update pre-commit hooks to latest versions"
|
|
@echo " make deps-check # Check for outdated dependencies"
|
|
@echo " make deps-update # Update dependencies interactively"
|
|
@echo " make security # Run all security scans"
|
|
|
|
test: ## Run all tests (standard and property-based)
|
|
@echo "Running standard tests..."
|
|
@go test ./...
|
|
@echo ""
|
|
@echo "Running property-based tests..."
|
|
@$(MAKE) test-property
|
|
@echo ""
|
|
@echo "✅ All tests (standard + property) completed successfully!"
|
|
@echo ""
|
|
@echo "Note: Mutation tests require go-mutesting (compatible with Go 1.22/1.23 only)."
|
|
@echo " Run 'make test-mutation' if you have a compatible Go version."
|
|
@echo " Run 'make test-quick' for fast iteration (unit tests only)."
|
|
|
|
test-quick: ## Run only standard unit tests (fast)
|
|
go test ./...
|
|
|
|
test-coverage: ## Run tests with coverage and display in CLI
|
|
@echo "Running tests with coverage analysis..."
|
|
@go test ./... -coverprofile=coverage.out -covermode=atomic
|
|
@echo ""
|
|
@echo "=== Coverage Summary ==="
|
|
@go tool cover -func=coverage.out | tail -1
|
|
@echo ""
|
|
@echo "=== Package Coverage Details ==="
|
|
@go tool cover -func=coverage.out | grep -v "total:" | \
|
|
awk '{printf "%-50s %s\n", $$1, $$3}' | \
|
|
sort -k2 -nr
|
|
@echo ""
|
|
@echo "Coverage report saved to: coverage.out"
|
|
@echo "Run 'make test-coverage-html' to generate HTML report"
|
|
|
|
test-coverage-html: test-coverage ## Generate HTML coverage report and open in browser
|
|
@echo "Generating HTML coverage report..."
|
|
@go tool cover -html=coverage.out -o coverage.html
|
|
@echo "HTML coverage report generated: coverage.html"
|
|
@if command -v open >/dev/null 2>&1; then \
|
|
echo "Opening coverage report in browser..."; \
|
|
open coverage.html; \
|
|
elif command -v xdg-open >/dev/null 2>&1; then \
|
|
echo "Opening coverage report in browser..."; \
|
|
xdg-open coverage.html; \
|
|
else \
|
|
echo "Open coverage.html in your browser to view detailed coverage"; \
|
|
fi
|
|
|
|
test-coverage-check: ## Run tests with coverage check (overall >= 72%)
|
|
@command -v bc >/dev/null 2>&1 || { \
|
|
echo "❌ bc command not found. Please install bc (e.g., apt-get install bc, brew install bc)"; \
|
|
exit 1; \
|
|
}
|
|
@echo "Running tests with coverage check..."
|
|
@go test -cover -coverprofile=coverage.out ./...
|
|
@total=$$(go tool cover -func=coverage.out | grep total | awk '{print $$3}' | sed 's/%//'); \
|
|
if [ $$(echo "$$total < $(COVERAGE_THRESHOLD)" | bc) -eq 1 ]; then \
|
|
echo "❌ Coverage $$total% is below threshold $(COVERAGE_THRESHOLD)%"; \
|
|
exit 1; \
|
|
else \
|
|
echo "✅ Coverage $$total% meets threshold $(COVERAGE_THRESHOLD)%"; \
|
|
fi
|
|
|
|
.PHONY: test-mutation test-mutation-parser test-mutation-validation
|
|
|
|
test-mutation: test-mutation-parser test-mutation-validation ## Run all mutation tests
|
|
|
|
test-mutation-parser: ## Run mutation tests on parser (permission parsing)
|
|
@echo "Running mutation tests on parser..."
|
|
@command -v go-mutesting >/dev/null 2>&1 || { \
|
|
echo "❌ go-mutesting not found. Installing..."; \
|
|
go install github.com/zimmski/go-mutesting/cmd/go-mutesting@latest; \
|
|
}
|
|
@go-mutesting --do-not-remove internal/parser.go -- \
|
|
go test -v ./internal -run "TestParse.*Permissions|TestMerge.*Permissions|TestProcess.*Permission"
|
|
|
|
test-mutation-validation: ## Run mutation tests on validation (version and strings)
|
|
@echo "Running mutation tests on validation..."
|
|
@command -v go-mutesting >/dev/null 2>&1 || { \
|
|
echo "❌ go-mutesting not found. Installing..."; \
|
|
go install github.com/zimmski/go-mutesting/cmd/go-mutesting@latest; \
|
|
}
|
|
@echo "Testing version validation..."
|
|
@go-mutesting --do-not-remove internal/validation/validation.go -- \
|
|
go test -v ./internal/validation -run "TestIsCommitSHA|TestIsSemanticVersion|TestIsVersionPinned"
|
|
@echo ""
|
|
@echo "Testing string validation..."
|
|
@go-mutesting --do-not-remove internal/validation/strings.go -- \
|
|
go test -v ./internal/validation -run "TestParseGitHubURL|TestSanitize|TestFormat|TestClean"
|
|
|
|
.PHONY: test-property test-property-validation test-property-parser
|
|
|
|
test-property: test-property-validation test-property-parser ## Run all property-based tests
|
|
|
|
test-property-validation: ## Run property tests on validation (strings)
|
|
@echo "Running property tests on validation..."
|
|
@go test -v ./internal/validation -run ".*Properties" -timeout 30s
|
|
|
|
test-property-parser: ## Run property tests on parser (permission merging)
|
|
@echo "Running property tests on parser..."
|
|
@go test -v ./internal -run ".*Properties" -timeout 30s
|
|
|
|
lint: editorconfig ## Run all linters via pre-commit
|
|
@echo "Running all linters via pre-commit..."
|
|
@command -v pre-commit >/dev/null 2>&1 || \
|
|
{ echo "Please install pre-commit or run 'make devtools'"; exit 1; }
|
|
pre-commit run --all-files
|
|
|
|
pre-commit-install: ## Install pre-commit hooks
|
|
@echo "Installing pre-commit hooks..."
|
|
@command -v pre-commit >/dev/null 2>&1 || \
|
|
{ echo "Please install pre-commit or run 'make devtools'"; exit 1; }
|
|
pre-commit install
|
|
pre-commit install --hook-type commit-msg
|
|
|
|
pre-commit-update: ## Update pre-commit hooks to latest versions
|
|
@echo "Updating pre-commit hooks..."
|
|
@command -v pre-commit >/dev/null 2>&1 || \
|
|
{ echo "Please install pre-commit or run 'make devtools'"; exit 1; }
|
|
pre-commit autoupdate
|
|
|
|
build: ## Build the application
|
|
go build -o gh-action-readme .
|
|
|
|
config-verify: ## Verify golangci-lint configuration
|
|
golangci-lint config verify --verbose
|
|
|
|
run: ## Run the application
|
|
go run .
|
|
|
|
example: ## Generate example README
|
|
go run . gen --config config.yml --output-format=md
|
|
|
|
readme: ## Generate project README
|
|
go run . gen --config config.yml --output-format=md
|
|
|
|
clean: ## Clean build artifacts
|
|
rm -rf dist/
|
|
rm -f gh-action-readme coverage.out coverage.html
|
|
|
|
# Code formatting and EditorConfig targets
|
|
format: editorconfig-fix ## Format code and fix EditorConfig issues
|
|
@echo "Running all formatters..."
|
|
@command -v gofmt >/dev/null 2>&1 && gofmt -w -s . || echo "gofmt not available"
|
|
@command -v goimports >/dev/null 2>&1 && \
|
|
goimports -w -local github.com/ivuorinen/gh-action-readme . || \
|
|
echo "goimports not available"
|
|
|
|
editorconfig: ## Check EditorConfig compliance
|
|
@echo "Checking EditorConfig compliance..."
|
|
@command -v editorconfig-checker >/dev/null 2>&1 || \
|
|
{ echo "Please install editorconfig-checker or run 'make devtools'"; exit 1; }
|
|
editorconfig-checker || true
|
|
|
|
editorconfig-fix: ## Fix EditorConfig violations
|
|
@echo "EditorConfig violations cannot be automatically fixed by editorconfig-checker"
|
|
@echo "Please fix the reported issues manually or use your editor's EditorConfig plugin"
|
|
@echo "Running check to show issues..."
|
|
@command -v editorconfig-checker >/dev/null 2>&1 || \
|
|
{ echo "Please install editorconfig-checker or run 'make devtools'"; exit 1; }
|
|
editorconfig-checker
|
|
|
|
# Development tools installation
|
|
devtools: ## Install all development tools
|
|
@echo "Installing development tools..."
|
|
@echo ""
|
|
@echo "=== Go Tools ==="
|
|
@command -v golangci-lint >/dev/null 2>&1 || \
|
|
{ echo "Installing golangci-lint..."; \
|
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
|
|
sh -s -- -b $(go env GOPATH)/bin; }
|
|
@command -v govulncheck >/dev/null 2>&1 || \
|
|
{ echo "Installing govulncheck..."; go install golang.org/x/vuln/cmd/govulncheck@latest; }
|
|
@command -v editorconfig-checker >/dev/null 2>&1 || \
|
|
{ echo "Installing editorconfig-checker..."; \
|
|
go install github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@latest; }
|
|
@command -v yamlfmt >/dev/null 2>&1 || \
|
|
{ echo "Installing yamlfmt..."; go install github.com/google/yamlfmt/cmd/yamlfmt@latest; }
|
|
@command -v go-mod-upgrade >/dev/null 2>&1 || \
|
|
{ echo "Installing go-mod-upgrade..."; \
|
|
go install github.com/oligot/go-mod-upgrade@latest; }
|
|
@echo "✓ Go tools installed"
|
|
@echo ""
|
|
@echo "=== Node.js Tools ==="
|
|
@command -v npm >/dev/null 2>&1 || \
|
|
{ echo "❌ npm not found. Please install Node.js first."; exit 1; }
|
|
@echo "✓ Node.js tools installed"
|
|
@echo ""
|
|
@echo "=== Python Tools ==="
|
|
@command -v python3 >/dev/null 2>&1 || \
|
|
{ echo "❌ python3 not found. Please install Python 3 first."; exit 1; }
|
|
@command -v pre-commit >/dev/null 2>&1 || \
|
|
{ echo "Installing pre-commit..."; pip install pre-commit; }
|
|
@echo "✓ Python tools installed"
|
|
@echo ""
|
|
@echo "=== System Tools ==="
|
|
@command -v trivy >/dev/null 2>&1 || \
|
|
{ echo "❌ trivy not found. Please install manually: https://aquasecurity.github.io/trivy/"; }
|
|
@command -v gitleaks >/dev/null 2>&1 || \
|
|
{ echo "❌ gitleaks not found. Please install manually: https://github.com/gitleaks/gitleaks"; }
|
|
@echo "✓ System tools check completed"
|
|
@echo ""
|
|
@echo "🎉 Development tools installation completed!"
|
|
@echo " Run 'make test lint' to verify everything works."
|
|
|
|
# Security targets
|
|
security: vulncheck trivy gitleaks ## Run all security scans
|
|
@echo "All security scans completed"
|
|
|
|
vulncheck: ## Run Go vulnerability check
|
|
@echo "Running Go vulnerability check..."
|
|
@command -v govulncheck >/dev/null 2>&1 || \
|
|
{ echo "Installing govulncheck..."; go install golang.org/x/vuln/cmd/govulncheck@latest; }
|
|
govulncheck ./...
|
|
|
|
audit: trivy gitleaks vulncheck ## Run comprehensive security audit
|
|
@echo "Running comprehensive security audit..."
|
|
go list -json -deps ./... | jq -r '.Module | select(.Path != null) | .Path + "@" + .Version' | sort -u
|
|
|
|
|
|
trivy: ## Run Trivy filesystem scan
|
|
@echo "Running Trivy filesystem scan..."
|
|
@command -v trivy >/dev/null 2>&1 || \
|
|
{ echo "Please install Trivy: https://aquasecurity.github.io/trivy/"; exit 1; }
|
|
trivy fs . --severity HIGH,CRITICAL
|
|
|
|
gitleaks: ## Run gitleaks secrets detection
|
|
@echo "Running gitleaks secrets detection..."
|
|
@command -v gitleaks >/dev/null 2>&1 || \
|
|
{ echo "Please install gitleaks: https://github.com/gitleaks/gitleaks"; exit 1; }
|
|
gitleaks detect --source . --verbose
|
|
|
|
# Dependency management targets
|
|
deps-check: ## Show outdated dependencies
|
|
@echo "Checking for outdated dependencies..."
|
|
@go list -u -m all | grep -v "^go: finding"
|
|
|
|
deps-update: ## Update dependencies interactively
|
|
@echo "Starting interactive dependency update..."
|
|
@command -v go-mod-upgrade >/dev/null 2>&1 || \
|
|
{ echo "Please install go-mod-upgrade or run 'make devtools'"; exit 1; }
|
|
go-mod-upgrade
|
|
@echo "Running go mod tidy..."
|
|
go mod tidy
|
|
|
|
deps-update-all: ## Update all dependencies to latest versions
|
|
@echo "Updating all dependencies to latest versions..."
|
|
@go get -u ./...
|
|
@echo "Running go mod tidy..."
|
|
go mod tidy
|
|
@echo "All dependencies updated"
|