Create LICENSE #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 🎯 Hexagonal Architecture CI/CD | |
| on: | |
| push: | |
| branches: [main, develop, developer, developers] | |
| pull_request: | |
| branches: [main, developer] # PRs to main (deploy) and developer (integration) | |
| env: | |
| GO_VERSION: "1.21" | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| # 🏗️ Job 1: Validar Arquitectura Hexagonal | |
| architecture-validation: | |
| name: 🏛️ Architecture Validation | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📂 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🔍 Validate Hexagonal Architecture Structure | |
| run: | | |
| echo "🏛️ Validating Hexagonal Architecture structure..." | |
| # Verificar estructura de carpetas obligatoria | |
| required_dirs=( | |
| "internal/core/domain" | |
| "internal/core/ports/repositories" | |
| "internal/core/ports/services" | |
| "internal/core/services" | |
| "internal/adapters/primary/http" | |
| "internal/adapters/secondary/persistence" | |
| "pkg" | |
| "cmd" | |
| "tests" | |
| ) | |
| for dir in "${required_dirs[@]}"; do | |
| if [ ! -d "$dir" ]; then | |
| echo "❌ Missing required directory: $dir" | |
| exit 1 | |
| else | |
| echo "✅ Found: $dir" | |
| fi | |
| done | |
| echo "🎉 Architecture structure validation passed!" | |
| - name: 🔎 Check Domain Purity (No external imports) | |
| run: | | |
| echo "🔍 Checking domain purity..." | |
| # Verificar que el dominio no importe dependencias externas | |
| domain_files=$(find internal/core/domain -name "*.go" | grep -v _test.go) | |
| for file in $domain_files; do | |
| echo "Checking $file..." | |
| # Verificar imports prohibidos en el dominio | |
| prohibited_imports=$(grep -E "import.*\"(github\.com|gorm\.io|gin|jwt)" "$file" | head -5) | |
| if [ ! -z "$prohibited_imports" ]; then | |
| echo "❌ Domain violation in $file:" | |
| echo "$prohibited_imports" | |
| echo "" | |
| echo "🚨 Domain layer should not import external dependencies!" | |
| exit 1 | |
| fi | |
| done | |
| echo "✅ Domain purity check passed!" | |
| - name: 🔄 Validate Dependency Direction | |
| run: | | |
| echo "🔄 Validating dependency direction..." | |
| # El core no debe importar adapters | |
| if grep -r "internal/adapters" internal/core/ | grep -v _test.go; then | |
| echo "❌ Core layer imports from adapters layer!" | |
| echo "🚨 This violates hexagonal architecture principles!" | |
| exit 1 | |
| fi | |
| echo "✅ Dependency direction validation passed!" | |
| # 🧪 Job 2: Tests y Quality | |
| test-and-quality: | |
| name: 🧪 Tests & Quality | |
| runs-on: ubuntu-latest | |
| needs: architecture-validation | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_PASSWORD: password | |
| POSTGRES_USER: postgres | |
| POSTGRES_DB: tasks_db_test | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| steps: | |
| - name: 📂 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🐹 Setup Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: 📦 Cache Go modules | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: 📥 Download dependencies | |
| run: go mod download | |
| - name: 🔍 Run Go vet | |
| run: go vet ./... | |
| - name: 🧹 Run Go fmt check | |
| run: | | |
| if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then | |
| echo "❌ Code is not properly formatted" | |
| gofmt -s -l . | |
| exit 1 | |
| fi | |
| echo "✅ Code formatting check passed" | |
| - name: 🧪 Run Unit Tests | |
| env: | |
| DB_HOST: localhost | |
| DB_PORT: 5432 | |
| DB_USER: postgres | |
| DB_PASSWORD: password | |
| DB_NAME: tasks_db_test | |
| DB_SSL_MODE: disable | |
| JWT_SECRET: test-secret-key | |
| run: | | |
| echo "🧪 Running unit tests..." | |
| go test ./tests/unit/... -v -race -coverprofile=unit_coverage.out | |
| echo "📊 Unit test coverage:" | |
| go tool cover -func=unit_coverage.out | |
| - name: 🔗 Run Integration Tests | |
| env: | |
| DB_HOST: localhost | |
| DB_PORT: 5432 | |
| DB_USER: postgres | |
| DB_PASSWORD: password | |
| DB_NAME: tasks_db_test | |
| DB_SSL_MODE: disable | |
| JWT_SECRET: test-secret-key | |
| run: | | |
| echo "🔗 Running integration tests..." | |
| go test ./tests/integration/... -v -coverprofile=integration_coverage.out | |
| - name: 🎯 Run All Tests with Coverage | |
| env: | |
| DB_HOST: localhost | |
| DB_PORT: 5432 | |
| DB_USER: postgres | |
| DB_PASSWORD: password | |
| DB_NAME: tasks_db_test | |
| DB_SSL_MODE: disable | |
| JWT_SECRET: test-secret-key | |
| run: | | |
| echo "🎯 Running all tests with coverage..." | |
| go test ./... -v -race -coverprofile=coverage.out -covermode=atomic | |
| echo "📊 Total coverage:" | |
| go tool cover -func=coverage.out | tail -1 | |
| - name: 📊 Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.out | |
| flags: unittests | |
| name: hexagonal-go-coverage | |
| # 🔒 Job 3: Security Scan | |
| security-scan: | |
| name: 🔒 Security Scan | |
| runs-on: ubuntu-latest | |
| needs: test-and-quality | |
| steps: | |
| - name: 📂 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🐹 Setup Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: 🔒 Run Gosec Security Scanner | |
| uses: securecodewarrior/github-action-gosec@master | |
| with: | |
| args: "-no-fail -fmt sarif -out gosec.sarif ./..." | |
| - name: 📊 Upload SARIF file | |
| uses: github/codeql-action/upload-sarif@v3 | |
| with: | |
| sarif_file: gosec.sarif | |
| # 🏗️ Job 4: Build & Docker | |
| build-and-docker: | |
| name: 🏗️ Build & Docker | |
| runs-on: ubuntu-latest | |
| needs: [test-and-quality, security-scan] | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: 📂 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🐹 Setup Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: 🏗️ Build binary | |
| run: | | |
| echo "🏗️ Building Go binary..." | |
| make build | |
| echo "✅ Build successful!" | |
| - name: 🐳 Log in to Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 🏷️ Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=sha,prefix={{branch}}- | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| - name: 🐳 Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # 🚀 Job 5: Deploy (cuando se mergea developer a main) | |
| deploy: | |
| name: 🚀 Deploy to Production | |
| runs-on: ubuntu-latest | |
| needs: build-and-docker | |
| if: | | |
| github.ref == 'refs/heads/main' && | |
| github.event_name == 'push' && | |
| ( | |
| contains(github.event.head_commit.message, 'Merge pull request') || | |
| github.event.head_commit.author.name != 'dependabot[bot]' | |
| ) | |
| environment: production | |
| steps: | |
| - name: 📂 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🚀 Deploy to Production | |
| run: | | |
| echo "🚀 Deploying to production environment..." | |
| echo "✅ Deployment completed!" | |
| # Aquí irían los comandos reales de deployment | |
| # Por ejemplo: kubectl apply, docker-compose pull, etc. | |
| # 📊 Job 6: Post-Deploy Verification | |
| post-deploy-verification: | |
| name: 📊 Post-Deploy Verification | |
| runs-on: ubuntu-latest | |
| needs: deploy | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - name: 📂 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🏥 Health Check | |
| run: | | |
| echo "🏥 Running post-deployment health checks..." | |
| # Simular health check | |
| sleep 5 | |
| echo "✅ API is healthy" | |
| echo "✅ Database connection OK" | |
| echo "✅ All services running correctly" | |
| echo "🎉 Post-deployment verification completed!" |