|
| 1 | +# Codex GitHub Actions Workflows |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Codex repository uses several GitHub Actions workflows for automated content validation, AI enhancement, indexing, and deployment. All workflows are designed with async processing, caching, and graceful error handling. |
| 6 | + |
| 7 | +## Workflow Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 11 | +│ PR Created │───▶│ Quick Validate │───▶│ AI Enhance │ |
| 12 | +│ or Updated │ │ (< 30s) │ │ (async) │ |
| 13 | +└─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 14 | + │ │ |
| 15 | + ▼ ▼ |
| 16 | + ┌─────────────────┐ ┌─────────────────┐ |
| 17 | + │ Schema Validate │ │ Post Feedback │ |
| 18 | + └─────────────────┘ └─────────────────┘ |
| 19 | + │ |
| 20 | + ▼ |
| 21 | + ┌─────────────────┐ |
| 22 | + │ Incremental │ |
| 23 | + │ Index + Cache │ |
| 24 | + └─────────────────┘ |
| 25 | + │ |
| 26 | + ▼ (on merge) |
| 27 | + ┌─────────────────┐ |
| 28 | + │ Publish Index │ |
| 29 | + │ + Notify │ |
| 30 | + └─────────────────┘ |
| 31 | +``` |
| 32 | + |
| 33 | +## Workflows |
| 34 | + |
| 35 | +### 1. `async-processing.yml` (Primary) |
| 36 | + |
| 37 | +**Triggers:** |
| 38 | +- Pull requests (opened, synchronized, ready_for_review) |
| 39 | +- Push to main branch |
| 40 | +- Manual dispatch with optional full reindex |
| 41 | + |
| 42 | +**Features:** |
| 43 | +- ⚡ Quick validation stage (< 30s) |
| 44 | +- 🔄 Async AI enhancement (non-blocking) |
| 45 | +- 📦 Incremental indexing with SQLite cache |
| 46 | +- 🔔 Real-time status updates via commit statuses |
| 47 | +- 🚀 Triggers frame.dev deployment on publish |
| 48 | + |
| 49 | +**Optimizations:** |
| 50 | +- Concurrency groups prevent duplicate runs |
| 51 | +- Cache restoration for faster builds |
| 52 | +- Parallel job execution where possible |
| 53 | + |
| 54 | +### 2. `auto-index.yml` |
| 55 | + |
| 56 | +**Triggers:** |
| 57 | +- Push to `weaves/`, `scripts/`, `schema/` |
| 58 | +- Manual dispatch |
| 59 | +- Repository dispatch (frame-deploy-complete) |
| 60 | + |
| 61 | +**Purpose:** |
| 62 | +Builds and publishes the search index JSON files. |
| 63 | + |
| 64 | +### 3. `ai-enhance-pr.yml` |
| 65 | + |
| 66 | +**Triggers:** |
| 67 | +- Pull requests (opened, synchronized) |
| 68 | + |
| 69 | +**Purpose:** |
| 70 | +AI-powered content analysis and suggestions: |
| 71 | +- Quality scoring |
| 72 | +- Auto-tag detection |
| 73 | +- Readability analysis |
| 74 | +- Safe auto-fixes (with `auto-enhance` label) |
| 75 | + |
| 76 | +**Skipping:** |
| 77 | +- Add `skip-ai` label to skip AI analysis |
| 78 | +- Dependabot PRs are automatically skipped |
| 79 | + |
| 80 | +### 4. `auto-merge-weavers.yml` |
| 81 | + |
| 82 | +**Triggers:** |
| 83 | +- Pull requests from trusted Weavers |
| 84 | + |
| 85 | +**Purpose:** |
| 86 | +Automatic approval and merge for trusted contributors: |
| 87 | +- Checks `.github/WEAVERS.txt` for author |
| 88 | +- Runs validation and duplicate checks |
| 89 | +- Auto-approves and squash merges |
| 90 | + |
| 91 | +### 5. `test.yml` |
| 92 | + |
| 93 | +**Triggers:** |
| 94 | +- Push and PR to main |
| 95 | + |
| 96 | +**Purpose:** |
| 97 | +- Unit tests with coverage |
| 98 | +- SQL cache functionality tests |
| 99 | +- Integration tests (full workflow) |
| 100 | + |
| 101 | +### 6. `build-index.yml` |
| 102 | + |
| 103 | +**Triggers:** |
| 104 | +- Push to main |
| 105 | +- Manual dispatch |
| 106 | + |
| 107 | +**Purpose:** |
| 108 | +Builds search index with SQL caching and pushes to `index` branch. |
| 109 | + |
| 110 | +## Caching Strategy |
| 111 | + |
| 112 | +### SQLite Cache |
| 113 | +``` |
| 114 | +.cache/codex.db |
| 115 | +``` |
| 116 | +- Stores file hashes and metadata |
| 117 | +- Only re-processes changed files |
| 118 | +- ~80% faster incremental builds |
| 119 | + |
| 120 | +### Embedding Cache |
| 121 | +``` |
| 122 | +.cache/embeddings/ |
| 123 | +``` |
| 124 | +- Pre-computed document embeddings |
| 125 | +- Persists across runs |
| 126 | +- ~60% faster search index builds |
| 127 | + |
| 128 | +### Cache Keys |
| 129 | +```yaml |
| 130 | +key: codex-index-v2-${{ hashFiles('weaves/**/*.md') }} |
| 131 | +restore-keys: |
| 132 | + - codex-index-v2- |
| 133 | + - codex-index- |
| 134 | +``` |
| 135 | +
|
| 136 | +## Environment Variables |
| 137 | +
|
| 138 | +| Variable | Required | Description | |
| 139 | +|----------|----------|-------------| |
| 140 | +| `ANTHROPIC_API_KEY` | AI only | Claude API key for AI enhancement | |
| 141 | +| `OPENAI_API_KEY` | AI only | OpenAI API key (fallback) | |
| 142 | +| `GH_PAT` | Yes | Personal access token for cross-repo triggers | |
| 143 | + |
| 144 | +## Manual Triggers |
| 145 | + |
| 146 | +### Force Full Reindex |
| 147 | +```bash |
| 148 | +gh workflow run async-processing.yml -f full_reindex=true |
| 149 | +``` |
| 150 | + |
| 151 | +### Run Specific Workflow |
| 152 | +```bash |
| 153 | +gh workflow run auto-index.yml |
| 154 | +gh workflow run ai-enhance-pr.yml |
| 155 | +``` |
| 156 | + |
| 157 | +## Error Handling |
| 158 | + |
| 159 | +1. **Validation Failures:** |
| 160 | + - Posts detailed error comments on PR |
| 161 | + - Updates commit status to failed |
| 162 | + - Does not block other jobs |
| 163 | + |
| 164 | +2. **AI Enhancement Failures:** |
| 165 | + - Logs error but continues |
| 166 | + - Never blocks merging |
| 167 | + - Falls back gracefully |
| 168 | + |
| 169 | +3. **Index Failures:** |
| 170 | + - Attempts to use cached index |
| 171 | + - Posts warning but allows manual merge |
| 172 | + |
| 173 | +## Integration Points |
| 174 | + |
| 175 | +### frame.dev Deployment |
| 176 | +When index is published, triggers `repository_dispatch` to frame.dev: |
| 177 | +```yaml |
| 178 | +event-type: codex-index-updated |
| 179 | +client-payload: '{"sha": "..."}' |
| 180 | +``` |
| 181 | + |
| 182 | +### Webhook Notifications |
| 183 | +The `finalize` job updates commit status with: |
| 184 | +- Processing progress |
| 185 | +- Final result (success/failure) |
| 186 | +- Link to workflow run |
| 187 | + |
| 188 | +## Best Practices |
| 189 | + |
| 190 | +1. **For Contributors:** |
| 191 | + - Let workflows run before requesting review |
| 192 | + - Address AI suggestions when possible |
| 193 | + - Use `skip-ai` label sparingly |
| 194 | + |
| 195 | +2. **For Maintainers:** |
| 196 | + - Monitor workflow run times |
| 197 | + - Clear cache if builds are stale |
| 198 | + - Review AI suggestions before auto-merge |
| 199 | + |
| 200 | +3. **For Weavers:** |
| 201 | + - Ensure validation passes locally: `npm run validate` |
| 202 | + - Test indexing: `npm run index -- --validate` |
| 203 | + - Avoid large changes in single PRs (> 50 files) |
| 204 | + |
| 205 | +## Troubleshooting |
| 206 | + |
| 207 | +### Cache Issues |
| 208 | +```bash |
| 209 | +# Clear cache via workflow |
| 210 | +gh workflow run async-processing.yml -f full_reindex=true |
| 211 | +
|
| 212 | +# Or manually delete cache |
| 213 | +gh cache delete $(gh cache list | grep codex | awk '{print $1}') |
| 214 | +``` |
| 215 | + |
| 216 | +### Stuck Workflows |
| 217 | +```bash |
| 218 | +# Cancel running workflows |
| 219 | +gh run cancel $(gh run list --workflow=async-processing.yml --status=in_progress -q '.[0].databaseId') |
| 220 | +``` |
| 221 | + |
| 222 | +### View Logs |
| 223 | +```bash |
| 224 | +gh run view --log |
| 225 | +``` |
| 226 | + |
0 commit comments