Skip to content

Commit 642abbb

Browse files
authored
chore: generate coverage report so sonarqube coverage gate is valid (#393)
# Pull Request ## 🧾 Ticket Link <!-- Add the Jira ticket link here --> https://nhsd-jira.digital.nhs.uk/browse/NPA-XXXX --- ## 📄 Description/Summary of Changes <!-- Describe the changes made in this PR. Include the purpose/scope/impact of the changes --> - Any change to sandbox code was failing the sonarqube test coverage check because it has no coverage report to check. This PR adds a test run to the pipeline, which generates the coverage report. It this updates the sonar config to tell it where to look for the coverage report to check the change in covered lines. --- ## 🧪 Developer Testing Carried Out <!-- Describe what tests (automated/unit/manual etc.) have been done for the ticket. Include: --> <!-- - Any tests added/updated --> <!-- - Evidence that each acceptance criterion from the Jira ticket is met --> <!-- - Evidence of tests running eg. link to github workflow with tests passing or screenshot of tests running locally --> - <!-- Briefly describe the testing carried out in this PR --> --- ## 📋 PR Principles <!-- Principles we as a team follow when conducting a PR --> - Keep PRs Small and Focused: Ensure the PR addresses a single task or feature to make it easier to review. - Multiple PRs for one Ticket: When splitting work into multiple PRs, clearly describe what this PR addresses and outline the remaining work to complete the ticket. - Ensure Tests Are Included: Add or update unit, integration, or end-to-end tests to cover the changes made. - Follow Coding Standards: Ensure the code adheres to the team's coding guidelines and best practices. - Resolve Comments Promptly: If you raise a comment, ensure you follow up and resolve it before approving the PR to maintain clarity and ensure comments are addressed. - Foster Learning: PR reviews are an opportunity to share knowledge, provide constructive feedback, and encourage a collaborative environment. ## 🏷️ Naming Conventions Reminder Please ensure the following naming conventions are followed: - PR title follows the format: `NPA-XXXX: <short-description>` - Branch name follows the convention: `<type>/NPA-XXXX/<short-description>` - Commit messages follow the template: `NPA-XXXX: <short-description>`
1 parent 54162df commit 642abbb

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

.github/workflows/sonarcloud.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ jobs:
1717
- uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20+
- name: Install poetry
21+
run: pipx install poetry
22+
- uses: actions/setup-python@v5
23+
with:
24+
python-version: "3.13"
25+
cache: "poetry"
26+
- name: Install Sandbox dependencies
27+
working-directory: sandbox
28+
run: poetry install
29+
- name: Generate Sandbox coverage report
30+
run: |
31+
VENV_PATH=$(cd sandbox && poetry env info --path)
32+
"$VENV_PATH/bin/pytest" --cov=sandbox/api --cov-config=sandbox/.coveragerc \
33+
--cov-report=xml:sandbox/coverage.xml sandbox/api/tests
2034
- name: SonarCloud Scan
2135
uses: SonarSource/sonarqube-scan-action@fd88b7d7ccbaefd23d8f36f73b59db7a3d246602 # v6
2236
env:

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ sandbox/archive/
2929
sandbox/.hypothesis/
3030

3131
.tool-versions
32+
33+
34+
# unit test coverage reports
35+
.coverage
36+
sandbox/.coverage
37+
sandbox/coverage.xml
38+
htmlcov
39+
lambdas/htmlcov

sandbox/.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
relative_files = True

sonar-project.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ sonar.projectKey=NHSDigital_validated-relationships-service-api
22
sonar.organization=nhsdigital
33
sonar.exclusions=**/node_modules/**,**/dist/**,**/tests/**
44
sonar.sources=sandbox
5-
sonar.python.version=3.13
5+
sonar.python.version=3.13
6+
sonar.python.coverage.reportPaths=sandbox/coverage.xml

0 commit comments

Comments
 (0)