forked from NVIDIA/TransformerEngine
-
Notifications
You must be signed in to change notification settings - Fork 30
354 lines (321 loc) · 16 KB
/
Copy pathall_tests_common.yml
File metadata and controls
354 lines (321 loc) · 16 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
name: Common All Tests
on:
workflow_call:
inputs:
platform:
required: true
type: string
description: Platform configuration name
run_unit_tests:
required: false
type: boolean
default: true
description: Whether to run unit tests in this workflow
run_integration_tests:
required: false
type: boolean
default: true
description: Whether to run integration tests in this workflow
jobs:
checkout_and_config:
name: checkout_and_config
defaults:
run:
shell: bash
runs-on: ubuntu-latest
outputs:
ci_image: ${{ steps.config.outputs.ci_image }}
container_pull_policy: ${{ steps.config.outputs.container_pull_policy }}
runs_on: ${{ steps.config.outputs.runs_on }}
container_volumes: ${{ steps.config.outputs.container_volumes }}
container_options: ${{ steps.config.outputs.container_options }}
device_types: ${{ steps.config.outputs.device_types }}
setup_script: ${{ steps.config.outputs.setup_script }}
checkout_submodules: ${{ steps.config.outputs.checkout_submodules }}
unit_test_matrix: ${{ steps.config.outputs.unit_test_matrix }}
unit_test_timeout_minutes: ${{ steps.config.outputs.unit_test_timeout_minutes }}
integration_test_matrix: ${{ steps.config.outputs.integration_test_matrix }}
coverage_enabled: ${{ steps.config.outputs.coverage_enabled }}
coverage_required: ${{ steps.config.outputs.coverage_required }}
coverage_sources: ${{ steps.config.outputs.coverage_sources }}
coverage_include: ${{ steps.config.outputs.coverage_include }}
coverage_omit: ${{ steps.config.outputs.coverage_omit }}
coverage_python: ${{ steps.config.outputs.coverage_python }}
test_artifact_enabled: ${{ steps.config.outputs.test_artifact_enabled }}
test_artifact_name: ${{ steps.config.outputs.test_artifact_name }}
test_artifact_path: ${{ steps.config.outputs.test_artifact_path }}
test_artifact_build_script: ${{ steps.config.outputs.test_artifact_build_script }}
test_artifact_runs_on: ${{ steps.config.outputs.test_artifact_runs_on }}
test_artifact_container_options: ${{ steps.config.outputs.test_artifact_container_options }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Load platform configuration
id: config
run: |
set -euo pipefail
PLATFORM="${{ inputs.platform }}"
CONFIG_FILE=".github/configs/${PLATFORM}.yml"
# Install mikefarah/yq (v4) for YAML parsing
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.45.1/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
/usr/local/bin/yq --version
echo "Loading configuration from $CONFIG_FILE"
# Read CI image
CI_IMAGE=$(yq '.ci_image' "$CONFIG_FILE")
echo "ci_image=$CI_IMAGE" >> $GITHUB_OUTPUT
CONTAINER_PULL_POLICY=$(yq '.container_pull_policy // "never"' "$CONFIG_FILE")
echo "container_pull_policy=$CONTAINER_PULL_POLICY" >> $GITHUB_OUTPUT
# Read runner labels and format as JSON array
RUNS_ON=$(yq '.runner_labels | tojson(0)' "$CONFIG_FILE")
echo "runs_on=$RUNS_ON" >> $GITHUB_OUTPUT
# Read container volumes and format as JSON array
VOLUMES=$(yq '.container_volumes | tojson(0)' "$CONFIG_FILE")
echo "container_volumes=$VOLUMES" >> $GITHUB_OUTPUT
# Read container options
OPTIONS=$(yq '.container_options' "$CONFIG_FILE")
echo "container_options=$OPTIONS" >> $GITHUB_OUTPUT
# Read device types
DEVICE_TYPES=$(yq '.device_types | tojson(0)' "$CONFIG_FILE")
echo "device_types=$DEVICE_TYPES" >> $GITHUB_OUTPUT
# Read setup script path
SETUP_SCRIPT=$(yq '.setup_script // ""' "$CONFIG_FILE")
echo "setup_script=$SETUP_SCRIPT" >> $GITHUB_OUTPUT
CHECKOUT_SUBMODULES=$(yq '.checkout_submodules // "false"' "$CONFIG_FILE")
echo "checkout_submodules=$CHECKOUT_SUBMODULES" >> $GITHUB_OUTPUT
TEST_ARTIFACT_ENABLED=$(yq '.test_artifact.enabled // false' "$CONFIG_FILE")
TEST_ARTIFACT_RUNS_ON=$(yq '(.test_artifact.runner_labels // .runner_labels) | tojson(0)' "$CONFIG_FILE")
TEST_ARTIFACT_OPTIONS=$(yq '.test_artifact.container_options // .container_options' "$CONFIG_FILE")
TEST_ARTIFACT_NAME=""
TEST_ARTIFACT_PATH=""
TEST_ARTIFACT_BUILD_SCRIPT=""
if [ "$TEST_ARTIFACT_ENABLED" = "true" ]; then
TEST_ARTIFACT_NAME="test-artifact-$PLATFORM"
TEST_ARTIFACT_PATH=$(yq '.test_artifact.path // ""' "$CONFIG_FILE")
TEST_ARTIFACT_BUILD_SCRIPT=$(yq '.test_artifact.build_script // ""' "$CONFIG_FILE")
if [ -z "$TEST_ARTIFACT_PATH" ] || [ -z "$TEST_ARTIFACT_BUILD_SCRIPT" ]; then
echo "test_artifact.path and test_artifact.build_script are required in $CONFIG_FILE" >&2
exit 1
fi
if [[ "$TEST_ARTIFACT_PATH" = /* ]]; then
echo "test_artifact.path must be repository-relative: $TEST_ARTIFACT_PATH" >&2
exit 1
fi
if [ ! -f "$TEST_ARTIFACT_BUILD_SCRIPT" ]; then
echo "test_artifact.build_script does not exist: $TEST_ARTIFACT_BUILD_SCRIPT" >&2
exit 1
fi
fi
echo "test_artifact_enabled=$TEST_ARTIFACT_ENABLED" >> $GITHUB_OUTPUT
echo "test_artifact_name=$TEST_ARTIFACT_NAME" >> $GITHUB_OUTPUT
echo "test_artifact_path=$TEST_ARTIFACT_PATH" >> $GITHUB_OUTPUT
echo "test_artifact_build_script=$TEST_ARTIFACT_BUILD_SCRIPT" >> $GITHUB_OUTPUT
echo "test_artifact_runs_on=$TEST_ARTIFACT_RUNS_ON" >> $GITHUB_OUTPUT
echo "test_artifact_container_options=$TEST_ARTIFACT_OPTIONS" >> $GITHUB_OUTPUT
UNIT_TEST_MATRIX=$(yq '.unit_test_matrix | tojson(0)' "$CONFIG_FILE")
if [ "$UNIT_TEST_MATRIX" = "null" ] || [ "$UNIT_TEST_MATRIX" = "[]" ]; then
echo "unit_test_matrix must be defined in $CONFIG_FILE" >&2
exit 1
fi
echo "unit_test_matrix=$UNIT_TEST_MATRIX" >> $GITHUB_OUTPUT
UNIT_TEST_TIMEOUT_MINUTES=$(yq '.unit_test_timeout_minutes // 90' "$CONFIG_FILE")
if ! [[ "$UNIT_TEST_TIMEOUT_MINUTES" =~ ^[1-9][0-9]*$ ]]; then
echo "unit_test_timeout_minutes must be a positive integer in $CONFIG_FILE" >&2
exit 1
fi
echo "unit_test_timeout_minutes=$UNIT_TEST_TIMEOUT_MINUTES" >> $GITHUB_OUTPUT
INTEGRATION_TEST_MATRIX=$(yq '.integration_test_matrix // [] | tojson(0)' "$CONFIG_FILE")
if [ "${{ inputs.run_integration_tests }}" = "true" ] && \
{ [ "$INTEGRATION_TEST_MATRIX" = "null" ] || [ "$INTEGRATION_TEST_MATRIX" = "[]" ]; }; then
echo "integration_test_matrix must be defined in $CONFIG_FILE" >&2
exit 1
fi
echo "integration_test_matrix=$INTEGRATION_TEST_MATRIX" >> $GITHUB_OUTPUT
COVERAGE_ENABLED=$(yq '.coverage.enabled // false' "$CONFIG_FILE")
COVERAGE_REQUIRED=$(yq '.coverage.required // false' "$CONFIG_FILE")
COVERAGE_SOURCES=$(yq '.coverage.sources // [] | join(",")' "$CONFIG_FILE")
COVERAGE_INCLUDE=$(yq '.coverage.include // [] | join(",")' "$CONFIG_FILE")
COVERAGE_OMIT=$(yq '.coverage.omit // [] | join(",")' "$CONFIG_FILE")
COVERAGE_PYTHON=$(yq '.coverage.python // "python3"' "$CONFIG_FILE")
if [ "$COVERAGE_ENABLED" = "true" ] && [ -z "$COVERAGE_SOURCES" ]; then
echo "coverage.sources must define at least one importable package or directory in $CONFIG_FILE" >&2
exit 1
fi
echo "coverage_enabled=$COVERAGE_ENABLED" >> $GITHUB_OUTPUT
echo "coverage_required=$COVERAGE_REQUIRED" >> $GITHUB_OUTPUT
echo "coverage_sources=$COVERAGE_SOURCES" >> $GITHUB_OUTPUT
echo "coverage_include=$COVERAGE_INCLUDE" >> $GITHUB_OUTPUT
echo "coverage_omit=$COVERAGE_OMIT" >> $GITHUB_OUTPUT
echo "coverage_python=$COVERAGE_PYTHON" >> $GITHUB_OUTPUT
build_test_artifact:
name: build_test_artifact
needs:
- checkout_and_config
if: needs.checkout_and_config.outputs.test_artifact_enabled == 'true'
runs-on: ${{ fromJson(needs.checkout_and_config.outputs.test_artifact_runs_on) }}
defaults:
run:
shell: bash
container:
image: ${{ needs.checkout_and_config.outputs.ci_image }}
volumes: ${{ fromJson(needs.checkout_and_config.outputs.container_volumes) }}
options: --pull ${{ needs.checkout_and_config.outputs.container_pull_policy }} ${{ needs.checkout_and_config.outputs.test_artifact_container_options }}
steps:
- name: Prepare checkout environment
run: |
/usr/bin/git config --global safe.directory '*'
/usr/bin/git config --global --unset-all credential.helper 2>/dev/null || true
/usr/bin/git config --system --unset-all credential.helper 2>/dev/null || true
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: ${{ needs.checkout_and_config.outputs.checkout_submodules }}
set-safe-directory: true
- name: Build test artifact
env:
TE_CI_ARTIFACT_DIR: ${{ github.workspace }}/${{ needs.checkout_and_config.outputs.test_artifact_path }}
run: bash "$GITHUB_WORKSPACE/${{ needs.checkout_and_config.outputs.test_artifact_build_script }}"
timeout-minutes: 90
- name: Upload test artifact
uses: actions/upload-artifact@v4
with:
name: ${{ needs.checkout_and_config.outputs.test_artifact_name }}
path: ${{ github.workspace }}/${{ needs.checkout_and_config.outputs.test_artifact_path }}/*.whl
if-no-files-found: error
retention-days: 1
overwrite: true
unit_tests:
name: unit_tests
if: >-
always() && inputs.run_unit_tests &&
needs.checkout_and_config.result == 'success' &&
(needs.build_test_artifact.result == 'success' ||
needs.build_test_artifact.result == 'skipped')
needs:
- checkout_and_config
- build_test_artifact
strategy:
fail-fast: false
matrix:
device: ${{ fromJson(needs.checkout_and_config.outputs.device_types) }}
uses: ./.github/workflows/unit_tests_common.yml
with:
platform: ${{ inputs.platform }}
device: ${{ matrix.device }}
image: ${{ needs.checkout_and_config.outputs.ci_image }}
container_pull_policy: ${{ needs.checkout_and_config.outputs.container_pull_policy }}
runs_on: ${{ needs.checkout_and_config.outputs.runs_on }}
container_volumes: ${{ needs.checkout_and_config.outputs.container_volumes }}
container_options: ${{ needs.checkout_and_config.outputs.container_options }}
setup_script: ${{ needs.checkout_and_config.outputs.setup_script }}
checkout_submodules: ${{ needs.checkout_and_config.outputs.checkout_submodules }}
test_matrix: ${{ needs.checkout_and_config.outputs.unit_test_matrix }}
timeout_minutes: ${{ fromJson(needs.checkout_and_config.outputs.unit_test_timeout_minutes) }}
coverage_enabled: ${{ fromJson(needs.checkout_and_config.outputs.coverage_enabled) }}
coverage_required: ${{ fromJson(needs.checkout_and_config.outputs.coverage_required) }}
coverage_sources: ${{ needs.checkout_and_config.outputs.coverage_sources }}
coverage_include: ${{ needs.checkout_and_config.outputs.coverage_include }}
coverage_omit: ${{ needs.checkout_and_config.outputs.coverage_omit }}
coverage_python: ${{ needs.checkout_and_config.outputs.coverage_python }}
test_artifact_name: ${{ needs.checkout_and_config.outputs.test_artifact_name }}
test_artifact_path: ${{ needs.checkout_and_config.outputs.test_artifact_path }}
unit_tests_complete:
name: unit_tests_complete
needs:
- unit_tests
runs-on: ubuntu-latest
if: always() && inputs.run_unit_tests
steps:
- name: Check unit tests result
run: |
if [ "${{ needs.unit_tests.result }}" != "success" ] && \
[ "${{ needs.unit_tests.result }}" != "skipped" ]; then
echo "❌ Unit tests failed: ${{ needs.unit_tests.result }}"
exit 1
fi
echo "✅ Unit tests passed"
integration_tests:
name: integration_tests
if: >-
always() && inputs.run_integration_tests &&
needs.checkout_and_config.result == 'success' &&
(needs.build_test_artifact.result == 'success' ||
needs.build_test_artifact.result == 'skipped') &&
(needs.unit_tests_complete.result == 'success' ||
needs.unit_tests_complete.result == 'skipped')
needs:
- checkout_and_config
- build_test_artifact
- unit_tests_complete
strategy:
fail-fast: false
matrix:
device: ${{ fromJson(needs.checkout_and_config.outputs.device_types) }}
uses: ./.github/workflows/integration_tests_common.yml
with:
device: ${{ matrix.device }}
image: ${{ needs.checkout_and_config.outputs.ci_image }}
container_pull_policy: ${{ needs.checkout_and_config.outputs.container_pull_policy }}
runs_on: ${{ needs.checkout_and_config.outputs.runs_on }}
container_volumes: ${{ needs.checkout_and_config.outputs.container_volumes }}
container_options: ${{ needs.checkout_and_config.outputs.container_options }}
setup_script: ${{ needs.checkout_and_config.outputs.setup_script }}
checkout_submodules: ${{ needs.checkout_and_config.outputs.checkout_submodules }}
test_matrix: ${{ needs.checkout_and_config.outputs.integration_test_matrix }}
test_artifact_name: ${{ needs.checkout_and_config.outputs.test_artifact_name }}
test_artifact_path: ${{ needs.checkout_and_config.outputs.test_artifact_path }}
integration_tests_complete:
name: integration_tests_complete
if: always() && inputs.run_integration_tests
needs:
- integration_tests
runs-on: ubuntu-latest
steps:
- name: Check integration tests result
run: |
if [ "${{ needs.integration_tests.result }}" != "success" ] && \
[ "${{ needs.integration_tests.result }}" != "skipped" ]; then
echo "❌ Integration tests failed: ${{ needs.integration_tests.result }}"
exit 1
fi
echo "✅ Integration tests passed"
all_tests_complete:
defaults:
run:
shell: bash
needs:
- checkout_and_config
- build_test_artifact
- unit_tests_complete
- integration_tests_complete
runs-on: ubuntu-latest
if: always()
steps:
- name: Verify all tests passed
run: |
# Check all test jobs (skip if not run)
failed=false
if [ "${{ needs.checkout_and_config.result }}" != "success" ]; then
echo "Checkout or platform configuration failed: ${{ needs.checkout_and_config.result }}"
failed=true
fi
if [ "${{ needs.build_test_artifact.result }}" != "success" ] && \
[ "${{ needs.build_test_artifact.result }}" != "skipped" ]; then
echo "Test artifact build failed or was cancelled: ${{ needs.build_test_artifact.result }}"
failed=true
fi
if [ "${{ needs.unit_tests_complete.result }}" != "success" ] && \
[ "${{ needs.unit_tests_complete.result }}" != "skipped" ]; then
echo "❌ Unit tests failed or cancelled: ${{ needs.unit_tests_complete.result }}"
failed=true
fi
if [ "${{ needs.integration_tests_complete.result }}" != "success" ] && \
[ "${{ needs.integration_tests_complete.result }}" != "skipped" ]; then
echo "❌ Integration tests failed or cancelled: ${{ needs.integration_tests_complete.result }}"
failed=true
fi
if [ "$failed" = "true" ]; then
exit 1
fi
echo "✅ All tests completed successfully!"