mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-02-09 00:47:23 +00:00
chore: even more linting, test fixes (#24)
* chore(lint): funcorder * chore(lint): yamlfmt, ignored broken test yaml files * chore(tests): tests do not output garbage, add coverage * chore(lint): fix editorconfig violations * chore(lint): move from eclint to editorconfig-checker * chore(lint): add pre-commit, run and fix * chore(ci): we use renovate to manage updates
This commit is contained in:
156
Makefile
156
Makefile
@@ -1,5 +1,6 @@
|
||||
.PHONY: help test lint run example clean readme config-verify security vulncheck audit snyk trivy gitleaks \
|
||||
editorconfig editorconfig-fix format
|
||||
.PHONY: help test test-coverage test-coverage-html lint build run example \
|
||||
clean readme config-verify security vulncheck audit snyk trivy gitleaks \
|
||||
editorconfig editorconfig-fix format devtools pre-commit-install pre-commit-update
|
||||
|
||||
all: help
|
||||
|
||||
@@ -10,18 +11,66 @@ help: ## Show this help message
|
||||
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||
@echo ""
|
||||
@echo "Common workflows:"
|
||||
@echo " make test lint # Run tests and linting"
|
||||
@echo " make format # Format code and fix EditorConfig issues"
|
||||
@echo " make security # Run all security scans"
|
||||
@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 security # Run all security scans"
|
||||
|
||||
test: ## Run all tests
|
||||
go test ./...
|
||||
|
||||
lint: format ## Run linter (after formatting)
|
||||
golangci-lint run \
|
||||
--max-issues-per-linter 100 \
|
||||
--max-same-issues 50 \
|
||||
--output.tab.path stdout || true
|
||||
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
|
||||
|
||||
lint: ## 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-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
|
||||
@@ -37,6 +86,7 @@ readme: ## Generate project README
|
||||
|
||||
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
|
||||
@@ -48,43 +98,59 @@ format: editorconfig-fix ## Format code and fix EditorConfig issues
|
||||
|
||||
editorconfig: ## Check EditorConfig compliance
|
||||
@echo "Checking EditorConfig compliance..."
|
||||
@command -v eclint >/dev/null 2>&1 || \
|
||||
{ echo "Please install eclint: npm install -g eclint"; exit 1; }
|
||||
@echo "Checking files for EditorConfig compliance..."
|
||||
@find . -type f \( \
|
||||
-name "*.go" -o \
|
||||
-name "*.yml" -o \
|
||||
-name "*.yaml" -o \
|
||||
-name "*.json" -o \
|
||||
-name "*.md" -o \
|
||||
-name "Makefile" -o \
|
||||
-name ".snyk" -o \
|
||||
-name "*.tmpl" -o \
|
||||
-name "*.adoc" -o \
|
||||
-name "*.sh" \
|
||||
\) -not -path "./gh-action-readme" -not -path "./coverage*" \
|
||||
-not -path "./testutil.test" -not -path "./test_*" | \
|
||||
xargs eclint check
|
||||
@command -v editorconfig-checker >/dev/null 2>&1 || \
|
||||
{ echo "Please install editorconfig-checker or run 'make devtools'"; exit 1; }
|
||||
editorconfig-checker
|
||||
|
||||
editorconfig-fix: ## Fix EditorConfig violations
|
||||
@echo "Fixing EditorConfig violations..."
|
||||
@command -v eclint >/dev/null 2>&1 || \
|
||||
{ echo "Please install eclint: npm install -g eclint"; exit 1; }
|
||||
@echo "Fixing files for EditorConfig compliance..."
|
||||
@find . -type f \( \
|
||||
-name "*.go" -o \
|
||||
-name "*.yml" -o \
|
||||
-name "*.yaml" -o \
|
||||
-name "*.json" -o \
|
||||
-name "*.md" -o \
|
||||
-name "Makefile" -o \
|
||||
-name ".snyk" -o \
|
||||
-name "*.tmpl" -o \
|
||||
-name "*.adoc" -o \
|
||||
-name "*.sh" \
|
||||
\) -not -path "./gh-action-readme" -not -path "./coverage*" \
|
||||
-not -path "./testutil.test" -not -path "./test_*" | \
|
||||
xargs eclint fix
|
||||
@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; }
|
||||
@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; }
|
||||
@command -v snyk >/dev/null 2>&1 || \
|
||||
{ echo "Installing snyk..."; npm install -g snyk; }
|
||||
@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 snyk trivy gitleaks ## Run all security scans
|
||||
|
||||
Reference in New Issue
Block a user