# Talk2Map CI/CD Workflow Guide This document explains the complete CI/CD workflow for the Talk2Map FastAPI project, including feature development, testing, and deployment processes. ## ๐Ÿ”„ Workflow Overview The workflow implements a **fully manual-controlled feature โ†’ staging โ†’ main โ†’ production** pipeline where: - ๐Ÿ‘ฅ **Developer manually triggers all actions** - No automatic testing on feature branches - ๐Ÿงช **Tests run only when developer initiates** - Complete manual control - ๐Ÿš€ **Manual promotion at every stage** - Developers decide when to advance **Key principle: Developers have complete control over when testing and merging happens.** ``` graph TD A[Developer creates feature/name branch] --> B[Push code to feature branch] B --> C[๐Ÿ‘ฅ Developer manually triggers feature testing] C --> D[Manual Feature Testing workflow] D --> E[Run tests on feature branch] E --> F{Tests pass?} F -->|No| G[โŒ Fix tests and retry] F -->|Yes| H[Check conflicts with staging] H --> I{Conflicts detected?} I -->|Yes| J[โŒ Resolve conflicts and retry] I -->|No| K[โœ… Merge to staging] K --> L[Staging CI triggers automatically] L --> M[Run tests on staging] M --> N{Tests pass?} N -->|No| O[โŒ Create failure issue] N -->|Yes| P[โœ… Deploy to HF Test Space] P --> Q[API Testing workflow triggers] Q --> R[๐Ÿ‘ฅ Developer manually promotes to main] R --> S[Manual Promotion workflow] S --> T[Run tests on staging again] T --> U{Tests pass?} U -->|No| V[โŒ Block promotion] U -->|Yes| W[โœ… Merge to main] W --> X[Deploy to Production triggers] X --> Y[Run final tests on main] Y --> Z{Tests pass?} Z -->|No| AA[โŒ Block deployment] Z -->|Yes| BB[๐Ÿš€ Deploy to HF Production] ``` ## ๐Ÿšซ **STRICT BLOCKING POLICY** **The workflow implements a zero-tolerance policy for failures:** ### โŒ What Blocks Merges: 1. **Test Failures** - Any failing test in `pytest -v` 2. **Merge Conflicts** - Any conflicts detected between branches 3. **Workflow Errors** - Any step failure in the CI pipeline ### ๐Ÿšจ What Happens When Blocked: 1. **NO MERGE OCCURS** - The workflow stops immediately 2. **GitHub Issue Created** - Detailed alert with: - Exact failure reason - Step-by-step resolution instructions - Links to relevant logs and resources 3. **Labels Applied** - `merge-blocked`, `urgent` for easy filtering 4. **Developer Notification** - Issue assignment and team alerts ### โœ… Merge Only Happens When: - โœ… **ALL tests pass** (`pytest -v` returns 0) - โœ… **NO conflicts detected** (clean merge possible) - โœ… **Workflow completes successfully** (all steps green) **Remember: Better to block a merge than break the pipeline!** --- ## ๐Ÿ“ˆ Workflow Components ### 1. Manual Feature Testing and Staging Merge (`manual-feature-merge.yml`) **Triggers:** Manual workflow dispatch only **Purpose:** Test feature branch and merge to staging when developer is ready **Manual Process:** 1. Developer triggers workflow with feature branch name 2. Run tests on specified feature branch using `pytest -v` 3. Check for merge conflicts with staging branch 4. **ONLY if BOTH conditions are met:** - โœ… All feature tests pass - โœ… No merge conflicts detected **THEN:** Merge feature to staging 5. **If ANY condition fails:** - โŒ **NO MERGE OCCURS** - ๐Ÿšจ GitHub issue created with detailed failure information - ๐Ÿšซ Developer must fix issues and retry **Key Features:** - โœ… **Complete manual control** - No automatic testing on feature branches - โœ… Pre-merge conflict detection - โœ… Test validation before merge - โœ… Detailed success/failure notifications ### 2. Staging Branch CI (`staging-ci.yml`) **Triggers:** Push to `staging` branch (after manual merge) **Purpose:** Test and deploy staging after developer merges **Process:** 1. **Tests run AFTER merge to staging** 2. If tests pass: - Deploy to HuggingFace test space - Create success notification - Mark as "ready for promotion" 3. If tests fail: - Create failure alert - Block further progression **Key Features:** - โœ… **Post-merge testing** - tests run after code is in staging - โœ… Automatic test space deployment - โœ… Clear success/failure notifications - โœ… Ready-for-promotion status ### 3. API Endpoint Testing (`api-testing.yml`) **Triggers:** After successful Staging Branch CI **Purpose:** Test deployed API endpoints on HuggingFace **Process:** 1. Wait for HuggingFace deployment (configurable wait time) 2. Validate Postman collection 3. Run Newman tests against deployed API 4. Generate HTML test reports 5. Create success/failure notifications **Environments:** - **Test:** `https://neurostack-in-talk2map-test.hf.space` - **Production:** `https://neurostack-in-talk2map-prod.hf.space` **Manual Trigger Options:** - Custom base URL - Environment selection (test/production) - Custom wait time ### 4. Manual Staging to Main Promotion (`promote.yml`) **Triggers:** Manual workflow dispatch only **Purpose:** Manually promote staging to main when developer is ready **Manual Process:** 1. Developer triggers the workflow manually 2. Run tests on staging branch again 3. Check for merge conflicts with main branch 4. **ONLY if BOTH conditions are met:** - โœ… All staging tests pass - โœ… No merge conflicts with main **THEN:** Merge staging to main and trigger production deployment 5. **If ANY condition fails:** - โŒ **NO PROMOTION OCCURS** - ๐Ÿšจ Detailed GitHub issue created with resolution steps - ๐Ÿšซ Production deployment blocked **Manual Control:** - โœ… **Developer decides when to promote** - No automatic promotion - โœ… Final validation before production - โœ… Conflict detection and blocking - โœ… Clear success/failure feedback ### 5. Production Deployment (`sync-to-hf.yml`) **Triggers:** After successful staging to main promotion **Purpose:** Deploy main branch to production **ONLY with final validation** **Strict Blocking Process:** 1. Run final tests on main branch 2. **ONLY if tests pass:** - โœ… Deploy to HuggingFace production space - โœ… Create deployment success notification 3. **If tests fail:** - โŒ **NO DEPLOYMENT OCCURS** - ๐Ÿšจ Production deployment blocked - ๐Ÿšซ Create urgent alert for manual intervention **Production Safety:** - โœ… **Final gate:** Last chance to catch issues before production - โœ… Zero-downtime protection: No broken code reaches production - โœ… Emergency procedures documented for failures - โœ… Deployment success/failure notifications **Production URL:** `https://neurostack-in-talk2map-prod.hf.space` ### 6. Manual Promotion (`manual-promote.yml`) **Purpose:** Emergency manual promotion from staging to main (alternative method) **Use Cases:** - Resolve complex merge conflicts manually - Emergency deployments - Override automatic promotion when needed ## ๐Ÿš€ Developer Workflow ### Step 1: Create Feature Branch ```bash # Create and switch to feature branch git checkout -b feature/your-feature-name # Make your changes # ... code changes ... # Commit and push git add . git commit -m "Add your feature" git push origin feature/your-feature-name ``` ### Step 2: Manual Feature Testing and Staging Merge ```bash # When ready to test and merge your feature: # Go to GitHub Actions โ†’ Manual Feature Testing and Staging Merge โ†’ Run workflow # Provide: # - Feature branch name: feature/your-feature-name # - Reason: "Feature ready for staging" ``` **What happens:** 1. **Manual Feature Testing** workflow runs 2. Tests execute on your feature branch 3. If successful and no conflicts, merges to staging 4. **No automatic testing** - only when you trigger it ### Step 3: Staging Validation (Automatic) 1. **Staging CI** runs automatically after merge 2. Tests execute on the staging branch 3. If successful, deploys to HuggingFace test space 4. **API Testing** runs against the test deployment ### Step 4: Manual Promotion to Production ```bash # When ready to go to production: # Go to Actions โ†’ Manual Staging to Main Promotion โ†’ Run workflow # Provide reason for promotion ``` **What happens:** 1. **Manual Promotion** workflow runs 2. Tests run on staging again 3. If successful and no conflicts, promotes to main 4. **Production deployment** triggers automatically ### Step 5: Production Deployment (Automatic) 1. **Production deployment** runs after main is updated 2. Final tests run on main branch 3. Main branch deployed to HuggingFace production 4. Production API is live ## ๐Ÿ”ง Configuration ### Environment Variables Required - `GROQ_API_KEY`: For running tests - `HF_TOKEN`: HuggingFace deployment token - `GITHUB_TOKEN`: Automatically provided by GitHub ### HuggingFace Spaces - **Test Space:** `neurostack-in/talk2map-test` - **Production Space:** `neurostack-in/talk2map-prod` ### Test Configuration Tests are located in the `tests/` directory: - `tests/unit/` - Unit tests - `tests/integration/` - Integration tests - `tests/e2e/` - End-to-end tests Run tests locally: `pytest -v` ## ๐Ÿšจ Error Handling & Alerts The workflow creates GitHub Issues for various failure scenarios: ### Merge Conflicts - **Title:** "๐Ÿšจ Merge Conflict Alert: Feature branch X cannot merge to staging" - **Content:** Detailed conflict information and resolution steps - **Labels:** `merge-conflict`, `urgent` ### Test Failures - **Title:** "โŒ Feature Branch CI Failed: branch-name" - **Content:** Workflow run links and troubleshooting steps - **Labels:** `ci-failure`, `urgent` ### API Test Failures - **Title:** "โŒ API Tests Failed - Environment" - **Content:** Test results and debugging information - **Labels:** `api-test-failure`, `environment`, `urgent` ### Deployment Issues - **Title:** "โŒ Production Deployment Failed" - **Content:** Deployment logs and recovery steps - **Labels:** `deployment-failure`, `production`, `urgent` ## ๐ŸŽฏ Best Practices ### Branch Naming - Use `feature/` prefix for all feature branches - Example: `feature/add-user-authentication` - Example: `feature/fix-map-rendering` ### Commit Messages - Use clear, descriptive commit messages - Reference issues when applicable - Follow conventional commit format when possible ### Testing - Run tests locally before pushing: `pytest -v` - Ensure all tests pass before creating pull requests - Add tests for new features and bug fixes ### Conflict Resolution - Pull latest staging changes before starting new features - Resolve conflicts promptly when alerts are created - Test thoroughly after resolving conflicts ## ๐Ÿ” Monitoring & Debugging ### Workflow Status - Check GitHub Actions tab for workflow status - Review workflow logs for detailed information - Monitor GitHub Issues for automated alerts ### API Testing - Download HTML test reports from workflow artifacts - Use manual API testing workflow for debugging - Test both environments (test/production) as needed ### HuggingFace Deployments - Check HuggingFace Space logs for deployment issues - Verify API accessibility after deployments - Monitor space status and performance ## ๐Ÿ†˜ Troubleshooting ### Common Issues #### 1. Merge Conflicts **Solution:** Follow the commands in the automated GitHub issue ```bash git checkout feature/your-branch git fetch origin git merge origin/staging # Resolve conflicts manually git add . git commit -m "Resolve merge conflicts with staging" git push origin feature/your-branch ``` #### 2. Test Failures **Solution:** Check workflow logs and fix failing tests ```bash # Run tests locally pytest -v # Fix failing tests # Commit and push fixes git add . git commit -m "Fix failing tests" git push origin feature/your-branch ``` #### 3. API Tests Failing **Solution:** Check API accessibility and configuration - Verify GROQ_API_KEY is valid - Check HuggingFace deployment status - Review API logs and error messages #### 4. Deployment Failures **Solution:** Check HuggingFace token and space configuration - Verify HF_TOKEN secret is valid - Check space permissions and settings - Review deployment logs ### Manual Overrides #### Manual Promotion Use the manual promotion workflow when automatic promotion fails: 1. Go to Actions โ†’ Manual Promotion (Staging to Main) 2. Click "Run workflow" 3. Provide reason for manual promotion 4. Monitor the workflow execution #### Manual API Testing Test specific environments manually: 1. Go to Actions โ†’ API Endpoint Testing 2. Click "Run workflow" 3. Select environment (test/production) 4. Optionally customize URL and wait time 5. Review test results and reports ## ๐Ÿ“ˆ Workflow Metrics The workflows provide comprehensive reporting: - โœ… Success/failure notifications - ๐Ÿ“Š Test coverage reports - ๐Ÿ• Deployment timing information - ๐Ÿ“‹ Detailed error logs and debugging info - ๐Ÿ”— Direct links to relevant resources All notifications are created as GitHub Issues with appropriate labels for easy filtering and management.