Skip to content

Commit ad3df1a

Browse files
committed
Refactor CI workflow to consolidate unit testing and code coverage jobs, improving clarity and efficiency
1 parent 52a2f80 commit ad3df1a

File tree

1 file changed

+26
-59
lines changed

1 file changed

+26
-59
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
name: CI - Testing and Code Coverage
2-
32
on:
43
workflow_dispatch:
54
workflow_call:
65
outputs:
76
test-result:
87
description: "Test execution result"
9-
value: ${{ jobs.code-coverage.outputs.result }}
8+
value: ${{ jobs.testing-and-coverage.outputs.result }}
109

1110
env:
1211
MONGO_URI: ${{ secrets.MONGO_URI }}
1312
MONGO_USERNAME: ${{ secrets.MONGO_USERNAME }}
1413
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
1514

1615
jobs:
17-
unit-testing:
18-
name: Unit Testing
16+
testing-and-coverage:
17+
name: Testing and Code Coverage
1918
strategy:
2019
matrix:
2120
python-version: ["3.10", "3.11", "3.12"]
@@ -24,85 +23,53 @@ jobs:
2423
- os: windows-latest
2524
python-version: "3.10"
2625
runs-on: ${{ matrix.os }}
27-
26+
outputs:
27+
result: ${{ steps.coverage.outcome }}
2828
steps:
2929
- name: Checkout Repository
3030
uses: actions/checkout@v5
31+
with:
32+
fetch-depth: 0 # Needed for SonarQube
3133

32-
- name: Setup Puthon Version - ${{ matrix.python-version }}
34+
- name: Setup Python Version - ${{ matrix.python-version }}
3335
uses: actions/setup-python@v5
3436
with:
3537
python-version: ${{ matrix.python-version }}
36-
38+
3739
- name: Install Dependencies
38-
run: pip install -r requirements.txt
40+
run: |
41+
pip install -r requirements.txt
42+
pip install pytest-cov
3943
4044
- name: Unit Testing
41-
id: Python-unit-testing-step
45+
id: unit-tests
4246
run: pytest --junitxml=test-results.xml
4347

44-
- name: Archive Test Result
45-
if: always()
46-
uses: actions/upload-artifact@v4
47-
with:
48-
name: Mocha-Test-Result-${{ matrix.os }}-${{ matrix.python-version }}
49-
path: test-results.xml
50-
retention-days: 1
51-
52-
code-coverage:
53-
name: Code Coverage
54-
needs: unit-testing
55-
runs-on: ubuntu-latest
56-
outputs:
57-
result: ${{ steps.coverage.outcome }}
58-
steps:
59-
- name: Checkout Repository
60-
uses: actions/checkout@v5
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: pip install -r requirements.txt
69-
7048
- name: Run Code Coverage
7149
id: coverage
7250
continue-on-error: true
7351
run: pytest --cov=. --cov-report=xml --cov-report=html
7452

75-
- name: Archive Coverage Report
53+
- name: Archive Test Results
7654
if: always()
7755
uses: actions/upload-artifact@v4
7856
with:
79-
name: Coverage-Report
80-
path: coverage/
57+
name: Test-Results-${{ matrix.os }}-${{ matrix.python-version }}
58+
path: test-results.xml
8159
retention-days: 1
82-
sonarqube:
83-
name: SonarQube
84-
needs: code-coverage
85-
runs-on: ubuntu-latest
86-
steps:
87-
- uses: actions/checkout@v5
88-
with:
89-
fetch-depth: 0
9060

91-
- name: Setup Python
92-
uses: actions/setup-python@v4
61+
- name: Archive Coverage Report
62+
if: always() && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
63+
uses: actions/upload-artifact@v4
9364
with:
94-
python-version: "3.12"
95-
96-
- name: Install Dependencies
97-
run: |
98-
pip install -r requirements.txt
99-
pip install pytest-cov
100-
101-
- name: Run Code Coverage
102-
id: coverage
103-
continue-on-error: true
104-
run: pytest --cov=. --cov-report=html --cov-report=xml
65+
name: Coverage-Report-${{ matrix.os }}-${{ matrix.python-version }}
66+
path: |
67+
coverage.xml
68+
htmlcov/
69+
retention-days: 1
70+
10571
- name: SonarQube Scan
72+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
10673
uses: SonarSource/sonarqube-scan-action@v5
10774
with:
10875
args: >

0 commit comments

Comments
 (0)