|
| 1 | +# Branching Strategy |
| 2 | + |
| 3 | +This repository follows a **main/next** branching model to ensure stable releases while allowing for continuous development. |
| 4 | + |
| 5 | +## Branch Overview |
| 6 | + |
| 7 | +### `main` Branch |
| 8 | +- **Purpose**: Production-ready code |
| 9 | +- **Protection**: Only accepts PRs from `next` branch (enforced by CI) |
| 10 | +- **Releases**: Stable releases (e.g., v1.2.0, v1.3.0) |
| 11 | +- **CI/CD**: Full test suite, security scans, and release automation |
| 12 | + |
| 13 | +### `next` Branch |
| 14 | +- **Purpose**: Integration branch for upcoming releases |
| 15 | +- **Protection**: Accepts PRs from feature branches |
| 16 | +- **Releases**: Pre-releases (e.g., v1.3.0-next.1, v1.3.0-next.2) |
| 17 | +- **CI/CD**: Full test suite and security scans |
| 18 | + |
| 19 | +## Workflow |
| 20 | + |
| 21 | +### For Feature Development |
| 22 | + |
| 23 | +1. **Create your feature branch from `next`**: |
| 24 | + ```bash |
| 25 | + git checkout next |
| 26 | + git pull origin next |
| 27 | + git checkout -b feature/my-feature |
| 28 | + ``` |
| 29 | + |
| 30 | +2. **Develop and test your changes**: |
| 31 | + ```bash |
| 32 | + # Make your changes |
| 33 | + git add . |
| 34 | + git commit -m "feat: add new feature" |
| 35 | + ``` |
| 36 | + |
| 37 | +3. **Submit PR to `next` branch**: |
| 38 | + - Target branch: `next` |
| 39 | + - Get review and approval |
| 40 | + - Merge to `next` |
| 41 | + |
| 42 | +4. **Testing in `next`**: |
| 43 | + - Your changes are now in `next` |
| 44 | + - Pre-release version created (e.g., v1.3.0-next.1) |
| 45 | + - Can be tested in staging environments |
| 46 | + |
| 47 | +### For Release to Production |
| 48 | + |
| 49 | +1. **Create PR from `next` to `main`**: |
| 50 | + - Only when `next` is stable and ready for release |
| 51 | + - Typically done by maintainers |
| 52 | + - Triggers full CI/CD pipeline |
| 53 | + |
| 54 | +2. **Merge to `main`**: |
| 55 | + - Creates stable release (e.g., v1.3.0) |
| 56 | + - Publishes to PyPI (if configured) |
| 57 | + - Updates documentation |
| 58 | + |
| 59 | +3. **Sync `next` with `main`** (if needed): |
| 60 | + ```bash |
| 61 | + git checkout next |
| 62 | + git merge main |
| 63 | + git push origin next |
| 64 | + ``` |
| 65 | + |
| 66 | +## Branch Protection Rules |
| 67 | + |
| 68 | +### Automated Protection (CI Enforcement) |
| 69 | +The `check-source-branch` job in `.github/workflows/ci.yaml` enforces that: |
| 70 | +- PRs to `main` must come from `next` branch only |
| 71 | +- PRs violating this rule will **fail CI** and cannot be merged |
| 72 | +- All other CI jobs are blocked until this check passes |
| 73 | +- Helpful comment is posted explaining the violation |
| 74 | + |
| 75 | +### How It Works |
| 76 | +When you create a PR: |
| 77 | +1. The `check-source-branch` job runs first |
| 78 | +2. If targeting `main` from any branch other than `next`, it fails |
| 79 | +3. All other jobs (tests, security scans, etc.) are skipped |
| 80 | +4. A comment explains how to fix the issue |
| 81 | + |
| 82 | +### Recommended GitHub Settings |
| 83 | +Configure these in **Settings → Branches → Branch protection rules**: |
| 84 | + |
| 85 | +#### For `main` branch: |
| 86 | +- ✅ Require pull request reviews before merging (1 approval) |
| 87 | +- ✅ Require status checks to pass before merging |
| 88 | + - Required checks: `check-source-branch`, `test`, `test-e2e`, `security` |
| 89 | +- ✅ Require branches to be up to date before merging |
| 90 | +- ✅ Do not allow bypassing the above settings |
| 91 | + |
| 92 | +#### For `next` branch: |
| 93 | +- ✅ Require pull request reviews before merging (1 approval) |
| 94 | +- ✅ Require status checks to pass before merging |
| 95 | + - Required checks: `test`, `test-e2e`, `security` |
| 96 | +- ✅ Require branches to be up to date before merging |
| 97 | + |
| 98 | +## Hotfixes |
| 99 | + |
| 100 | +For urgent production fixes: |
| 101 | + |
| 102 | +1. **Create hotfix branch from `main`**: |
| 103 | + ```bash |
| 104 | + git checkout main |
| 105 | + git pull origin main |
| 106 | + git checkout -b hotfix/critical-bug |
| 107 | + ``` |
| 108 | + |
| 109 | +2. **Make minimal fix**: |
| 110 | + ```bash |
| 111 | + # Fix the bug |
| 112 | + git add . |
| 113 | + git commit -m "fix: critical security issue" |
| 114 | + ``` |
| 115 | + |
| 116 | +3. **Submit PR to `next` first**: |
| 117 | + - Even hotfixes should go through `next` |
| 118 | + - Allows for testing in pre-release |
| 119 | + - Merge to `next`, then immediately create PR to `main` |
| 120 | + |
| 121 | +4. **Fast-track if critical**: |
| 122 | + - Get expedited review |
| 123 | + - Merge `next` → `main` quickly after verification |
| 124 | + |
| 125 | +## Troubleshooting |
| 126 | + |
| 127 | +### "check-source-branch failed" Error |
| 128 | + |
| 129 | +**Problem**: You created a PR from your feature branch directly to `main`. |
| 130 | + |
| 131 | +**Solution**: |
| 132 | +1. Close the PR to `main` |
| 133 | +2. Create a new PR from your feature branch to `next` |
| 134 | +3. After merge to `next`, a maintainer will create PR from `next` → `main` |
| 135 | + |
| 136 | +### Merge Conflicts |
| 137 | + |
| 138 | +If `next` has conflicts with `main`: |
| 139 | +```bash |
| 140 | +git checkout next |
| 141 | +git merge main |
| 142 | +# Resolve conflicts |
| 143 | +git commit |
| 144 | +git push origin next |
| 145 | +``` |
| 146 | + |
| 147 | +## Benefits of This Strategy |
| 148 | + |
| 149 | +1. **Stability**: `main` always contains tested, production-ready code |
| 150 | +2. **Continuous Integration**: `next` allows ongoing development without blocking |
| 151 | +3. **Pre-release Testing**: Features can be tested in staging before production |
| 152 | +4. **Clear History**: Easy to see what's in production vs. what's coming next |
| 153 | +5. **Automated Protection**: CI enforcement prevents accidental direct merges to `main` |
| 154 | +6. **No Manual Oversight**: Violations are caught automatically before any reviewer sees them |
| 155 | + |
| 156 | +## Questions? |
| 157 | + |
| 158 | +If you have questions about the branching strategy, please: |
| 159 | +- Check existing GitHub discussions |
| 160 | +- Ask in PR comments |
| 161 | +- Contact the maintainers |
0 commit comments