-
Notifications
You must be signed in to change notification settings - Fork 393
256 lines (221 loc) · 8.75 KB
/
tests_diff.yml
File metadata and controls
256 lines (221 loc) · 8.75 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
name: Runnability tests on changed examples
concurrency:
group: pr-tests-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
log_level:
description: 'Log level to use for pytest.'
type: choice
options:
- ERROR
- INFO
- DEBUG
default: INFO
required: false
platform:
description: 'Platform to use for testing. By default both RVC2 and RVC4 are used but you can use only one by passing only `rvc2` or `rvc4`(use lowercase).'
default: "all"
required: false
strict_mode:
description: "If set to 'yes', tests will fail on DepthAI warnings."
type: choice
options:
- "yes"
- "no"
default: "no"
required: false
subtests:
description: "Specify if should run only peripheral, only standalone or both"
type: choice
options:
- "all"
- "peripheral"
- "standalone"
default: "all"
required: false
pull_request:
types: [opened, synchronize, reopened, labeled]
branches:
- main
jobs:
precheck:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- name: Evaluate trigger condition
id: check
run: |
EVENT_NAME="${{ github.event_name }}"
RAW_LABELS=$(cat <<'JSON'
${{ toJson(github.event.pull_request.labels) }}
JSON
)
if [[ "$RAW_LABELS" == "null" || -z "$RAW_LABELS" ]]; then
LABELS="[]"
else
LABELS="$RAW_LABELS"
fi
SHOULD_RUN="false"
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
SHOULD_RUN="true"
elif [[ "$EVENT_NAME" == "pull_request" ]]; then
if echo "$LABELS" | jq -r '.[].name' | grep -q "testable"; then
SHOULD_RUN="true"
fi
fi
echo "should_run=$SHOULD_RUN" >> "$GITHUB_OUTPUT"
setup:
runs-on: ubuntu-latest
needs: [precheck]
if: needs.precheck.outputs.should_run == 'true'
outputs:
matrix_platform: ${{ steps.set-matrix.outputs.platform }}
matrix_python: ${{ steps.set-matrix.outputs.python }}
steps:
- id: set-matrix
env:
INPUT_PLATFORM: ${{ github.event.inputs.platform || 'all' }}
INPUT_PYTHON: "3.10" # Test only on python 3.10
run: |
if [ "$INPUT_PLATFORM" = "all" ]; then
echo 'platform=["rvc2","rvc4"]' >> $GITHUB_OUTPUT
else
echo "platform=[\"$INPUT_PLATFORM\"]" >> $GITHUB_OUTPUT
fi
if [ "$INPUT_PYTHON" = "all" ]; then
echo 'python=["3.8", "3.10", "3.12"]' >> $GITHUB_OUTPUT
else
echo "python=[\"$INPUT_PYTHON\"]" >> $GITHUB_OUTPUT
fi
detect-changes:
runs-on: ubuntu-latest
needs: [precheck]
if: needs.precheck.outputs.should_run == 'true'
outputs:
example_dirs: ${{ steps.detect.outputs.example_dirs }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: detect
run: |
git fetch origin main
changed_files=$(git diff --name-only origin/main...HEAD)
example_dirs=""
while read -r file; do
dir=$(dirname "$file")
while [ "$dir" != "." ] && [ "$dir" != "/" ]; do
if [[ -f "$dir/main.py" && -f "$dir/requirements.txt" ]]; then
example_dirs="$example_dirs $dir"
break
fi
dir=$(dirname "$dir")
done
done <<< "$changed_files"
example_dirs=$(echo "$example_dirs" | tr ' ' '\n' | sort -u | xargs)
echo "Changed example dirs: $example_dirs"
echo "example_dirs=$example_dirs" >> "$GITHUB_OUTPUT"
- name: Log if no examples detected
if: steps.detect.outputs.example_dirs == ''
run: echo "✅ No runnable examples detected in this PR."
test_peripheral:
runs-on: ["self-hosted", "testbed-runner"]
needs: [setup, detect-changes]
if: needs.detect-changes.outputs.example_dirs != '' &&
((inputs.subtests || 'all') == 'all' || (inputs.subtests || 'all') == 'peripheral')
strategy:
matrix:
python-version: ${{ fromJSON(needs.setup.outputs.matrix_python) }}
platform: ${{ fromJSON(needs.setup.outputs.matrix_platform) }}
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
- name: Install HIL
run: |
pip install hil_framework --upgrade --index-url https://__token__:${{ secrets.GITLAB_TOKEN }}@gitlab.luxonis.com/api/v4/projects/213/packages/pypi/simple
- name: Set model variable
run: |
if [ "${{ matrix.platform }}" = "rvc2" ]; then
echo "MODEL=oak_d_s2" >> $GITHUB_ENV
elif [ "${{ matrix.platform }}" = "rvc4" ]; then
echo "MODEL=oak4_pro or oak4_d" >> $GITHUB_ENV
fi
- name: Run Test
run: |
export RESERVATION_NAME="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#${{ matrix.python-version}}-${{ matrix.platform }}"
export INFLUXDB_TOKEN=${{ secrets.INFLUXDB_TOKEN }}
ENV_VARS="\
--env PLATFORM=${{ matrix.platform }} \
--env PYTHON_VERSION_ENV=${{ matrix.python-version }} \
--env LOG_LEVEL=${{ github.event.inputs.log_level || 'INFO' }} \
--env ROOT_DIR='${{ needs.detect-changes.outputs.example_dirs }}' \
--env STRICT_MODE=${{ github.event.inputs.strict_mode || 'no' }} "
RESERVATION_OPTION="--reservation-name $RESERVATION_NAME"
exec hil_runner --models "$MODEL" $RESERVATION_OPTION $HOLD_RESERVATION --wait --sync-workspace \
--dockerfile ./tests/Dockerfile_peripheral \
--docker-build-args "--build-arg PYTHON_VERSION=${{ matrix.python-version }}" \
--docker-run-args "$ENV_VARS"
test_standalone:
runs-on: ["self-hosted", "testbed-runner"]
needs: [setup, detect-changes]
if: needs.detect-changes.outputs.example_dirs != '' &&
((inputs.subtests || 'all') == 'all' || (inputs.subtests || 'all') == 'standalone')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
- name: Install HIL
run: |
pip install hil_framework --upgrade --index-url https://__token__:${{ secrets.GITLAB_TOKEN }}@gitlab.luxonis.com/api/v4/projects/213/packages/pypi/simple
- name: Run Test
run: |
export RESERVATION_NAME="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}#standalone"
export INFLUXDB_TOKEN=${{ secrets.INFLUXDB_TOKEN }}
ENV_VARS="\
--env PLATFORM="rvc4" \
--env PYTHON_VERSION_ENV="3.10" \
--env LOG_LEVEL=${{ github.event.inputs.log_level || 'INFO' }} \
--env ROOT_DIR='${{ needs.detect-changes.outputs.example_dirs }}' \
--env STRICT_MODE=${{ github.event.inputs.strict_mode || 'no' }} \
--env DEVICE_PASSWORD=${{ secrets.DEVICE_PASSWORD }} \
--env LOCAL_STATIC_REGISTRY=${{ secrets.LOCAL_STATIC_REGISTRY }}"
RESERVATION_OPTION="--reservation-name $RESERVATION_NAME"
exec hil_runner --models "oak4_pro or oak4_d" $RESERVATION_OPTION $HOLD_RESERVATION --wait --oakctl --sync-workspace \
--dockerfile ./tests/Dockerfile_standalone \
--docker-build-args "--build-arg PYTHON_VERSION=3.12" \
--docker-run-args "$ENV_VARS"
final:
name: Runnability of changed examples
runs-on: ubuntu-latest
needs:
- precheck
- test_peripheral
- test_standalone
if: always()
steps:
- name: Fail if tests have been skipped
if: needs.precheck.outputs.should_run == 'false'
run: |
echo "❌ PR is not marked as testable (no 'testable' label). Skipping tests is not allowed."
exit 1
- name: Fail if any previous job failed
if: ${{ needs.test_peripheral.result == 'failure' || needs.test_standalone.result == 'failure' || needs.test_peripheral.result == 'cancelled' || needs.test_standalone.result == 'cancelled' }}
run: |
echo "❌ One or more required tests failed or were cancelled."
exit 1
- name: All required jobs passed
run: echo "✅ All tests passed successfully."