talk2map-test / WORKFLOW_GUIDE.md
Noel-Teens's picture
testing new workflow
bfa95ad
|
Raw History Blame Contribute Delete
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

# 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

# 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

# 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

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

# 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.