-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (145 loc) · 4.58 KB
/
Copy pathci-python.yml
File metadata and controls
161 lines (145 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: CI - Python
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
workflow_call:
inputs:
python-version:
description: Python version to use
required: false
type: string
default: "3.12"
python-versions:
description: "JSON array of versions for matrix testing (overrides python-version)"
required: false
type: string
default: ""
working-dir:
description: Working directory
required: false
type: string
default: "."
run-lint:
description: Run ruff linting
required: false
type: boolean
default: true
run-test:
description: Run pytest
required: false
type: boolean
default: true
run-type-check:
description: Run mypy type checking
required: false
type: boolean
default: false
test-command:
description: Custom test command (default pytest)
required: false
type: string
default: ""
coverage-threshold:
description: Minimum coverage percentage (0 to disable)
required: false
type: number
default: 0
upload-coverage:
description: Upload coverage report as artifact
required: false
type: boolean
default: false
permissions:
contents: read
jobs:
lint:
if: ${{ inputs.run-lint }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Ruff lint + format check
uses: chartboost/ruff-action@v1
with:
args: check --output-format=github
src: ${{ inputs.working-dir }}
- name: Ruff format check
uses: chartboost/ruff-action@v1
with:
args: format --check
src: ${{ inputs.working-dir }}
type-check:
if: ${{ inputs.run-type-check }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: pip
- name: Install deps
working-directory: ${{ inputs.working-dir }}
run: |
pip install mypy
for f in requirements.txt requirements-dev.txt; do
[ -f "$f" ] && pip install -r "$f"
done
[ -f pyproject.toml ] && pip install -e ".[dev]" 2>/dev/null || true
- name: Run mypy
working-directory: ${{ inputs.working-dir }}
run: mypy . --ignore-missing-imports
test:
if: ${{ inputs.run-test }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ${{ inputs.python-versions != '' && fromJSON(inputs.python-versions) || fromJSON(format('["{0}"]', inputs.python-version)) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install deps
working-directory: ${{ inputs.working-dir }}
run: |
for f in requirements.txt requirements-dev.txt; do
[ -f "$f" ] && pip install -r "$f"
done
[ -f pyproject.toml ] && pip install -e ".[dev]" 2>/dev/null || true
pip install pytest pytest-cov
- name: Run tests
working-directory: ${{ inputs.working-dir }}
env:
TEST_COMMAND: ${{ inputs.test-command }}
COVERAGE_THRESHOLD: ${{ inputs.coverage-threshold }}
UPLOAD_COVERAGE: ${{ inputs.upload-coverage }}
run: |
set -uo pipefail
if [ -n "$TEST_COMMAND" ]; then
eval "$TEST_COMMAND"
else
ARGS="--tb=short -q"
if [ "$COVERAGE_THRESHOLD" != "0" ] || [ "$UPLOAD_COVERAGE" = "true" ]; then
ARGS="$ARGS --cov --cov-report=xml --cov-report=term --cov-fail-under=$COVERAGE_THRESHOLD"
fi
rc=0
python -m pytest $ARGS || rc=$?
# pytest exits 5 when it collects no tests at all
if [ "$rc" -eq 5 ]; then
echo "::notice::No tests collected, skipping test job"
rc=0
fi
exit "$rc"
fi
- name: Upload coverage
if: ${{ inputs.upload-coverage && always() }}
uses: actions/upload-artifact@v4
with:
name: coverage-py${{ matrix.python-version }}
path: ${{ inputs.working-dir }}/coverage.xml
retention-days: 7