mirror of
https://github.com/ivuorinen/gh-action-readme.git
synced 2026-03-17 17:02:02 +00:00
refactor: major codebase improvements and test framework overhaul
This commit represents a comprehensive refactoring of the codebase focused on improving code quality, testability, and maintainability. Key improvements: - Implement dependency injection and interface-based architecture - Add comprehensive test framework with fixtures and test suites - Fix all linting issues (errcheck, gosec, staticcheck, goconst, etc.) - Achieve full EditorConfig compliance across all files - Replace hardcoded test data with proper fixture files - Add configuration loader with hierarchical config support - Improve error handling with contextual information - Add progress indicators for better user feedback - Enhance Makefile with help system and improved editorconfig commands - Consolidate constants and remove deprecated code - Strengthen validation logic for GitHub Actions - Add focused consumer interfaces for better separation of concerns Testing improvements: - Add comprehensive integration tests - Implement test executor pattern for better test organization - Create extensive YAML fixture library for testing - Fix all failing tests and improve test coverage - Add validation test fixtures to avoid embedded YAML in Go files Build and tooling: - Update Makefile to show help by default - Fix editorconfig commands to use eclint properly - Add comprehensive help documentation to all make targets - Improve file selection patterns to avoid glob errors This refactoring maintains backward compatibility while significantly improving the internal architecture and developer experience.
This commit is contained in:
85
Makefile
85
Makefile
@@ -1,84 +1,113 @@
|
||||
.PHONY: test lint run example clean readme config-verify security vulncheck audit snyk trivy gitleaks \
|
||||
.PHONY: help test lint run example clean readme config-verify security vulncheck audit snyk trivy gitleaks \
|
||||
editorconfig editorconfig-fix format
|
||||
|
||||
all: test lint
|
||||
all: help
|
||||
|
||||
test:
|
||||
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 test lint # Run tests and linting"
|
||||
@echo " make format # Format code and fix EditorConfig issues"
|
||||
@echo " make security # Run all security scans"
|
||||
|
||||
test: ## Run all tests
|
||||
go test ./...
|
||||
|
||||
lint: editorconfig
|
||||
lint: format ## Run linter (after formatting)
|
||||
golangci-lint run || true
|
||||
|
||||
config-verify:
|
||||
config-verify: ## Verify golangci-lint configuration
|
||||
golangci-lint config verify --verbose
|
||||
|
||||
run:
|
||||
run: ## Run the application
|
||||
go run .
|
||||
|
||||
example:
|
||||
example: ## Generate example README
|
||||
go run . gen --config config.yaml --output-format=md
|
||||
|
||||
readme:
|
||||
readme: ## Generate project README
|
||||
go run . gen --config config.yaml --output-format=md
|
||||
|
||||
clean:
|
||||
clean: ## Clean build artifacts
|
||||
rm -rf dist/
|
||||
|
||||
# Code formatting and EditorConfig targets
|
||||
format: editorconfig-fix
|
||||
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:
|
||||
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 key files for EditorConfig compliance..."
|
||||
eclint check Makefile .github/workflows/*.yml main.go internal/**/*.go *.md .goreleaser.yaml
|
||||
@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 "*.tmpl" -o \
|
||||
-name "*.adoc" -o \
|
||||
-name "*.sh" \
|
||||
\) -not -path "./.*" -not -path "./gh-action-readme" -not -path "./coverage*" \
|
||||
-not -path "./testutil.test" -not -path "./test_*" | \
|
||||
xargs eclint check
|
||||
|
||||
editorconfig-fix:
|
||||
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 key files for EditorConfig compliance..."
|
||||
eclint fix Makefile .github/workflows/*.yml main.go internal/**/*.go *.md .goreleaser.yaml
|
||||
|
||||
editorconfig-check:
|
||||
@echo "Running editorconfig-checker..."
|
||||
@command -v editorconfig-checker >/dev/null 2>&1 || \
|
||||
{ echo "Please install editorconfig-checker: npm install -g editorconfig-checker"; exit 1; }
|
||||
editorconfig-checker
|
||||
@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 "*.tmpl" -o \
|
||||
-name "*.adoc" -o \
|
||||
-name "*.sh" \
|
||||
\) -not -path "./.*" -not -path "./gh-action-readme" -not -path "./coverage*" \
|
||||
-not -path "./testutil.test" -not -path "./test_*" | \
|
||||
xargs eclint fix
|
||||
|
||||
# Security targets
|
||||
security: vulncheck snyk trivy gitleaks
|
||||
security: vulncheck snyk trivy gitleaks ## Run all security scans
|
||||
@echo "All security scans completed"
|
||||
|
||||
vulncheck:
|
||||
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: vulncheck
|
||||
audit: vulncheck ## Run comprehensive security audit
|
||||
@echo "Running comprehensive security audit..."
|
||||
go list -json -deps ./... | jq -r '.Module | select(.Path != null) | .Path + "@" + .Version' | sort -u
|
||||
|
||||
snyk:
|
||||
snyk: ## Run Snyk security scan
|
||||
@echo "Running Snyk security scan..."
|
||||
@command -v snyk >/dev/null 2>&1 || \
|
||||
{ echo "Please install Snyk CLI: npm install -g snyk"; exit 1; }
|
||||
snyk test --file=go.mod --package-manager=gomodules
|
||||
|
||||
trivy:
|
||||
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:
|
||||
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; }
|
||||
|
||||
Reference in New Issue
Block a user