Skip to content

Commit e9d8b24

Browse files
authored
chore: Add coverage reports to Python test pipelines (#237)
- Extend the existing unit and integration test pipelines to upload code coverage reports to Codecov. - Perform the coverage upload only for a single OS and a single Python version. - The specific test coverage-related calls are resolved in the specific repositories (SDK, Client, and Crawlee). - Relates: apify/crawlee-python#767
1 parent 9e24bed commit e9d8b24

File tree

7 files changed

+84
-39
lines changed

7 files changed

+84
-39
lines changed

.github/workflows/python_bump_and_update_changelog.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ jobs:
3131

3232
steps:
3333
- name: Checkout repository
34-
uses: actions/checkout@v4
34+
uses: actions/checkout@v6
3535
with:
3636
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
3737

3838
- name: Set up Python
39-
uses: actions/setup-python@v5
39+
uses: actions/setup-python@v6
4040
with:
4141
python-version: ${{ inputs.python_version }}
4242

4343
- name: Set up uv package manager
44-
uses: astral-sh/setup-uv@v6
44+
uses: astral-sh/setup-uv@v7
4545
with:
4646
python-version: ${{ inputs.python_version }}
4747

.github/workflows/python_docs_check.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
steps:
2121
- name: Checkout source code
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@v6
2323

2424
- name: Set up Node
2525
uses: actions/setup-node@v4
@@ -32,12 +32,12 @@ jobs:
3232
corepack prepare yarn@stable --activate
3333
3434
- name: Set up Python
35-
uses: actions/setup-python@v5
35+
uses: actions/setup-python@v6
3636
with:
3737
python-version: ${{ inputs.python_version }}
3838

3939
- name: Set up uv package manager
40-
uses: astral-sh/setup-uv@v6
40+
uses: astral-sh/setup-uv@v7
4141
with:
4242
python-version: ${{ inputs.python_version }}
4343

.github/workflows/python_integration_tests.yaml

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@ on:
44
workflow_call:
55
secrets:
66
APIFY_TEST_USER_PYTHON_SDK_API_TOKEN:
7-
description: API token of the Python testing user on Apify
7+
description: Apify API token for the primary Python SDK test user.
88
required: true
99
APIFY_TEST_USER_2_API_TOKEN:
10-
description: Second API token of different testing user on Apify. For multi-user test cases, such as sharing restricted access storage.
10+
description: Apify API token for a secondary test user, used in multi-user scenarios (e.g. sharing restricted storage).
1111
required: false
12-
12+
CODECOV_TOKEN:
13+
required: true
14+
description: Token for uploading coverage reports to Codecov.
1315
inputs:
1416
python-versions:
15-
description: List of Python versions to be used
17+
description: List of Python versions to be used (stringified JSON array).
18+
required: true
19+
type: string
20+
operating-systems:
21+
description: List of operating systems to be used.
22+
required: true
23+
type: string
24+
python-version-for-codecov:
25+
description: Python version to be used for codecov upload.
26+
required: true
27+
type: string
28+
operating-system-for-codecov:
29+
description: Operating system to be used for codecov upload.
1630
required: true
1731
type: string
1832

@@ -25,34 +39,46 @@ jobs:
2539
# Job to run integration tests from the main repository.
2640
integration_tests:
2741
name: Integration tests
28-
runs-on: ubuntu-latest
42+
2943
# Run this only for PRs from the main repository or for pushes to master. Skip otherwise.
3044
if: github.event.pull_request.head.repo.owner.login == 'apify' || github.ref == 'refs/heads/master'
3145

3246
strategy:
3347
matrix:
34-
python-version: ${{ fromJSON(inputs.python-versions)}}
48+
os: ${{ fromJSON(inputs.operating-systems) }}
49+
python-version: ${{ fromJSON(inputs.python-versions) }}
3550
max-parallel: 1 # No parallel tests to avoid exceeding API limits.
3651

52+
runs-on: ${{ matrix.os }}
53+
3754
steps:
3855
- name: Checkout repository
39-
uses: actions/checkout@v4
56+
uses: actions/checkout@v6
4057

4158
- name: Set up Python ${{ matrix.python-version }}
42-
uses: actions/setup-python@v5
59+
uses: actions/setup-python@v6
4360
with:
4461
python-version: ${{ matrix.python-version }}
4562

4663
- name: Set up uv package manager
47-
uses: astral-sh/setup-uv@v6
64+
uses: astral-sh/setup-uv@v7
4865
with:
4966
python-version: ${{ matrix.python-version }}
5067

5168
- name: Install Python dependencies
5269
run: make install-dev
5370

5471
- name: Run integration tests
55-
run: make INTEGRATION_TESTS_CONCURRENCY=8 integration-tests
72+
run: make INTEGRATION_TESTS_CONCURRENCY=8 integration-tests-cov
5673
env:
5774
APIFY_TEST_USER_API_TOKEN: ${{ secrets.APIFY_TEST_USER_PYTHON_SDK_API_TOKEN }}
5875
APIFY_TEST_USER_2_API_TOKEN: ${{ secrets.APIFY_TEST_USER_2_API_TOKEN }}
76+
77+
# Upload coverage only for the latest Python to avoid redundant uploads.
78+
- name: Upload integration test coverage
79+
if: ${{ matrix.os == inputs.operating-system-for-codecov && matrix.python-version == inputs.python-version-for-codecov }}
80+
uses: codecov/codecov-action@v5
81+
with:
82+
token: ${{ secrets.CODECOV_TOKEN }}
83+
files: coverage-integration.xml
84+
flags: integration

.github/workflows/python_lint_check.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call:
55
inputs:
66
python-versions:
7-
description: List of Python versions to be used
7+
description: List of Python versions to be used (stringified JSON array).
88
required: true
99
type: string
1010

@@ -18,15 +18,15 @@ jobs:
1818

1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v6
2222

2323
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v5
24+
uses: actions/setup-python@v6
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

2828
- name: Set up uv package manager
29-
uses: astral-sh/setup-uv@v6
29+
uses: astral-sh/setup-uv@v7
3030
with:
3131
python-version: ${{ matrix.python-version }}
3232

.github/workflows/python_type_check.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call:
55
inputs:
66
python-versions:
7-
description: List of Python versions to be used
7+
description: List of Python versions to be used (stringified JSON array).
88
required: true
99
type: string
1010

@@ -18,15 +18,15 @@ jobs:
1818

1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v6
2222

2323
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v5
24+
uses: actions/setup-python@v6
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

2828
- name: Set up uv package manager
29-
uses: astral-sh/setup-uv@v6
29+
uses: astral-sh/setup-uv@v7
3030
with:
3131
python-version: ${{ matrix.python-version }}
3232

.github/workflows/python_unit_tests.yaml

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@ on:
55
secrets:
66
httpbin_url:
77
required: false
8-
description: Used to set the HTTPBIN_URL environment variable
8+
description: URL that sets the HTTPBIN_URL environment variable.
9+
CODECOV_TOKEN:
10+
required: true
11+
description: Token for uploading coverage reports to Codecov.
912
inputs:
1013
python-versions:
11-
description: List of Python versions to be used
14+
description: List of Python versions to be used (stringified JSON array).
1215
required: true
1316
type: string
14-
os:
15-
description: List of operating systems to be used
16-
default: '["ubuntu-latest", "windows-latest"]'
17-
required: false
17+
operating-systems:
18+
description: List of operating systems to be used.
19+
required: true
20+
type: string
21+
python-version-for-codecov:
22+
description: Python version to be used for codecov upload.
23+
required: true
24+
type: string
25+
operating-system-for-codecov:
26+
description: Operating system to be used for codecov upload.
27+
required: true
1828
type: string
1929

2030
jobs:
@@ -23,8 +33,8 @@ jobs:
2333
strategy:
2434
fail-fast: false
2535
matrix:
26-
os: ${{ fromJSON(inputs.os)}}
27-
python-version: ${{ fromJSON(inputs.python-versions)}}
36+
os: ${{ fromJSON(inputs.operating-systems) }}
37+
python-version: ${{ fromJSON(inputs.python-versions) }}
2838
runs-on: ${{ matrix.os }}
2939
env:
3040
HTTPBIN_URL: ${{ secrets.httpbin_url || 'https://httpbin.org' }}
@@ -38,20 +48,29 @@ jobs:
3848
sudo killall Finder spindump ecosystemanalyticsd SystemUIServer NotificationCenter mds mds_stores mds_worker mdworker mdworker_shared || true
3949
4050
- name: Checkout repository
41-
uses: actions/checkout@v4
51+
uses: actions/checkout@v6
4252

4353
- name: Set up Python ${{ matrix.python-version }}
44-
uses: actions/setup-python@v5
54+
uses: actions/setup-python@v6
4555
with:
4656
python-version: ${{ matrix.python-version }}
4757

4858
- name: Set up uv package manager
49-
uses: astral-sh/setup-uv@v6
59+
uses: astral-sh/setup-uv@v7
5060
with:
5161
python-version: ${{ matrix.python-version }}
5262

5363
- name: Install Python dependencies
5464
run: make install-dev
5565

5666
- name: Run unit tests
57-
run: make unit-tests
67+
run: make unit-tests-cov
68+
69+
# Upload coverage only for the ubuntu-latest and latest Python to avoid redundant uploads.
70+
- name: Upload unit test coverage
71+
if: ${{ matrix.os == inputs.operating-system-for-codecov && matrix.python-version == inputs.python-version-for-codecov }}
72+
uses: codecov/codecov-action@v5
73+
with:
74+
token: ${{ secrets.CODECOV_TOKEN }}
75+
files: coverage-unit.xml
76+
flags: unit

prepare-pypi-distribution/action.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ runs:
2020
using: composite
2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@v6
2424
with:
2525
ref: ${{ inputs.ref }}
2626

2727
- name: Set up Python
28-
uses: actions/setup-python@v5
28+
uses: actions/setup-python@v6
2929
with:
3030
python-version: ${{ inputs.python_version }}
3131

3232
- name: Set up uv package manager
33-
uses: astral-sh/setup-uv@v6
33+
uses: astral-sh/setup-uv@v7
3434
with:
3535
python-version: ${{ inputs.python_version }}
3636

0 commit comments

Comments
 (0)