Skip to content

Commit 7e4e20b

Browse files
author
Jason Walker
committed
docs: add branch protection setup guide
- Add comprehensive guide for configuring branch protection - Include both automated and manual setup instructions - Document the complete PR-based workflow process - Explain all CI/CD status checks and their purposes - Provide troubleshooting guide for common issues Signed-off-by: Jason Walker <jason.walker1@aa.com>
1 parent 1357b15 commit 7e4e20b

1 file changed

Lines changed: 212 additions & 0 deletions

File tree

docs/branch-protection-setup.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Branch Protection Setup Guide
2+
3+
This guide will help you configure branch protection rules to enforce the PR-based workflow.
4+
5+
## Quick Setup
6+
7+
Run the provided script to automatically configure branch protection:
8+
9+
```bash
10+
./configure-branch-protection.sh
11+
```
12+
13+
This script will:
14+
- ✅ Create a `develop` branch (if it doesn't exist)
15+
- ✅ Configure branch protection rules for `main` branch
16+
- ✅ Optionally protect `develop` branch
17+
- ✅ Enable security features (Dependabot alerts, security updates)
18+
- ✅ Set up required status checks from CI/CD pipeline
19+
20+
## Manual Configuration
21+
22+
If you prefer to configure manually through GitHub's web interface:
23+
24+
### 1. Go to Repository Settings
25+
26+
Navigate to: `https://github.com/YOUR_USERNAME/REPO_NAME/settings/branches`
27+
28+
### 2. Add Branch Protection Rule
29+
30+
Click "Add rule" and configure:
31+
32+
**Branch name pattern:** `main`
33+
34+
**Protection settings:**
35+
- ✅ Require a pull request before merging
36+
- ✅ Require approvals: 1
37+
- ✅ Dismiss stale PR approvals when new commits are pushed
38+
- ✅ Require review from code owners (if you have CODEOWNERS file)
39+
- ✅ Require approval of the most recent reviewable push
40+
41+
- ✅ Require status checks to pass before merging
42+
- ✅ Require branches to be up to date before merging
43+
- **Required status checks:**
44+
- `spell-check`
45+
- `security-scan`
46+
- `lint-and-format`
47+
- `docs-check`
48+
- `build-validation`
49+
50+
- ✅ Require conversation resolution before merging
51+
- ✅ Require linear history
52+
- ✅ Include administrators
53+
- ❌ Allow force pushes
54+
- ❌ Allow deletions
55+
56+
### 3. Enable Security Features
57+
58+
Go to: `https://github.com/YOUR_USERNAME/REPO_NAME/settings/security_analysis`
59+
60+
Enable:
61+
- ✅ Dependabot alerts
62+
- ✅ Dependabot security updates
63+
- ✅ Secret scanning alerts (if available for your account type)
64+
65+
## Workflow After Branch Protection
66+
67+
### Feature Development
68+
69+
```bash
70+
# 1. Start from main branch
71+
git checkout main
72+
git pull origin main
73+
74+
# 2. Create feature branch
75+
git checkout -b feature/your-feature-name
76+
77+
# 3. Make changes and commit
78+
git add .
79+
git commit -sS -m "feat(scope): description of changes"
80+
81+
# 4. Push feature branch
82+
git push origin feature/your-feature-name
83+
84+
# 5. Create PR through GitHub web interface
85+
# - Fill out the PR template
86+
# - Wait for CI checks to pass
87+
# - Request review from team member
88+
# - Address any feedback
89+
# - Merge when approved and checks pass
90+
```
91+
92+
### Bug Fix Workflow
93+
94+
```bash
95+
# 1. Start from main branch
96+
git checkout main
97+
git pull origin main
98+
99+
# 2. Create fix branch
100+
git checkout -b fix/issue-description
101+
102+
# 3. Make changes and commit
103+
git add .
104+
git commit -sS -m "fix(scope): description of fix"
105+
106+
# 4. Push and create PR
107+
git push origin fix/issue-description
108+
# Create PR through GitHub web interface
109+
```
110+
111+
## CI/CD Pipeline Status Checks
112+
113+
The following checks must pass before merging:
114+
115+
### ✅ spell-check
116+
- Validates spelling in documentation files
117+
- Uses cspell with custom dictionary
118+
- Fails on unknown words or typos
119+
120+
### ✅ security-scan
121+
- Runs Grype vulnerability scanner
122+
- Scans for known vulnerabilities in dependencies
123+
- Uploads results to GitHub Security tab
124+
- Fails on medium+ severity findings
125+
126+
### ✅ lint-and-format
127+
- Validates markdown formatting
128+
- Checks for trailing whitespace
129+
- Validates YAML syntax
130+
- Ensures consistent documentation style
131+
132+
### ✅ docs-check
133+
- Verifies required documentation files exist
134+
- Checks for broken internal links
135+
- Validates documentation completeness
136+
137+
### ✅ build-validation
138+
- Validates shell script syntax
139+
- Checks file permissions
140+
- Ensures executables are properly configured
141+
142+
## Troubleshooting
143+
144+
### CI Checks Failing
145+
146+
**Spell Check Issues:**
147+
```bash
148+
# Run locally to see issues
149+
npm install -g cspell
150+
cspell "**/*.md" --config .cspell.json
151+
152+
# Add words to .cspell.json if needed
153+
```
154+
155+
**Security Scan Issues:**
156+
- Check Security tab for vulnerability details
157+
- Update dependencies to fix known issues
158+
- Consider suppressing false positives if necessary
159+
160+
**Lint Issues:**
161+
```bash
162+
# Run markdown linter locally
163+
npm install -g markdownlint-cli
164+
markdownlint "**/*.md" --config .markdownlint.json
165+
```
166+
167+
### Branch Protection Issues
168+
169+
**Can't push to main:**
170+
- This is expected! Create a feature branch instead
171+
- Use PR workflow for all changes
172+
173+
**Status checks not appearing:**
174+
- Ensure workflows have run at least once
175+
- Check Actions tab for workflow status
176+
- Verify workflow names match protection settings
177+
178+
**Admin bypass:**
179+
- Even admins must follow the workflow
180+
- This ensures consistent code quality
181+
- Use "Include administrators" setting to enforce
182+
183+
## Benefits of This Setup
184+
185+
**Quality Assurance**
186+
- All code reviewed before merging
187+
- Automated testing and validation
188+
- Consistent formatting and style
189+
190+
**Security**
191+
- Vulnerability scanning on every change
192+
- Secret detection prevents credential leaks
193+
- Dependency monitoring for supply chain security
194+
195+
**Collaboration**
196+
- Clear contribution guidelines
197+
- Standardized PR process
198+
- Documentation requirements enforced
199+
200+
**Maintainability**
201+
- Linear git history
202+
- Conventional commit messages
203+
- Comprehensive changelog tracking
204+
205+
**Automation**
206+
- Reduces manual oversight burden
207+
- Consistent quality checks
208+
- Automated security monitoring
209+
210+
---
211+
212+
This branch protection setup ensures high code quality while maintaining development velocity through automation and clear processes.

0 commit comments

Comments
 (0)