-
Notifications
You must be signed in to change notification settings - Fork 17
248 lines (204 loc) · 6.6 KB
/
pr-tests.yml
File metadata and controls
248 lines (204 loc) · 6.6 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: PR Tests
on:
pull_request:
branches: [ main, master, develop ]
jobs:
test-py312:
name: Python 3.12 Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
- name: Display Python and package information
run: |
source .venv/bin/activate
python --version
tox --version
which python
- name: Run Python 3.12 non-GPU tests
run: |
source .venv/bin/activate
tox -e py312-nogpu-cov
test-py311:
name: Python 3.11 Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
- name: Display Python and package information
run: |
source .venv/bin/activate
python --version
tox --version
which python
- name: Run Python 3.11 non-GPU tests
run: |
source .venv/bin/activate
# we will still be able to print out the coverage in this run, it just
# won't be able to upload it to codecov
tox -e py311-nogpu-cov
test-coverage:
name: Test with Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
- name: Display Python and package information
run: |
source .venv/bin/activate
python --version
tox --version
which python
- name: Run tests with coverage
run: |
source .venv/bin/activate
tox -e py312-nogpu-cov
- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: Red-Hat-AI-Innovation-Team/mini_trainer
fail_ci_if_error: true
verbose: true
format-check:
name: Format Check (Non-blocking)
runs-on: ubuntu-latest
continue-on-error: true # This makes the job non-required
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history to compare with base branch
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
- name: Check code formatting on changed files
run: |
source .venv/bin/activate
# Get the base branch (target branch of the PR)
BASE_BRANCH="${{ github.base_ref }}"
echo "Comparing against base branch: origin/$BASE_BRANCH"
# Get list of changed Python files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT origin/$BASE_BRANCH...HEAD | grep '\.py$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No Python files changed in this PR"
exit 0
fi
echo "Changed Python files:"
echo "$CHANGED_FILES"
# Run ruff format check on changed files only
echo "$CHANGED_FILES" | xargs ruff format --check
lint:
name: Linting (Non-blocking)
runs-on: ubuntu-latest
continue-on-error: true # This makes the job non-required
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history to compare with base branch
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e ".[dev]"
- name: Run linting checks on changed files
run: |
source .venv/bin/activate
# Get the base branch (target branch of the PR)
BASE_BRANCH="${{ github.base_ref }}"
echo "Comparing against base branch: origin/$BASE_BRANCH"
# Get list of changed Python files
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT origin/$BASE_BRANCH...HEAD | grep '\.py$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No Python files changed in this PR"
exit 0
fi
echo "Changed Python files:"
echo "$CHANGED_FILES"
# Run ruff on changed files only
echo "$CHANGED_FILES" | xargs ruff check
# Summary job to ensure required tests pass
tests-passed:
name: All Required Tests Passed
needs: [test-py312, test-py311, test-coverage]
runs-on: ubuntu-latest
if: always()
steps:
- name: Check test results
run: |
if [[ "${{ needs.test-py312.result }}" != "success" || \
"${{ needs.test-py311.result }}" != "success" || \
"${{ needs.test-coverage.result }}" != "success" ]]; then
echo "One or more required tests failed!"
echo "Python 3.12 tests: ${{ needs.test-py312.result }}"
echo "Python 3.11 tests: ${{ needs.test-py311.result }}"
echo "Coverage tests: ${{ needs.test-coverage.result }}"
exit 1
else
echo "All required tests passed successfully!"
echo "Format check: ${{ needs.format-check.result }} (non-blocking)"
echo "Linting: ${{ needs.lint.result }} (non-blocking)"
fi