Skip to content

Commit a54ec29

Browse files
committed
feat(build): implement modular Makefile architecture with comprehensive documentation
- Restructure Makefile system following SOLID principles and DRY methodology - Organize build system into semantic modules by responsibility: * core/: Shared variables and reusable functions * local/: Setup, QA, and development helpers * docker/: Containerized execution and Docker Compose management * pipeline/: CI/CD orchestration workflows - Add complete modular documentation suite: * MAKEFILE.md: Overview and quick start guide * MAKEFILE-setup.md: Dependency management and installation * MAKEFILE-qa.md: Testing, linting, and static analysis * MAKEFILE-pipeline.md: CI/CD pipelines and pre-commit hooks * MAKEFILE-helpers.md: Benchmarking and release management * MAKEFILE-docker.md: Docker commands and isolated execution * MAKEFILE-compose.md: Full-stack Docker Compose environment - Implement new capabilities: * Unified benchmark interface with baseline comparison (make bench) * Docker Compose lifecycle management (make up/down/restart) * Git hooks automation (make git-hooks-setup) * Modular CI/CD pipelines (make ci/ci-full/cd) - Maintain backward compatibility with all existing make targets - Each module follows single responsibility principle - Comprehensive troubleshooting guides and best practices included Refs: #documentation #architecture #devex
1 parent de7a747 commit a54ec29

19 files changed

Lines changed: 7551 additions & 316 deletions

.docs/MAKEFILE-compose.md

Lines changed: 1046 additions & 0 deletions
Large diffs are not rendered by default.

.docs/MAKEFILE-docker.md

Lines changed: 816 additions & 0 deletions
Large diffs are not rendered by default.

.docs/MAKEFILE-helpers.md

Lines changed: 1016 additions & 0 deletions
Large diffs are not rendered by default.

.docs/MAKEFILE-pipeline.md

Lines changed: 949 additions & 0 deletions
Large diffs are not rendered by default.

.docs/MAKEFILE-qa.md

Lines changed: 1279 additions & 0 deletions
Large diffs are not rendered by default.

.docs/MAKEFILE-setup.md

Lines changed: 1006 additions & 0 deletions
Large diffs are not rendered by default.

.docs/MAKEFILE.md

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
<div align="center">
2+
3+
# KaririCode DevKit
4+
5+
[![PHP Version](https://img.shields.io/badge/PHP-8.4%2B-777BB4?style=for-the-badge&logo=php)](https://www.php.net)
6+
[![Docker](https://img.shields.io/badge/Docker-Ready-2496ED?style=for-the-badge&logo=docker)](https://www.docker.com)
7+
[![Make](https://img.shields.io/badge/Make-Automation-6D00CC?style=for-the-badge&logo=gnu)](https://www.gnu.org/software/make/)
8+
[![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge)](LICENSE)
9+
10+
**Professional development environment for KaririCode Framework components**
11+
12+
[Website](https://kariricode.org) | [Documentation](https://kariricode.org/docs) | [GitHub](https://github.com/KaririCode-Framework/kariricode-devkit)
13+
14+
</div>
15+
16+
---
17+
18+
## 📚 Documentation Index
19+
20+
| Document | Scope | Makefile Modules |
21+
|----------|-------|------------------|
22+
| **[Setup & Installation](MAKEFILE-setup.md)** | Dependency management, environment setup | `Makefile.setup.mk` |
23+
| **[Quality Assurance](MAKEFILE-qa.md)** | Testing, linting, static analysis | `Makefile.qa.mk` |
24+
| **[CI/CD Pipelines](MAKEFILE-pipeline.md)** | Orchestrated workflows, pre-commit hooks | `Makefile.orchestration.mk` |
25+
| **[Development Helpers](MAKEFILE-helpers.md)** | Benchmarks, git hooks, release management | `Makefile.helpers.mk` |
26+
| **[Docker Commands](MAKEFILE-docker.md)** | Docker execution, isolated environments | `Makefile.docker-*.mk` |
27+
| **[Docker Compose](MAKEFILE-compose.md)** | Full stack environment management | `Makefile.docker-compose.mk` |
28+
29+
---
30+
31+
## 🚀 Quick Start
32+
33+
### First Time Setup
34+
```bash
35+
# 1. Check prerequisites
36+
make check-php # Verify PHP 8.4+
37+
38+
# 2. Install dependencies
39+
make install # Production dependencies
40+
make install-dev # + Development tools
41+
42+
# 3. Verify installation
43+
make info # Show environment info
44+
```
45+
46+
### Daily Development Workflow
47+
```bash
48+
# Local development
49+
make format # Auto-fix code style
50+
make test # Run tests
51+
make analyse # Static analysis
52+
53+
# Docker environment
54+
make up # Start services
55+
make test-compose # Integration tests
56+
make down # Stop services
57+
```
58+
59+
### CI/CD Integration
60+
```bash
61+
# Fast CI (1-2 min)
62+
make ci # Essential checks
63+
64+
# Full CI (3-5 min)
65+
make ci-full # Complete validation
66+
67+
# Docker CI (isolated)
68+
make docker-ci # Consistent environment
69+
```
70+
71+
---
72+
73+
## 📖 Architecture Overview
74+
75+
### Module Organization
76+
```
77+
.make/
78+
├── core/ # 🔧 Shared infrastructure
79+
│ ├── Makefile.variables.mk # Colors, paths, tools
80+
│ └── Makefile.functions.mk # Reusable shell functions
81+
82+
├── local/ # 💻 Local development
83+
│ ├── Makefile.setup.mk # Install, update, clean
84+
│ ├── Makefile.qa.mk # Test, lint, analyse
85+
│ └── Makefile.helpers.mk # Bench, hooks, stats
86+
87+
├── pipeline/ # 🔄 CI/CD workflows
88+
│ └── Makefile.orchestration.mk # Composed pipelines
89+
90+
└── docker/ # 🐳 Docker execution
91+
├── Makefile.docker-core.mk # Shell, composer, php
92+
├── Makefile.docker-compose.mk # Service lifecycle
93+
├── Makefile.docker-qa.mk # QA in containers
94+
├── Makefile.docker-image.mk # Image management
95+
└── Makefile.docker-tools.mk # Utilities
96+
```
97+
98+
### Design Principles
99+
100+
**Single Responsibility Principle (SRP)**
101+
- Each `.mk` file has one clear purpose
102+
- Setup ≠ QA ≠ Docker ≠ Pipeline
103+
104+
**DRY (Don't Repeat Yourself)**
105+
- Shared logic in `core/Makefile.functions.mk`
106+
- Variables centralized in `core/Makefile.variables.mk`
107+
108+
**Composability**
109+
- Complex workflows built from simple targets
110+
- `make ci` = lint + analyse + test
111+
- `make cd` = ci-full + bench + release prep
112+
113+
**Flexibility**
114+
- Local execution: `make test`
115+
- Docker execution: `make docker-test`
116+
- Same interface, different environment
117+
118+
---
119+
120+
## 🎯 Command Categories
121+
122+
### By Frequency
123+
124+
**Every Commit**
125+
```bash
126+
make format # Auto-fix style
127+
make lint # Syntax check
128+
make test-unit # Fast tests
129+
```
130+
131+
**Before Push**
132+
```bash
133+
make ci # Full local CI
134+
make analyse # Deep static analysis
135+
```
136+
137+
**Weekly**
138+
```bash
139+
make update # Update dependencies
140+
make security # Security audit
141+
make outdated # Check for updates
142+
```
143+
144+
**Release**
145+
```bash
146+
make cd # Complete validation
147+
make tag VERSION=X.Y.Z # Create tag
148+
```
149+
150+
### By Environment
151+
152+
**Local Machine**
153+
- Fast iteration
154+
- IDE integration
155+
- Custom configuration
156+
157+
**Docker Container**
158+
- Isolated environment
159+
- Consistent results
160+
- CI/CD simulation
161+
162+
**Docker Compose**
163+
- Full stack (PHP + Redis + Memcached)
164+
- Integration tests
165+
- Service dependencies
166+
167+
---
168+
169+
## 📋 Command Reference
170+
171+
### Essential Commands
172+
```bash
173+
# Help
174+
make help # Show all commands
175+
make <module>-help # Module-specific help
176+
177+
# Setup
178+
make install # Install dependencies
179+
make clean # Clean artifacts
180+
make verify-install # Verify setup
181+
182+
# Quality
183+
make test # Run tests
184+
make analyse # Static analysis
185+
make format # Auto-fix code
186+
187+
# Pipelines
188+
make ci # Fast CI
189+
make ci-full # Complete CI
190+
make pre-commit # Quick checks
191+
192+
# Docker
193+
make docker-ci # CI in Docker
194+
make up # Start compose
195+
make down # Stop compose
196+
```
197+
198+
### Getting Help
199+
```bash
200+
# General help
201+
make help
202+
203+
# Module-specific
204+
make bench-help # Benchmark parameters
205+
206+
# Debug
207+
make info # Environment info
208+
make debug-composer # Composer config
209+
make env-check # Docker env vars
210+
```
211+
212+
---
213+
214+
## 🔍 Troubleshooting
215+
216+
### Quick Diagnostics
217+
```bash
218+
# Check environment
219+
make info # PHP, Composer, tools
220+
make check-php # PHP version check
221+
222+
# Verify installation
223+
make verify-install # Check dependencies
224+
225+
# Docker issues
226+
make docker-info # Docker environment
227+
make validate-compose # docker-compose.yml syntax
228+
make logs # Service logs
229+
```
230+
231+
### Common Issues
232+
233+
| Issue | Quick Fix | Documentation |
234+
|-------|-----------|---------------|
235+
| Tests not executing | `export XDEBUG_MODE=off` | [MAKEFILE-qa.md](MAKEFILE-qa.md#troubleshooting) |
236+
| Port conflicts | Edit `.env`, change `APP_PORT` | [MAKEFILE-compose.md](MAKEFILE-compose.md#port-conflicts) |
237+
| Composer errors | `make debug-composer` | [MAKEFILE-setup.md](MAKEFILE-setup.md#troubleshooting) |
238+
| PHPStan errors | `make phpstan-baseline` | [MAKEFILE-qa.md](MAKEFILE-qa.md#static-analysis) |
239+
240+
---
241+
242+
## 🎓 Learning Path
243+
244+
### Beginner (Day 1)
245+
246+
1. Read: [Setup & Installation](MAKEFILE-setup.md)
247+
2. Run: `make install && make info`
248+
3. Test: `make test`
249+
250+
### Intermediate (Week 1)
251+
252+
1. Read: [Quality Assurance](MAKEFILE-qa.md)
253+
2. Setup: `make git-hooks-setup`
254+
3. Practice: `make pre-commit` workflow
255+
256+
### Advanced (Month 1)
257+
258+
1. Read: [Docker Compose](MAKEFILE-compose.md)
259+
2. Setup: `make up`
260+
3. Integrate: `make test-compose`
261+
262+
### Expert (Month 3)
263+
264+
1. Read: [CI/CD Pipelines](MAKEFILE-pipeline.md)
265+
2. Customize: Add project-specific targets
266+
3. Optimize: Benchmark and tune
267+
268+
---
269+
270+
## 🤝 Contributing
271+
272+
### Adding New Targets
273+
274+
1. **Choose the right module**
275+
- Setup related? → `Makefile.setup.mk`
276+
- Testing related? → `Makefile.qa.mk`
277+
- Docker related? → `Makefile.docker-*.mk`
278+
279+
2. **Follow conventions**
280+
```makefile
281+
target-name: ## Description for help
282+
@echo "$(BLUE)→ Action...$(RESET)"
283+
# implementation
284+
@echo "$(GREEN)✓ Success$(RESET)"
285+
```
286+
287+
3. **Document in corresponding .md file**
288+
289+
4. **Test locally and in Docker**
290+
```bash
291+
make target-name
292+
make docker-<target-name> # if applicable
293+
```
294+
295+
### Documentation Standards
296+
297+
- Use **semantic organization**
298+
- Include **working examples**
299+
- Add **troubleshooting sections**
300+
- Maintain **consistent formatting**
301+
- Update **command reference tables**
302+
303+
---
304+
305+
## 📞 Support
306+
307+
### Resources
308+
309+
- **Issues**: Found a bug? [Open an issue](https://github.com/KaririCode-Framework/kariricode-devkit/issues)
310+
- **Discussions**: Questions? [Start a discussion](https://github.com/KaririCode-Framework/kariricode-devkit/discussions)
311+
- **Documentation**: [Full documentation index](#-documentation-index)
312+
313+
### Quick Links
314+
315+
- [Prerequisites](MAKEFILE-setup.md#prerequisites)
316+
- [Installation Guide](MAKEFILE-setup.md#installation)
317+
- [Command Reference](#-command-reference)
318+
- [Troubleshooting](#-troubleshooting)
319+
- [Best Practices](MAKEFILE-pipeline.md#best-practices)
320+
321+
---
322+
323+
**Version**: 1.0.0
324+
**Maintainer**: Walmir Silva <walmir.silva@kariricode.org>

.make/core/Makefile.functions.mk

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ==============================================================================
2+
# KaririCode\DevKit - Reusable Functions
3+
# ==============================================================================
4+
# Define funções shell reutilizáveis seguindo DRY principle
5+
# ==============================================================================
6+
7+
# --- Validação de Parâmetros ---
8+
define validate_param
9+
@if [ -z "$($(1))" ]; then \
10+
echo "$(RED)$(1) required. Usage: $(2)$(RESET)"; \
11+
exit 1; \
12+
fi
13+
endef
14+
15+
# --- Execução Docker Genérica ---
16+
define docker_exec
17+
@echo "$(BLUE)→ Running $(1) in Docker...$(RESET)"
18+
@$(DOCKER_RUN) $(DOCKER_IMAGE) $(2)
19+
@echo "$(GREEN)$(1) complete$(RESET)"
20+
endef
21+
22+
define docker_exec_make
23+
@echo "$(BLUE)→ Running make $(1) in Docker...$(RESET)"
24+
@$(DOCKER_RUN) $(DOCKER_IMAGE) make $(1)
25+
@echo "$(GREEN)✓ Docker make $(1) complete$(RESET)"
26+
endef
27+
28+
# --- Verificação de Arquivo ---
29+
define check_file
30+
@test -f $(1) || (echo "$(RED)$(2) not found$(RESET)" && exit 1)
31+
endef
32+
33+
# --- Criação de Diretório ---
34+
define ensure_dir
35+
@mkdir -p $(1)
36+
endef
37+
38+
# --- Header de Pipeline ---
39+
define pipeline_header
40+
@echo "$(BOLD)$(CYAN)╔════════════════════════════════════════════════════════╗$(RESET)"
41+
@echo "$(BOLD)$(CYAN)$(1)$(RESET)"
42+
@echo "$(BOLD)$(CYAN)╚════════════════════════════════════════════════════════╝$(RESET)"
43+
@echo ""
44+
endef
45+
46+
# --- Verificação de Branch Git ---
47+
define check_git_branch
48+
@CURRENT_BRANCH=$$(git rev-parse --abbrev-ref HEAD); \
49+
if [ "$$CURRENT_BRANCH" != "$(1)" ]; then \
50+
echo "$(RED)✗ This action requires branch '$(1)' (current: $$CURRENT_BRANCH)$(RESET)"; \
51+
exit 1; \
52+
fi
53+
endef
54+
55+
# --- Verificação de Versão PHP ---
56+
define check_php_version
57+
@echo "$(BLUE)→ Checking PHP version...$(RESET)"; \
58+
CURRENT_VERSION="$(PHP_VERSION)"; \
59+
MIN_VERSION="$(PHP_MIN_VERSION)"; \
60+
LOWEST=$$(printf '%s\n%s' "$$MIN_VERSION" "$$CURRENT_VERSION" | sort -V | head -n1); \
61+
if [ "$$LOWEST" != "$$MIN_VERSION" ]; then \
62+
echo "$(RED)✗ PHP $$MIN_VERSION+ required, found $$CURRENT_VERSION$(RESET)"; \
63+
exit 1; \
64+
fi; \
65+
echo "$(GREEN)✓ PHP version $$CURRENT_VERSION OK (>= $$MIN_VERSION)$(RESET)"
66+
endef

0 commit comments

Comments
 (0)