Spaces:
Sleeping
Sleeping
|
Download WORKFLOW_GUIDE.md from neurostack-in/talk2map-test: direct link, hf CLI and curl.
- Browser
- Download file 13 kB
-
https://huggingface.co/spaces/neurostack-in/talk2map-test/resolve/main/WORKFLOW_GUIDE.md
- Command line
-
hf download hf://spaces/neurostack-in/talk2map-test/WORKFLOW_GUIDE.md
-
curl -L -o WORKFLOW_GUIDE.md https://huggingface.co/spaces/neurostack-in/talk2map-test/resolve/main/WORKFLOW_GUIDE.md
13 kB
| # 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. |