|
| 1 | +# Branch Protection Settings for augint-api |
| 2 | + |
| 3 | +This document outlines the recommended GitHub Repository Ruleset settings for the augint-api serverless Infrastructure as Code (IaC) project. |
| 4 | + |
| 5 | +## Repository Ruleset Configuration |
| 6 | + |
| 7 | +**Navigate to:** Settings → Rules → Rulesets → **Create repository ruleset** |
| 8 | + |
| 9 | +**Note:** This repository uses GitHub's new Repository Rulesets (not classic branch protection rules) for enhanced flexibility and better auto-merge integration. |
| 10 | + |
| 11 | +## Dev Branch Protection Ruleset |
| 12 | + |
| 13 | +Create a ruleset named **"Development Branch Protection"** for auto-merge functionality. |
| 14 | + |
| 15 | +#### Ruleset Settings |
| 16 | + |
| 17 | +**General Settings:** |
| 18 | +- **Ruleset Name**: `Development Branch Protection` |
| 19 | +- **Enforcement Status**: `Active` |
| 20 | +- **Target Branches**: `Include by pattern` → `dev` |
| 21 | +- **Bypass List**: |
| 22 | + - Add GitHub Apps that need bypass (e.g., `github-actions`) |
| 23 | + - Add repository administrators for emergency access |
| 24 | + |
| 25 | +#### Protection Rules |
| 26 | + |
| 27 | +✅ **Restrict deletions** |
| 28 | +- Prevents accidental deletion of the dev branch |
| 29 | + |
| 30 | +✅ **Require pull request before merging** |
| 31 | +- **Required number of approvals**: `0` (auto-merge handles this) |
| 32 | +- **Dismiss stale PR approvals when new commits are pushed**: `Yes` |
| 33 | +- **Require review from CODEOWNERS**: `No` (for development speed) |
| 34 | + |
| 35 | +✅ **Require status checks to pass before merging** |
| 36 | +- **Require branches to be up to date before merging**: `Yes` |
| 37 | +- **Required status checks** (exact names from serverless-gitops.yaml): |
| 38 | + - `Security scanning (SAST, dependencies, licenses)` |
| 39 | + - `Run unit tests (no infrastructure)` |
| 40 | + - `Infrastructure validation (SAM validate, cfn-lint)` |
| 41 | + - `Deploy serverless API` |
| 42 | + - `Run integration tests (against deployed API)` |
| 43 | + - `Run E2E tests and smoke tests (all environments)` |
| 44 | + |
| 45 | +✅ **Require conversation resolution before merging** |
| 46 | +- Ensures all discussions are resolved before merge |
| 47 | + |
| 48 | +✅ **Block force pushes** |
| 49 | +- Maintains clean git history and prevents accidental overwrites |
| 50 | + |
| 51 | +#### Advanced Settings |
| 52 | + |
| 53 | +**Bypass permissions:** |
| 54 | +- Repository administrators can bypass in emergencies |
| 55 | +- GitHub Actions can bypass for automated processes |
| 56 | + |
| 57 | +## Main Branch Protection Ruleset |
| 58 | + |
| 59 | +Create a second ruleset named **"Production Branch Protection"** for production releases. |
| 60 | + |
| 61 | +#### Ruleset Settings |
| 62 | + |
| 63 | +**General Settings:** |
| 64 | +- **Ruleset Name**: `Production Branch Protection` |
| 65 | +- **Enforcement Status**: `Active` |
| 66 | +- **Target Branches**: `Include by pattern` → `main` |
| 67 | + |
| 68 | +#### Protection Rules |
| 69 | + |
| 70 | +✅ **Restrict deletions** |
| 71 | +- Prevents accidental deletion of main branch |
| 72 | + |
| 73 | +✅ **Restrict pushes** |
| 74 | +- Only administrators can push directly (emergency situations only) |
| 75 | + |
| 76 | +✅ **Require pull request before merging** |
| 77 | +- **Required number of approvals**: `1` (manual oversight for production) |
| 78 | +- **Dismiss stale PR approvals when new commits are pushed**: `Yes` |
| 79 | +- **Require review from CODEOWNERS**: `Yes` |
| 80 | + |
| 81 | +✅ **Require status checks to pass before merging** |
| 82 | +- **Require branches to be up to date before merging**: `Yes` |
| 83 | +- **Required status checks** (same as dev branch): |
| 84 | + - `Security scanning (SAST, dependencies, licenses)` |
| 85 | + - `Run unit tests (no infrastructure)` |
| 86 | + - `Infrastructure validation (SAM validate, cfn-lint)` |
| 87 | + - `Deploy serverless API` |
| 88 | + - `Run integration tests (against deployed API)` |
| 89 | + - `Run E2E tests and smoke tests (all environments)` |
| 90 | + |
| 91 | +✅ **Require conversation resolution before merging** |
| 92 | + |
| 93 | +✅ **Block force pushes** |
| 94 | + |
| 95 | +## Repository Settings |
| 96 | + |
| 97 | +**Navigate to:** Settings → General → Pull Requests |
| 98 | + |
| 99 | +### Required Settings for Auto-Merge |
| 100 | + |
| 101 | +✅ **Allow auto-merge** |
| 102 | +- Enables GitHub's native auto-merge functionality |
| 103 | + |
| 104 | +✅ **Allow squash merging** |
| 105 | +- Maintains clean commit history (recommended) |
| 106 | + |
| 107 | +❌ **Allow merge commits** (disabled) |
| 108 | +- Prevents noisy merge commits in history |
| 109 | + |
| 110 | +❌ **Allow rebase merging** (disabled) |
| 111 | +- Reduces merge strategy complexity |
| 112 | + |
| 113 | +✅ **Always suggest updating pull request branches** |
| 114 | +- Helps keep branches up to date |
| 115 | + |
| 116 | +✅ **Automatically delete head branches** |
| 117 | +- Cleans up feature branches after merge |
| 118 | + |
| 119 | +## Status Check Names Reference |
| 120 | + |
| 121 | +The exact status check names that must be configured in the ruleset (from serverless-gitops.yaml): |
| 122 | + |
| 123 | +```yaml |
| 124 | +Required Status Checks: |
| 125 | +- "Security scanning (SAST, dependencies, licenses)" |
| 126 | +- "Run unit tests (no infrastructure)" |
| 127 | +- "Infrastructure validation (SAM validate, cfn-lint)" |
| 128 | +- "Deploy serverless API" |
| 129 | +- "Run integration tests (against deployed API)" |
| 130 | +- "Run E2E tests and smoke tests (all environments)" |
| 131 | +``` |
| 132 | +
|
| 133 | +**Important:** Status check names must match exactly as they appear in the GitHub Actions workflow. Any mismatch will prevent auto-merge from working. |
| 134 | +
|
| 135 | +## Differences from augint-library |
| 136 | +
|
| 137 | +The augint-api project has additional quality gates compared to augint-library due to its Infrastructure as Code (IaC) nature: |
| 138 | +
|
| 139 | +| Project | Quality Gates | Additional Requirements | |
| 140 | +|---------|---------------|-------------------------| |
| 141 | +| **augint-library** | 4 gates | Unit tests, security, compliance, pre-commit | |
| 142 | +| **augint-api** | 6 gates | + Infrastructure validation, deployment, integration/E2E tests | |
| 143 | +
|
| 144 | +This reflects the higher complexity and risk associated with serverless infrastructure deployment. |
| 145 | +
|
| 146 | +## Auto-Merge Integration |
| 147 | +
|
| 148 | +The ruleset configuration works seamlessly with the auto-merge job in `serverless-gitops.yaml`: |
| 149 | + |
| 150 | +1. **Development branches** push to GitHub |
| 151 | +2. **Pipeline runs** all 6 quality gates |
| 152 | +3. **Auto-merge job** enables GitHub auto-merge if all gates pass |
| 153 | +4. **GitHub auto-merge** waits for all required status checks |
| 154 | +5. **Automatic merge** happens when all conditions are met |
| 155 | + |
| 156 | +## Troubleshooting |
| 157 | + |
| 158 | +### Common Ruleset Issues |
| 159 | + |
| 160 | +**Auto-merge not working:** |
| 161 | +1. Verify all 6 status checks are configured with exact names |
| 162 | +2. Check that auto-merge is enabled in repository settings |
| 163 | +3. Ensure the development branch is up to date |
| 164 | +4. Confirm the PR targets the `dev` branch |
| 165 | + |
| 166 | +**Status checks not found:** |
| 167 | +1. Check job names in `.github/workflows/serverless-gitops.yaml` |
| 168 | +2. Verify the pipeline has run at least once to establish status checks |
| 169 | +3. Update ruleset with exact status check names from successful pipeline runs |
| 170 | + |
| 171 | +**Emergency access needed:** |
| 172 | +1. Repository administrators can bypass rulesets |
| 173 | +2. Use "Override branch protection" option in PR interface |
| 174 | +3. Document reason for bypass in PR comments |
| 175 | + |
| 176 | +## Validation |
| 177 | + |
| 178 | +To verify your ruleset configuration: |
| 179 | + |
| 180 | +1. Create a test branch: `feat/issue-test-auto-merge` |
| 181 | +2. Make a small change and push |
| 182 | +3. Create PR targeting `dev` branch |
| 183 | +4. Verify all 6 status checks appear and must pass |
| 184 | +5. Confirm auto-merge enables when all checks pass |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +This configuration ensures robust protection for both development and production branches while enabling efficient auto-merge workflows for routine development. |
0 commit comments