Skip to content

Commit 83849bd

Browse files
committed
Refactor CI workflow to separate unit testing and code coverage jobs for improved clarity and maintainability
1 parent ad3df1a commit 83849bd

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ on:
55
outputs:
66
test-result:
77
description: "Test execution result"
8-
value: ${{ jobs.testing-and-coverage.outputs.result }}
8+
value: ${{ jobs.coverage-and-sonar.outputs.result }}
99

1010
env:
1111
MONGO_URI: ${{ secrets.MONGO_URI }}
1212
MONGO_USERNAME: ${{ secrets.MONGO_USERNAME }}
1313
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
1414

1515
jobs:
16-
testing-and-coverage:
17-
name: Testing and Code Coverage
16+
unit-testing:
17+
name: Unit Testing
1818
strategy:
1919
matrix:
2020
python-version: ["3.10", "3.11", "3.12"]
@@ -23,33 +23,22 @@ jobs:
2323
- os: windows-latest
2424
python-version: "3.10"
2525
runs-on: ${{ matrix.os }}
26-
outputs:
27-
result: ${{ steps.coverage.outcome }}
2826
steps:
2927
- name: Checkout Repository
3028
uses: actions/checkout@v5
31-
with:
32-
fetch-depth: 0 # Needed for SonarQube
3329

3430
- name: Setup Python Version - ${{ matrix.python-version }}
3531
uses: actions/setup-python@v5
3632
with:
3733
python-version: ${{ matrix.python-version }}
3834

3935
- name: Install Dependencies
40-
run: |
41-
pip install -r requirements.txt
42-
pip install pytest-cov
36+
run: pip install -r requirements.txt
4337

4438
- name: Unit Testing
4539
id: unit-tests
4640
run: pytest --junitxml=test-results.xml
4741

48-
- name: Run Code Coverage
49-
id: coverage
50-
continue-on-error: true
51-
run: pytest --cov=. --cov-report=xml --cov-report=html
52-
5342
- name: Archive Test Results
5443
if: always()
5544
uses: actions/upload-artifact@v4
@@ -58,18 +47,44 @@ jobs:
5847
path: test-results.xml
5948
retention-days: 1
6049

50+
coverage-and-sonar:
51+
name: Code Coverage and SonarQube
52+
needs: unit-testing
53+
runs-on: ubuntu-latest
54+
outputs:
55+
result: ${{ steps.coverage.outcome }}
56+
steps:
57+
- name: Checkout Repository
58+
uses: actions/checkout@v5
59+
with:
60+
fetch-depth: 0 # Needed for SonarQube
61+
62+
- name: Setup Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: "3.12"
66+
67+
- name: Install Dependencies
68+
run: |
69+
pip install -r requirements.txt
70+
pip install pytest-cov
71+
72+
- name: Run Code Coverage
73+
id: coverage
74+
continue-on-error: true
75+
run: pytest --cov=. --cov-report=xml --cov-report=html
76+
6177
- name: Archive Coverage Report
62-
if: always() && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
78+
if: always()
6379
uses: actions/upload-artifact@v4
6480
with:
65-
name: Coverage-Report-${{ matrix.os }}-${{ matrix.python-version }}
81+
name: Coverage-Report
6682
path: |
6783
coverage.xml
6884
htmlcov/
6985
retention-days: 1
7086

7187
- name: SonarQube Scan
72-
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
7388
uses: SonarSource/sonarqube-scan-action@v5
7489
with:
7590
args: >

0 commit comments

Comments
 (0)