Skip to content

Commit b178409

Browse files
committed
Add reusable Python tests workflow
1 parent 812d7c4 commit b178409

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/python-tests.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Reusable Python Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
additional_commands:
7+
description: 'Additional commands to run after installing dependencies'
8+
required: false
9+
type: string
10+
default: ''
11+
make_command:
12+
description: 'Make/build command to run'
13+
required: false
14+
type: string
15+
default: ''
16+
17+
jobs:
18+
test:
19+
name: Python
20+
runs-on: ${{ matrix.os }}
21+
defaults:
22+
run:
23+
shell: bash
24+
steps:
25+
- name: Cancel Previous Runs
26+
uses: styfle/[email protected]
27+
with:
28+
access_token: ${{ github.token }}
29+
30+
- name: Checkout
31+
uses: actions/[email protected]
32+
with:
33+
submodules: true
34+
35+
- name: Determine working directory
36+
id: workdir
37+
run: |
38+
if [ -d "python" ]; then
39+
echo "dir=python" >> $GITHUB_OUTPUT
40+
else
41+
echo "dir=." >> $GITHUB_OUTPUT
42+
fi
43+
44+
- name: Install uv and set the python version
45+
uses: astral-sh/setup-uv@v6
46+
with:
47+
python-version: ${{ matrix.python }}
48+
version: "0.8.15"
49+
50+
- name: Install dependencies
51+
working-directory: ${{ steps.workdir.outputs.dir }}
52+
run: |
53+
uv venv
54+
uv pip install -r pyproject.toml --extra test
55+
56+
- name: Additional commands
57+
if: ${{ inputs.additional_commands != '' }}
58+
working-directory: ${{ steps.workdir.outputs.dir }}
59+
run: ${{ inputs.additional_commands }}
60+
61+
- name: Make/build
62+
if: ${{ inputs.make_command != '' }}
63+
working-directory: ${{ steps.workdir.outputs.dir }}
64+
run: ${{ inputs.make_command }}
65+
66+
- name: Run tests
67+
working-directory: ${{ steps.workdir.outputs.dir }}
68+
run: |
69+
uv run --no-sync python -m pytest -xv --cov --cov-report=xml --cov-branch
70+
71+
- name: Upload coverage to Codecov
72+
uses: codecov/[email protected]
73+
with:
74+
token: ${{ secrets.CODECOV_TOKEN }}
75+
working-directory: ${{ steps.workdir.outputs.dir }}
76+
fail_ci_if_error: false
77+
flags: python-tests
78+
name: codecov-umbrella
79+
verbose: true

0 commit comments

Comments
 (0)