# Phase 3: Enhanced CI/CD Workflow **Status:** โœ… Imported to n8n **Webhook URL:** `https://n8n.oky.sh/webhook/openhands-enhanced` **Last Updated:** 2025-12-01 --- ## ๐ŸŽฏ **Enhanced Features** ### 1. **Retry Logic** - Maximum 3 retry attempts - 15-second wait between retries - Tracks retry count in workflow static data ### 2. **Status Checking** - Waits 10 seconds for OpenHands initialization - Simulates build status checking - Returns SUCCESS/FAILED status ### 3. **Response Formatting** - JSON response with emoji indicators - Includes retry count - Shows build status, repo, branch, commit ### 4. **Error Handling** - Graceful degradation - Clear error messages - Fallback responses --- ## ๐Ÿ”„ **Workflow Flow** ``` [1] Gitea Webhook โ†“ [2] Extract Repo Info (JavaScript) โ†“ [3] Start OpenHands Build (SSH) โ†“ [4] Wait 10s (Initialization) โ†“ [5] Check Build Status (Simulated) โ†“ [6] Should Retry? (IF Node) โ”œโ”€ NO โ†’ [7] Format Response โ””โ”€ YES โ†’ [8] Wait 15s โ†’ [9] Under Max Retries? โ”œโ”€ YES โ†’ [10] Increment Retry โ†’ [11] Retry Build โ””โ”€ NO โ†’ [7] Format Response (MAX EXCEEDED) โ†“ [7] Format Response (with emoji & details) โ†“ [8] Send JSON Response ``` --- ## ๐Ÿ“Š **Response Format** ### Success Response ```json { "status": "SUCCESS", "emoji": "โœ…", "repo": "gitadmin/mvp-factory-openhands", "branch": "main", "commit": "abc123", "message": "Build completed successfully", "timestamp": "2025-12-01T18:15:00.000Z", "retry_count": 0 } ``` ### Failure Response ```json { "status": "FAILED", "emoji": "โŒ", "repo": "gitadmin/mvp-factory-openhands", "branch": "main", "commit": "abc123", "message": "Build failed - errors detected", "timestamp": "2025-12-01T18:15:00.000Z", "retry_count": 1 } ``` --- ## ๐Ÿ”ง **Key Improvements Over Phase 2** ### Phase 2 (Basic) - Webhook โ†’ Extract โ†’ SSH โ†’ Response - Simple execution - No retry logic - No status checking - Basic response ### Phase 3 (Enhanced) - โœ… Webhook โ†’ Extract โ†’ SSH โ†’ Wait โ†’ Check โ†’ Retry Loop โ†’ Response - โœ… Retry logic (3 attempts) - โœ… Status checking - โœ… Detailed response with status - โœ… Error handling - โœ… Better UX with emojis --- ## ๐Ÿงช **Testing** ### Activate Workflow 1. Go to: https://n8n.oky.sh 2. Find: "Gitea โ†’ OpenHands Enhanced CI/CD" 3. **Toggle to activate** (green) ### Test Manually ```bash curl -X POST https://n8n.oky.sh/webhook/openhands-enhanced \ -H "Content-Type: application/json" \ -d '{ "repository": { "name": "test-repo", "full_name": "gitadmin/test-repo", "clone_url": "https://git.oky.sh/gitadmin/test-repo.git" }, "ref": "refs/heads/main", "after": "xyz789", "commits": [{"message": "Test enhanced workflow"}], "pusher": {"username": "gitadmin"} }' ``` ### Expected Response ```json { "status": "SUCCESS", "emoji": "โœ…", "message": "Build completed successfully", ... } ``` --- ## ๐Ÿš€ **Gitea Webhook Configuration** ### Update Gitea Webhook 1. Go to Gitea repository 2. Settings โ†’ Webhooks โ†’ Edit existing webhook 3. Update URL to: `https://n8n.oky.sh/webhook/openhands-enhanced` 4. Save ### Alternative: Create New Webhook 1. Add Webhook โ†’ Gitea 2. URL: `https://n8n.oky.sh/webhook/openhands-enhanced` 3. Push Events: โœ… 4. Active: โœ… --- ## ๐Ÿ“ˆ **Production Readiness** ### โœ… Working - Webhook receiving - Payload extraction - SSH execution - Retry logic - Status reporting - Response formatting ### ๐Ÿ”„ Future Enhancements - Actual OpenHands status checking (instead of simulation) - Post status to Gitea API (commit statuses) - Email/Slack notifications - Build artifacts storage - Test result reporting --- ## ๐Ÿ”‘ **Configuration** ### Workflow Settings - **Name:** "Gitea โ†’ OpenHands Enhanced CI/CD" - **Path:** `openhands-enhanced` - **Active:** โœ… - **Version:** 1 ### SSH Credentials - **ID:** v2BMXeCFGpXaoIyb - **Name:** SSH Private Key account - **Key:** /home/bam/.ssh/n8n_key ### Retry Settings - **Max Retries:** 3 - **Wait Between Retries:** 15 seconds - **Initial Wait:** 10 seconds --- ## ๐Ÿ“ **Notes** - This workflow is **simulated** - build status checking is mocked - In production, replace "Check Build Status" with actual OpenHands API polling - Retry logic uses n8n static data to persist counter across nodes - The workflow will eventually complete (either SUCCESS or MAX RETRIES EXCEEDED) --- ## ๐ŸŽ“ **Key Learnings** 1. **n8n Static Data** - Use `$workflow.staticData` for persistent state 2. **Retry Patterns** - Combine Wait + IF nodes for retry loops 3. **Response Formatting** - JavaScript nodes can format JSON responses 4. **Conditional Logic** - IF nodes with multiple branches for complex flows 5. **SSH Integration** - Works reliably for executing commands remotely --- **Status:** Ready for testing โœ… **Next:** Configure Gitea webhook and test end-to-end