|
| 1 | +# GitHub Actions CI/CD |
| 2 | + |
| 3 | +This directory contains GitHub Actions workflows for continuous integration and code quality checks. |
| 4 | + |
| 5 | +## Workflows |
| 6 | + |
| 7 | +### 🧪 test.yml - Test Suite |
| 8 | +**Trigger:** Push to any branch (Python changes only), PRs to main (Python changes only) |
| 9 | + |
| 10 | +**What it does:** |
| 11 | +- Matrix testing on Python 3.11 and 3.12 |
| 12 | +- Runs pytest with coverage |
| 13 | +- Uploads coverage to Codecov (Python 3.11 only) |
| 14 | + |
| 15 | +**Required:** ✅ Must pass for PR merge |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +### 🎨 lint.yml - Code Quality |
| 20 | +**Trigger:** Push to any branch (Python changes only), PRs to main (Python changes only) |
| 21 | + |
| 22 | +**What it does:** |
| 23 | +- **Ruff**: Fast Python linter (checks imports, unused variables, etc.) |
| 24 | +- **Black**: Code formatting verification (100 char line length) |
| 25 | +- **mypy**: Static type checking |
| 26 | + |
| 27 | +**Required:** ⚠️ Non-blocking but should be addressed |
| 28 | + |
| 29 | +**Fix issues:** |
| 30 | +```bash |
| 31 | +# Auto-fix formatting |
| 32 | +black . |
| 33 | + |
| 34 | +# Auto-fix some linting issues |
| 35 | +ruff check --fix . |
| 36 | + |
| 37 | +# Check types |
| 38 | +mypy . --ignore-missing-imports |
| 39 | +``` |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +### 🔒 security.yml - Security Scanning |
| 44 | +**Trigger:** Push to main (Python changes only), PRs (Python changes only), Weekly (Sundays) |
| 45 | + |
| 46 | +**What it does:** |
| 47 | +- **Bandit**: Scans for common security issues |
| 48 | +- **Safety**: Checks for vulnerable dependencies |
| 49 | +- Uploads security reports as artifacts |
| 50 | + |
| 51 | +**Required:** ⚠️ Review findings, critical issues must be fixed |
| 52 | + |
| 53 | +--- |
| 54 | + |
| 55 | +### 📊 pr-metrics.yml - PR Analysis |
| 56 | +**Trigger:** PR opened/updated |
| 57 | + |
| 58 | +**What it does:** |
| 59 | +- Analyzes PR size (small/medium/large/extra-large) for Python code |
| 60 | +- Calculates test-to-production code ratio |
| 61 | +- Measures commit quality: |
| 62 | + - Large commits (>100 lines): Target <20% |
| 63 | + - Sprawling commits (>5 files): Target <10% |
| 64 | +- Posts analysis comment on PR |
| 65 | + |
| 66 | +**Based on:** [PDCA Framework](https://github.com/kenjudy/human-ai-collaboration-process) |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Configuration Files |
| 71 | + |
| 72 | +Configuration can be added to `pyproject.toml` for: |
| 73 | +- **Black** (formatter) |
| 74 | +- **Ruff** (linter) |
| 75 | +- **mypy** (type checker) |
| 76 | +- **pytest** (test runner) |
| 77 | +- **coverage** (coverage reporting) |
| 78 | +- **Bandit** (security scanner) |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Local Development |
| 83 | + |
| 84 | +### Run all quality checks locally: |
| 85 | + |
| 86 | +```bash |
| 87 | +# Activate virtual environment |
| 88 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 89 | + |
| 90 | +# Run tests with coverage |
| 91 | +pytest . --cov=. --cov-report=term-missing |
| 92 | + |
| 93 | +# Check formatting |
| 94 | +black --check . |
| 95 | + |
| 96 | +# Auto-format code |
| 97 | +black . |
| 98 | + |
| 99 | +# Lint code |
| 100 | +ruff check . |
| 101 | + |
| 102 | +# Auto-fix linting issues |
| 103 | +ruff check --fix . |
| 104 | + |
| 105 | +# Type check |
| 106 | +mypy . --ignore-missing-imports |
| 107 | + |
| 108 | +# Security scan |
| 109 | +bandit -r . --exclude ./.venv,./.pytest_cache |
| 110 | +safety check |
| 111 | +``` |
| 112 | + |
| 113 | +### Pre-commit checks: |
| 114 | + |
| 115 | +Before committing, run: |
| 116 | +```bash |
| 117 | +black . && ruff check --fix . && pytest . |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## Quality Targets |
| 123 | + |
| 124 | +### Test Coverage |
| 125 | +- **Target:** >80% |
| 126 | +- **Location:** All Python files |
| 127 | + |
| 128 | +### Commit Quality |
| 129 | +- **Large commits:** <20% (>100 production lines) |
| 130 | +- **Sprawling commits:** <10% (>5 files changed) |
| 131 | +- **Test ratio:** 0.5-2.0 (test lines : production lines) |
| 132 | + |
| 133 | +### PR Size |
| 134 | +- **Small:** <100 production lines |
| 135 | +- **Medium:** 100-200 lines |
| 136 | +- **Large:** 200-500 lines (harder to review) |
| 137 | +- **Extra-large:** >500 lines (should be split) |
| 138 | + |
| 139 | +### Code Quality |
| 140 | +- **Complexity:** Max 10 (ruff C901) |
| 141 | +- **Line length:** 100 characters (black) |
| 142 | +- **Import organization:** Automatic (ruff I) |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Troubleshooting |
| 147 | + |
| 148 | +### CI failures |
| 149 | + |
| 150 | +**Tests failing:** |
| 151 | +```bash |
| 152 | +# Run locally with same environment |
| 153 | +LANGSMITH_API_KEY=test-api-key pytest . -v |
| 154 | +``` |
| 155 | + |
| 156 | +**Coverage too low:** |
| 157 | +- Add tests for untested code |
| 158 | +- Check coverage report: `pytest --cov=. --cov-report=html` |
| 159 | +- Open `htmlcov/index.html` in browser |
| 160 | + |
| 161 | +**Linting failures:** |
| 162 | +```bash |
| 163 | +# See what needs fixing |
| 164 | +ruff check . |
| 165 | + |
| 166 | +# Auto-fix |
| 167 | +ruff check --fix . |
| 168 | +black . |
| 169 | +``` |
| 170 | + |
| 171 | +**Security issues:** |
| 172 | +```bash |
| 173 | +# See details |
| 174 | +bandit -r . --exclude ./.venv,./.pytest_cache -f screen |
| 175 | +safety check |
| 176 | + |
| 177 | +# Review and fix critical issues |
| 178 | +# Update dependencies if needed |
| 179 | +``` |
| 180 | + |
| 181 | +--- |
| 182 | + |
| 183 | +## Badges |
| 184 | + |
| 185 | +Add to README.md: |
| 186 | + |
| 187 | +```markdown |
| 188 | + |
| 189 | + |
| 190 | + |
| 191 | +[](https://codecov.io/gh/YOUR_USERNAME/export-langsmith-data) |
| 192 | +``` |
| 193 | + |
| 194 | +--- |
| 195 | + |
| 196 | +## References |
| 197 | + |
| 198 | +- [PDCA Framework for AI-Assisted Code Generation](https://github.com/kenjudy/human-ai-collaboration-process) |
| 199 | +- [Ruff Documentation](https://docs.astral.sh/ruff/) |
| 200 | +- [Black Documentation](https://black.readthedocs.io/) |
| 201 | +- [pytest Documentation](https://docs.pytest.org/) |
0 commit comments