|
| 1 | +# Pull Request and Merge Requirements |
| 2 | + |
| 3 | +This repository has automated checks that must pass before pull requests can be merged to the main branch. |
| 4 | + |
| 5 | +## Required Checks |
| 6 | + |
| 7 | +### 1. Tests Must Pass ✅ |
| 8 | +- All unit tests must execute successfully |
| 9 | +- Tests are run using Maven: `mvn test` |
| 10 | +- Test failures will block the PR from being merged |
| 11 | + |
| 12 | +### 2. Code Coverage ≥ 80% 📊 |
| 13 | +- JaCoCo measures code coverage during test execution |
| 14 | +- Instruction coverage must be at least 80% |
| 15 | +- Coverage is checked using: `mvn jacoco:check` |
| 16 | +- Coverage reports are uploaded to [Codecov](https://codecov.io/gh/devops-thiago/MeuServidorHTTP) |
| 17 | + |
| 18 | +### 3. SonarCloud Quality Gate ✅ |
| 19 | +- Code quality analysis is performed by SonarCloud |
| 20 | +- Quality gate must pass (no critical/major issues) |
| 21 | +- Analysis is run using: `mvn sonar:sonar` |
| 22 | +- Results available at [SonarCloud](https://sonarcloud.io/project/overview?id=devops-thiago_MeuServidorHTTP) |
| 23 | + |
| 24 | +## Automated Workflows |
| 25 | + |
| 26 | +### PR Checks (`pr-checks.yml`) |
| 27 | +Triggered on every pull request to `master`/`main`: |
| 28 | +- Compiles code |
| 29 | +- Runs tests |
| 30 | +- Generates coverage report |
| 31 | +- Validates 80% coverage threshold |
| 32 | +- Uploads coverage to Codecov |
| 33 | +- Runs SonarCloud analysis |
| 34 | + |
| 35 | +### Merge Validation (`merge-checks.yml`) |
| 36 | +Triggered when code is merged to `master`/`main`: |
| 37 | +- Same checks as PR validation |
| 38 | +- Ensures main branch always meets quality standards |
| 39 | + |
| 40 | +### CI Workflow (`ci.yml`) |
| 41 | +General CI pipeline that runs on pushes and PRs: |
| 42 | +- Comprehensive validation |
| 43 | +- Caches Maven dependencies for faster builds |
| 44 | +- Reports results to external services |
| 45 | + |
| 46 | +## Branch Protection |
| 47 | + |
| 48 | +The main branch should be configured with the following protection rules: |
| 49 | +- Require pull request reviews |
| 50 | +- Require status checks to pass before merging: |
| 51 | + - `PR Validation - Tests, Coverage & Quality Gate` |
| 52 | +- Require branches to be up to date before merging |
| 53 | +- Restrict pushes that bypass pull requests |
| 54 | + |
| 55 | +## Local Development |
| 56 | + |
| 57 | +Before creating a PR, ensure your changes pass all checks: |
| 58 | + |
| 59 | +```bash |
| 60 | +# Run tests |
| 61 | +mvn clean test |
| 62 | + |
| 63 | +# Check coverage |
| 64 | +mvn jacoco:report jacoco:check |
| 65 | + |
| 66 | +# Run SonarCloud analysis (requires SONAR_TOKEN) |
| 67 | +mvn sonar:sonar |
| 68 | +``` |
| 69 | + |
| 70 | +## Secrets Configuration |
| 71 | + |
| 72 | +The following secrets must be configured in the repository: |
| 73 | +- `CODECOV_TOKEN`: Token for uploading coverage to Codecov |
| 74 | +- `SONAR_TOKEN`: Token for SonarCloud analysis |
| 75 | +- `GITHUB_TOKEN`: Automatically provided by GitHub Actions |
| 76 | + |
| 77 | +## Coverage Improvement |
| 78 | + |
| 79 | +If coverage falls below 80%, consider: |
| 80 | +1. Adding unit tests for uncovered code paths |
| 81 | +2. Removing unnecessary/unreachable code |
| 82 | +3. Testing edge cases and error conditions |
| 83 | +4. Mocking external dependencies in tests |
0 commit comments