Skip to content

Commit 9638381

Browse files
authored
ci: add coverage report on PRs (#837)
1 parent 84fdbbe commit 9638381

4 files changed

Lines changed: 96 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ jobs:
2323
secrets:
2424
UIPATH_URL: ${{ secrets.UIPATH_URL }}
2525
UIPATH_CLIENT_ID: ${{ secrets.UIPATH_CLIENT_ID }}
26-
UIPATH_CLIENT_SECRET: ${{ secrets.UIPATH_CLIENT_SECRET }}
26+
UIPATH_CLIENT_SECRET: ${{ secrets.UIPATH_CLIENT_SECRET }}
27+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/test.yml

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ name: Test
33
on:
44
workflow_call:
55
secrets:
6-
UIPATH_URL:
7-
required: true
8-
UIPATH_CLIENT_ID:
9-
required: true
10-
UIPATH_CLIENT_SECRET:
11-
required: true
6+
UIPATH_URL:
7+
required: true
8+
UIPATH_CLIENT_ID:
9+
required: true
10+
UIPATH_CLIENT_SECRET:
11+
required: true
12+
SONAR_TOKEN:
13+
required: false
1214

1315
jobs:
1416
test:
@@ -41,19 +43,66 @@ jobs:
4143
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version')"
4244
uses: actions/setup-python@v5
4345
with:
44-
python-version-file: ".python-version"
46+
python-version: ${{ matrix.python-version }}
4547

4648
- name: Install dependencies
4749
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version')"
48-
run: uv sync --all-extras
50+
run: uv sync --all-extras --python ${{ matrix.python-version }}
4951

5052
- name: Run tests
51-
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version')"
52-
run: uv run pytest
53+
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version') && !(matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13')"
54+
run: uv run --python ${{ matrix.python-version }} pytest
55+
env:
56+
UIPATH_URL: ${{ secrets.UIPATH_URL }}
57+
UIPATH_CLIENT_ID: ${{ secrets.UIPATH_CLIENT_ID }}
58+
UIPATH_CLIENT_SECRET: ${{ secrets.UIPATH_CLIENT_SECRET }}
59+
60+
- name: Run tests with coverage
61+
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13'"
62+
run: uv run --python ${{ matrix.python-version }} pytest --cov-report=xml --cov-report=html --tb=short
5363
env:
5464
UIPATH_URL: ${{ secrets.UIPATH_URL }}
5565
UIPATH_CLIENT_ID: ${{ secrets.UIPATH_CLIENT_ID }}
5666
UIPATH_CLIENT_SECRET: ${{ secrets.UIPATH_CLIENT_SECRET }}
5767

68+
- name: Upload coverage HTML report
69+
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13' && always()"
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: coverage-html-report
73+
path: htmlcov/
74+
retention-days: 30
75+
76+
- name: Upload coverage XML report
77+
if: "!contains(github.event.pull_request.labels.*.name, 'test-core-dev-version') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.13' && always()"
78+
uses: actions/upload-artifact@v4
79+
with:
80+
name: coverage-xml-report
81+
path: coverage.xml
82+
retention-days: 30
83+
5884
continue-on-error: true
5985

86+
sonarcloud:
87+
name: SonarCloud
88+
needs: test
89+
runs-on: ubuntu-latest
90+
if: always() && needs.test.result != 'failure'
91+
permissions:
92+
contents: read
93+
steps:
94+
- name: Checkout
95+
uses: actions/checkout@v4
96+
with:
97+
fetch-depth: 0
98+
99+
- name: Download coverage
100+
uses: actions/download-artifact@v4
101+
continue-on-error: true
102+
with:
103+
name: coverage-xml-report
104+
105+
- name: SonarCloud Scan
106+
uses: SonarSource/sonarqube-scan-action@2f77a1ec69fb1d595b06f35ab27e97605bdef703 # v5
107+
env:
108+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

pyproject.toml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,31 @@ disallow_untyped_defs = false
127127
[tool.pytest.ini_options]
128128
testpaths = ["tests"]
129129
python_files = "test_*.py"
130-
addopts = "-ra -q"
130+
addopts = "-ra -q --cov=src/uipath_langchain --cov-report=term-missing"
131131
asyncio_default_fixture_loop_scope = "function"
132132
asyncio_mode = "auto"
133133

134+
[tool.coverage.run]
135+
source = ["src/uipath_langchain"]
136+
relative_files = true
137+
omit = [
138+
"*/tests/*",
139+
"*/__pycache__/*",
140+
"*/site-packages/*",
141+
"*/conftest.py",
142+
]
143+
144+
[tool.coverage.report]
145+
show_missing = true
146+
precision = 2
147+
exclude_lines = [
148+
"pragma: no cover",
149+
"def __repr__",
150+
"raise NotImplementedError",
151+
"if TYPE_CHECKING:",
152+
"@(abc\\.)?abstractmethod",
153+
]
154+
134155
[[tool.uv.index]]
135156
name = "testpypi"
136157
url = "https://test.pypi.org/simple/"

sonar-project.properties

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sonar.projectKey=UiPath_uipath-langchain-python
2+
sonar.organization=ui
3+
sonar.host.url=https://sonarcloud.io
4+
5+
sonar.sources=src/uipath_langchain
6+
sonar.tests=tests
7+
8+
sonar.python.version=3.11,3.12,3.13
9+
sonar.python.coverage.reportPaths=coverage.xml
10+
11+
sonar.exclusions=**/samples/**,**/testcases/**,**/template/**
12+
13+
sonar.sourceEncoding=UTF-8

0 commit comments

Comments
 (0)