Skip to content

Commit 8a8d955

Browse files
authored
test: start tracking test coverage (#3061)
* test: start tracking test coverage * improvements * more
1 parent d5271fe commit 8a8d955

3 files changed

Lines changed: 86 additions & 8 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Add comment about test coverage to PRs
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- "Test / kreuzberg"
7+
types: [completed]
8+
9+
jobs:
10+
comment:
11+
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request'
12+
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write
15+
steps:
16+
- name: Get integration name from workflow name
17+
id: integration
18+
run: |
19+
# Workflow names follow "Test / <name>" convention
20+
echo "name=$(echo '${{ github.event.workflow_run.name }}' | sed 's/Test \/ //')" >> $GITHUB_OUTPUT
21+
22+
- uses: py-cov-action/python-coverage-comment-action@7188638f871f721a365d644f505d1ff3df20d683 # v3.40
23+
with:
24+
GITHUB_TOKEN: ${{ github.token }}
25+
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
26+
SUBPROJECT_ID: ${{ steps.integration.outputs.name }}
27+
COMMENT_ARTIFACT_NAME: coverage-comment-${{ steps.integration.outputs.name }}

.github/workflows/kreuzberg.yml

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,55 @@ on:
1010
- "integrations/kreuzberg/**"
1111
- "!integrations/kreuzberg/*.md"
1212
- ".github/workflows/kreuzberg.yml"
13+
push:
14+
branches:
15+
- main
16+
paths:
17+
- "integrations/kreuzberg/**"
18+
- "!integrations/kreuzberg/*.md"
19+
- ".github/workflows/kreuzberg.yml"
1320

1421
defaults:
1522
run:
1623
working-directory: integrations/kreuzberg
1724

1825
concurrency:
19-
group: kreuzberg-${{ github.head_ref }}
26+
group: kreuzberg-${{ github.head_ref || github.sha }}
2027
cancel-in-progress: true
2128

2229
env:
2330
PYTHONUNBUFFERED: "1"
2431
FORCE_COLOR: "1"
32+
TEST_MATRIX_OS: '["ubuntu-latest", "windows-latest", "macos-latest"]'
33+
TEST_MATRIX_PYTHON: '["3.10", "3.14"]'
2534

2635
jobs:
36+
compute-test-matrix:
37+
runs-on: ubuntu-slim
38+
defaults:
39+
run:
40+
working-directory: .
41+
outputs:
42+
os: ${{ steps.set.outputs.os }}
43+
python-version: ${{ steps.set.outputs.python-version }}
44+
steps:
45+
- id: set
46+
run: |
47+
echo "os=${{ github.event_name == 'push' && '["ubuntu-latest"]' || env.TEST_MATRIX_OS }}" >> $GITHUB_OUTPUT
48+
echo "python-version=${{ github.event_name == 'push' && '["3.10"]' || env.TEST_MATRIX_PYTHON }}" >> $GITHUB_OUTPUT
49+
2750
run:
2851
name: Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
52+
needs: compute-test-matrix
2953
runs-on: ${{ matrix.os }}
54+
permissions:
55+
contents: write
56+
pull-requests: write
3057
strategy:
3158
fail-fast: false
3259
matrix:
33-
os: [ubuntu-latest, windows-latest, macos-latest]
34-
python-version: ["3.10", "3.14"]
60+
os: ${{ fromJSON(needs.compute-test-matrix.outputs.os) }}
61+
python-version: ${{ fromJSON(needs.compute-test-matrix.outputs.python-version) }}
3562

3663
steps:
3764
- name: Support longpaths
@@ -50,13 +77,36 @@ jobs:
5077
run: pip install hatch
5178

5279
- name: Lint
53-
if: matrix.python-version == '3.10' && runner.os == 'Linux'
80+
if: github.event_name != 'push' && matrix.python-version == '3.10' && runner.os == 'Linux'
5481
run: hatch run fmt-check && hatch run test:types
5582

56-
- name: Run tests
57-
run: hatch run test:cov-retry
83+
- name: Run unit tests
84+
run: hatch run test:unit-cov-retry
85+
86+
# On PR: generates coverage comment artifact. On push to main: stores coverage baseline on data branch.
87+
- name: Store unit tests coverage
88+
if: matrix.python-version == '3.10' && runner.os == 'Linux' && github.event_name != 'schedule'
89+
uses: py-cov-action/python-coverage-comment-action@7188638f871f721a365d644f505d1ff3df20d683 # v3.40
90+
with:
91+
GITHUB_TOKEN: ${{ github.token }}
92+
COVERAGE_PATH: integrations/kreuzberg
93+
SUBPROJECT_ID: kreuzberg
94+
COMMENT_ARTIFACT_NAME: coverage-comment-kreuzberg
95+
96+
- name: Run integration tests
97+
run: hatch run test:integration-cov-append-retry
98+
99+
- name: Store combined coverage
100+
if: github.event_name == 'push'
101+
uses: py-cov-action/python-coverage-comment-action@7188638f871f721a365d644f505d1ff3df20d683 # v3.40
102+
with:
103+
GITHUB_TOKEN: ${{ github.token }}
104+
COVERAGE_PATH: integrations/kreuzberg
105+
SUBPROJECT_ID: kreuzberg-combined
106+
COMMENT_ARTIFACT_NAME: coverage-comment-kreuzberg-combined
58107

59108
- name: Run unit tests with lowest direct dependencies
109+
if: github.event_name != 'push'
60110
run: |
61111
hatch run uv pip compile pyproject.toml --resolution lowest-direct --output-file requirements_lowest_direct.txt
62112
hatch -e test env run -- uv pip install -r requirements_lowest_direct.txt
@@ -69,7 +119,6 @@ jobs:
69119
hatch -e test env run -- uv pip install git+https://github.com/deepset-ai/haystack.git@main
70120
hatch run test:unit
71121
72-
73122
notify-slack-on-failure:
74123
needs: run
75124
if: failure() && github.event_name == 'schedule'

integrations/kreuzberg/pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ dependencies = [
6666
unit = 'pytest -m "not integration" {args:tests}'
6767
integration = 'pytest -m "integration" {args:tests}'
6868
all = 'pytest {args:tests}'
69-
cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
69+
unit-cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x -m "not integration" {args:tests}'
70+
integration-cov-append-retry = 'pytest --cov=haystack_integrations --cov-append --reruns 3 --reruns-delay 30 -x -m "integration" {args:tests}'
7071
types = "mypy -p haystack_integrations.components.converters.kreuzberg {args}"
7172

7273
[tool.ruff]
@@ -161,6 +162,7 @@ asyncio_default_fixture_loop_scope = "function"
161162
source = ["haystack_integrations"]
162163
branch = true
163164
parallel = false
165+
relative_files = true
164166

165167
[tool.coverage.report]
166168
omit = ["*/tests/*", "*/__init__.py"]

0 commit comments

Comments
 (0)