CI/CD Pipeline Guide
CI/CD Pipeline Guide
Section titled “CI/CD Pipeline Guide”This document describes the comprehensive CI/CD pipeline implemented for the Bartendie application.
Overview
Section titled “Overview”The CI/CD pipeline ensures code quality, runs comprehensive tests, and automates deployment. It consists of multiple workflows that run different checks based on the trigger event.
Workflows
Section titled “Workflows”1. Main CI/CD Pipeline (.github/workflows/deploy.yml)
Section titled “1. Main CI/CD Pipeline (.github/workflows/deploy.yml)”Triggers:
- Push to
mainbranch - Pull requests to
mainbranch - Manual workflow dispatch
Jobs:
Backend Tests & Quality (backend-tests)
Section titled “Backend Tests & Quality (backend-tests)”- Runtime: Ubuntu Latest with PostgreSQL 15
- Dependencies: Elixir 1.16, OTP 26
- Steps:
- Install Elixir dependencies with caching
- Check code formatting (
mix format --check-formatted) - Run static analysis (
mix credo --strict) - Compile with warnings as errors
- Run full test suite with coverage (
mix test --cover) - Upload test results and coverage reports
Frontend Unit Tests (frontend-tests)
Section titled “Frontend Unit Tests (frontend-tests)”- Runtime: Ubuntu Latest
- Dependencies: Node.js 18, pnpm
- Steps:
- Install frontend dependencies with caching
- Run ESLint (
pnpm lint) - Run Vitest unit tests (
pnpm test:run) - Generate test coverage (
pnpm test:coverage) - Build frontend (
pnpm build) - Upload test results and build artifacts
End-to-End Tests (e2e-tests)
Section titled “End-to-End Tests (e2e-tests)”- Runtime: Ubuntu Latest with PostgreSQL 15
- Dependencies: Elixir 1.16, Node.js 18, Playwright
- Steps:
- Set up both backend and frontend environments
- Install Playwright browsers
- Set up test database
- Build frontend for testing
- Run Playwright E2E tests across multiple browsers
- Upload test results, screenshots, and videos
Build Verification (build-verification)
Section titled “Build Verification (build-verification)”- Runtime: Ubuntu Latest with PostgreSQL 15
- Dependencies: Full stack setup
- Steps:
- Compile backend for production
- Build frontend for production
- Verify backend can start and respond
- Upload production build artifacts
Deploy Documentation (deploy-docs)
Section titled “Deploy Documentation (deploy-docs)”- Condition: Only on
mainbranch pushes - Dependencies: All test jobs must pass
- Steps:
- Build Docusaurus documentation
- Deploy to Digital Ocean via SSH/rsync
Deploy Application (deploy-app)
Section titled “Deploy Application (deploy-app)”- Condition: Only on
mainbranch pushes - Dependencies: All test jobs must pass
- Status: Placeholder for future implementation
Test Results Summary (test-summary)
Section titled “Test Results Summary (test-summary)”- Condition: Always runs (even if tests fail)
- Dependencies: All test jobs
- Steps:
- Download all test artifacts
- Generate comprehensive test summary
- Create GitHub Step Summary with results
- Fail pipeline if any critical tests failed
2. PR Quality Checks (.github/workflows/pr-checks.yml)
Section titled “2. PR Quality Checks (.github/workflows/pr-checks.yml)”Triggers:
- Pull request opened, synchronized, or reopened
Purpose: Fast quality checks for pull requests without running the full test suite.
Steps:
- Code formatting checks
- Static analysis (Credo)
- Compilation warnings check
- Frontend linting
- Build verification
- Automated PR comment with results
Environment Variables
Section titled “Environment Variables”Global Environment
Section titled “Global Environment”ELIXIR_VERSION: '1.16'OTP_VERSION: '26'NODE_VERSION: '18'MIX_ENV: testDATABASE_URL: postgres://postgres:postgres@localhost:5432/bartendie_testEVENTSTORE_URL: postgres://postgres:postgres@localhost:5432/bartendie_eventstore_testRequired Secrets
Section titled “Required Secrets”SSH_PRIVATE_KEY: SSH private key for deploymentSSH_KNOWN_HOSTS: Known hosts for SSH connectionSSH_USER: SSH username for deploymentSSH_HOST: SSH hostname for deployment
Database Configuration
Section titled “Database Configuration”PostgreSQL Services
Section titled “PostgreSQL Services”Each job that needs database access includes a PostgreSQL 15 service:
services: postgres: image: postgres:15 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_DB: bartendie_test ports: - 5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5Database Setup
Section titled “Database Setup”- Test databases are automatically created and migrated
- Event store databases are configured for event sourcing tests
- Health checks ensure database readiness before tests run
Caching Strategy
Section titled “Caching Strategy”Elixir Dependencies
Section titled “Elixir Dependencies”- uses: actions/cache@v4 with: path: | deps _build key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}Frontend Dependencies
Section titled “Frontend Dependencies”- uses: actions/setup-node@v4 with: node-version: ${{ env.NODE_VERSION }} cache: 'pnpm' cache-dependency-path: frontend/pnpm-lock.yamlTest Artifacts
Section titled “Test Artifacts”Collected Artifacts
Section titled “Collected Artifacts”- Backend: Test coverage reports, compiled artifacts
- Frontend: Test coverage, build output, lint results
- E2E: Playwright test results, screenshots, videos, traces
- Build: Production-ready artifacts for deployment
Retention
Section titled “Retention”- All test artifacts are retained for 7 days
- Build artifacts are available for deployment jobs
Parallel Execution
Section titled “Parallel Execution”Job Dependencies
Section titled “Job Dependencies”backend-tests ──┐frontend-tests ─┼── build-verification ──┐e2e-tests ──────┘ ├── deploy-docs ├── deploy-app └── test-summaryOptimization
Section titled “Optimization”- Backend and frontend tests run in parallel
- E2E tests run independently (can be parallelized further)
- Build verification waits for unit tests but not E2E
- Deployment only happens after all tests pass
Error Handling
Section titled “Error Handling”Fail-Fast Strategy
Section titled “Fail-Fast Strategy”- Compilation errors fail immediately
- Critical test failures stop dependent jobs
- Quality checks must pass for deployment
Comprehensive Reporting
Section titled “Comprehensive Reporting”- Test summary always runs (even on failures)
- All artifacts are collected regardless of test outcomes
- GitHub Step Summary provides detailed results
Status Badges
Section titled “Status Badges”Add to your README.md:
[](https://github.com/r26D/bartendie/actions/workflows/deploy.yml)[](https://github.com/r26D/bartendie/actions/workflows/pr-checks.yml)Local Development
Section titled “Local Development”Running Tests Locally
Section titled “Running Tests Locally”# Backend testsmix test
# Frontend testscd frontend && pnpm test:run
# E2E testscd frontend && pnpm e2e
# Quality checksmix quality.cicd frontend && pnpm lintDebugging CI Issues
Section titled “Debugging CI Issues”- Check job logs in GitHub Actions
- Download test artifacts for detailed analysis
- Run tests locally with same environment
- Use
acttool to run GitHub Actions locally
Future Enhancements
Section titled “Future Enhancements”Planned Improvements
Section titled “Planned Improvements”- Performance Testing: Add load testing with Artillery or k6
- Security Scanning: Integrate SAST/DAST tools
- Dependency Scanning: Automated vulnerability checks
- Multi-environment Deployment: Staging → Production pipeline
- Blue-Green Deployment: Zero-downtime deployments
- Monitoring Integration: Post-deployment health checks
Deployment Targets
Section titled “Deployment Targets”The current pipeline includes a placeholder for application deployment. Future implementations could target:
- Heroku: Simple PaaS deployment
- AWS: ECS, Lambda, or EC2 deployment
- Digital Ocean: App Platform or Droplet deployment
- Docker: Containerized deployment to any platform
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”- Database Connection: Check PostgreSQL service health
- Cache Issues: Clear cache and retry
- Dependency Conflicts: Update lock files
- Test Timeouts: Increase timeout values in config
- Artifact Upload Failures: Check artifact paths and permissions
Debug Commands
Section titled “Debug Commands”# Check workflow syntaxact --list
# Validate workflow filesyamllint .github/workflows/
# Test specific job locallyact -j backend-tests