Skip to content

Commit 0d9407f

Browse files
committed
ci(json): Add requires_any field
1 parent 6fd7c07 commit 0d9407f

File tree

4 files changed

+95
-5
lines changed

4 files changed

+95
-5
lines changed

.github/scripts/install-platformio-esp32.sh

+35-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function count_sketches(){ # count_sketches <examples-path>
9696
continue
9797
fi
9898

99-
# Check if the sketch requires any configuration options
99+
# Check if the sketch requires any configuration options (AND)
100100
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
101101
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
102102
for requirement in $requirements; do
@@ -107,6 +107,23 @@ function count_sketches(){ # count_sketches <examples-path>
107107
fi
108108
done
109109
fi
110+
111+
# Check if the sketch requires any configuration options (OR)
112+
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
113+
if [[ "$requirements_or" != "null" ]] || [[ "$requirements_or" != "" ]]; then
114+
found=false
115+
for requirement in $requirements_or; do
116+
requirement=$(echo $requirement | xargs)
117+
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/esp32/sdkconfig")
118+
if [[ "$found_line" != "" ]]; then
119+
found=true
120+
break
121+
fi
122+
done
123+
if [[ "$found" == "false" ]]; then
124+
continue
125+
fi
126+
fi
110127
fi
111128

112129
echo $sketch >> sketches.txt
@@ -198,6 +215,23 @@ function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-
198215
fi
199216
done
200217
fi
218+
219+
# Check if the sketch requires any configuration options (OR)
220+
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
221+
if [[ "$requirements_or" != "null" ]] || [[ "$requirements_or" != "" ]]; then
222+
found=false
223+
for requirement in $requirements_or; do
224+
requirement=$(echo $requirement | xargs)
225+
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/esp32/sdkconfig")
226+
if [[ "$found_line" != "" ]]; then
227+
found=true
228+
break
229+
fi
230+
done
231+
if [[ "$found" == "false" ]]; then
232+
continue
233+
fi
234+
fi
201235
fi
202236

203237
sketchnum=$(($sketchnum + 1))

.github/scripts/sketch_utils.sh

+37-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
171171
exit 0
172172
fi
173173

174-
# Check if the sketch requires any configuration options
174+
# Check if the sketch requires any configuration options (AND)
175175
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
176176
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
177177
for requirement in $requirements; do
@@ -183,6 +183,24 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
183183
fi
184184
done
185185
fi
186+
187+
# Check if the sketch excludes any configuration options (OR)
188+
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
189+
if [[ "$requirements_or" != "null" ]] || [[ "$requirements_or" != "" ]]; then
190+
found=false
191+
for requirement in $requirements_or; do
192+
requirement=$(echo $requirement | xargs)
193+
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/$target/sdkconfig")
194+
if [[ "$found_line" != "" ]]; then
195+
found=true
196+
break
197+
fi
198+
done
199+
if [[ "$found" == "false" ]]; then
200+
echo "Target $target meets none of the requirements in requires_any for $sketchname. Skipping."
201+
exit 0
202+
fi
203+
fi
186204
fi
187205

188206
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
@@ -330,7 +348,7 @@ function count_sketches(){ # count_sketches <path> [target] [file] [ignore-requi
330348
fi
331349

332350
if [ "$ignore_requirements" != "1" ]; then
333-
# Check if the sketch requires any configuration options
351+
# Check if the sketch requires any configuration options (AND)
334352
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
335353
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
336354
for requirement in $requirements; do
@@ -341,6 +359,23 @@ function count_sketches(){ # count_sketches <path> [target] [file] [ignore-requi
341359
fi
342360
done
343361
fi
362+
363+
# Check if the sketch excludes any configuration options (OR)
364+
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
365+
if [[ "$requirements_or" != "null" ]] || [[ "$requirements_or" != "" ]]; then
366+
found=false
367+
for requirement in $requirements_or; do
368+
requirement=$(echo $requirement | xargs)
369+
found_line=$(grep -E "^$requirement" $SDKCONFIG_DIR/$target/sdkconfig)
370+
if [[ "$found_line" != "" ]]; then
371+
found=true
372+
break
373+
fi
374+
done
375+
if [[ "$found" == "false" ]]; then
376+
continue
377+
fi
378+
fi
344379
fi
345380
fi
346381
echo $sketch >> sketches.txt

.github/scripts/tests_run.sh

+20-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function run_test() {
3636
return 0
3737
fi
3838

39-
# Check if the sketch requires any configuration options
39+
# Check if the sketch requires any configuration options (AND)
4040
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
4141
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
4242
for requirement in $requirements; do
@@ -49,6 +49,25 @@ function run_test() {
4949
fi
5050
done
5151
fi
52+
53+
# Check if the sketch requires any configuration options (OR)
54+
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
55+
if [[ "$requirements_or" != "null" ]] || [[ "$requirements_or" != "" ]]; then
56+
found=false
57+
for requirement in $requirements_or; do
58+
requirement=$(echo $requirement | xargs)
59+
found_line=$(grep -E "^$requirement" "$SDKCONFIG_PATH")
60+
if [[ "$found_line" != "" ]]; then
61+
found=true
62+
break
63+
fi
64+
done
65+
if [[ "$found" == "false" ]]; then
66+
printf "\033[93mTarget $target meets none of the requirements in requires_any for $sketchname. Skipping.\033[0m\n"
67+
printf "\n\n\n"
68+
return 0
69+
fi
70+
fi
5271
fi
5372

5473
if [ $len -eq 1 ]; then

docs/en/contributing.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ CI JSON File
408408
The ``ci.json`` file is used to specify how the test suite and sketches will handled by the CI system. It can contain the following fields:
409409

410410
* ``requires``: A list of configurations in ``sdkconfig`` that are required to run the test suite. The test suite will only run on the targets
411-
that have the required configurations. By default, no configurations are required.
411+
that have **ALL** the required configurations. By default, no configurations are required.
412+
* ``requires_any``: A list of configurations in ``sdkconfig`` that are required to run the test suite. The test suite will only run on the targets
413+
that have **ANY** of the required configurations. By default, no configurations are required.
412414
* ``targets``: A dictionary that specifies the targets for which the tests will be run. The key is the target name and the value is a boolean
413415
that specifies if the test should be run for that target. By default, all targets are enabled as long as they have the required configurations
414416
specified in the ``requires`` field. This field is also valid for examples.

0 commit comments

Comments
 (0)