Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(json): Improve requirement checking #10554

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 7 additions & 86 deletions .github/scripts/install-platformio-esp32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ TOOLCHAIN_VERSION="12.2.0+20230208"
ESPTOOLPY_VERSION="~1.40501.0"
ESPRESSIF_ORGANIZATION_NAME="espressif"
SDKCONFIG_DIR="$PLATFORMIO_ESP32_PATH/tools/esp32-arduino-libs"
SCRIPTS_DIR="./.github/scripts"
COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count"
CHECK_REQUIREMENTS="${SCRIPTS_DIR}/sketch_utils.sh check_requirements"

echo "Installing Python Wheel ..."
pip install wheel > /dev/null 2>&1
Expand Down Expand Up @@ -74,64 +77,6 @@ function build_pio_sketch(){ # build_pio_sketch <board> <options> <path-to-ino>
python -m platformio ci --board "$board" "$sketch_dir" --project-option="$options"
}

function count_sketches(){ # count_sketches <examples-path>
local examples="$1"
rm -rf sketches.txt
if [ ! -d "$examples" ]; then
touch sketches.txt
return 0
fi
local sketches=$(find $examples -name *.ino)
local sketchnum=0
for sketch in $sketches; do
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
continue
elif [ -f $sketchdir/ci.json ]; then
# If the target is listed as false, skip the sketch. Otherwise, include it.
is_target=$(jq -r '.targets[esp32]' $sketchdir/ci.json)
if [[ "$is_target" == "false" ]]; then
continue
fi

# Check if the sketch requires any configuration options (AND)
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
if [[ "$requirements" != "null" && "$requirements" != "" ]]; then
for requirement in $requirements; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/esp32/sdkconfig")
if [[ "$found_line" == "" ]]; then
continue 2
fi
done
fi

# Check if the sketch requires any configuration options (OR)
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
if [[ "$requirements_or" != "null" && "$requirements_or" != "" ]]; then
found=false
for requirement in $requirements_or; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/esp32/sdkconfig")
if [[ "$found_line" != "" ]]; then
found=true
break
fi
done
if [[ "$found" == "false" ]]; then
continue
fi
fi
fi

echo $sketch >> sketches.txt
sketchnum=$(($sketchnum + 1))
done
return $sketchnum
}

function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-path> <chunk> <total-chunks>
if [ "$#" -lt 3 ]; then
echo "ERROR: Illegal number of parameters"
Expand Down Expand Up @@ -160,7 +105,7 @@ function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-
fi

set +e
count_sketches "$examples"
${COUNT_SKETCHES} "$examples" "esp32"
local sketchcount=$?
set -e
local sketches=$(cat sketches.txt)
Expand Down Expand Up @@ -204,33 +149,9 @@ function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-
continue
fi

# Check if the sketch requires any configuration options (AND)
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
if [[ "$requirements" != "null" && "$requirements" != "" ]]; then
for requirement in $requirements; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/esp32/sdkconfig")
if [[ "$found_line" == "" ]]; then
continue 2
fi
done
fi

# Check if the sketch requires any configuration options (OR)
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
if [[ "$requirements_or" != "null" && "$requirements_or" != "" ]]; then
found=false
for requirement in $requirements_or; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/esp32/sdkconfig")
if [[ "$found_line" != "" ]]; then
found=true
break
fi
done
if [[ "$found" == "false" ]]; then
continue
fi
local has_requirements=$(${CHECK_REQUIREMENTS} $sketchdir "$SDKCONFIG_DIR/esp32/sdkconfig")
if [ "$has_requirements" == "0" ]; then
continue
fi
fi

Expand Down
109 changes: 53 additions & 56 deletions .github/scripts/sketch_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ else
SDKCONFIG_DIR="tools/esp32-arduino-libs"
fi

function check_requirements(){ # check_requirements <sketchdir> <sdkconfig_path>
local sketchdir=$1
local sdkconfig_path=$2
local has_requirements=1

if [ ! -f "$sdkconfig_path" ] || [ ! -f "$sketchdir/ci.json" ]; then
echo "ERROR: sdkconfig or ci.json not found" 1>&2
# Return 1 on error to force the sketch to be built and fail. This way the
# CI will fail and the user will know that the sketch has a problem.
else
# Check if the sketch requires any configuration options (AND)
local requirements=$(jq -r '.requires[]? // empty' "$sketchdir/ci.json")
if [[ "$requirements" != "null" && "$requirements" != "" ]]; then
for requirement in $requirements; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$sdkconfig_path")
if [[ "$found_line" == "" ]]; then
has_requirements=0
fi
done
fi

# Check if the sketch requires any configuration options (OR)
local requirements_or=$(jq -r '.requires_any[]? // empty' "$sketchdir/ci.json")
if [[ "$requirements_or" != "null" && "$requirements_or" != "" ]]; then
local found=false
for requirement in $requirements_or; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$sdkconfig_path")
if [[ "$found_line" != "" ]]; then
found=true
break
fi
done
if [[ "$found" == "false" ]]; then
has_requirements=0
fi
fi
fi

echo $has_requirements
}

function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
while [ ! -z "$1" ]; do
case "$1" in
Expand Down Expand Up @@ -171,35 +214,10 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
exit 0
fi

# Check if the sketch requires any configuration options (AND)
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
if [[ "$requirements" != "null" && "$requirements" != "" ]]; then
for requirement in $requirements; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/$target/sdkconfig")
if [[ "$found_line" == "" ]]; then
echo "Target $target does not meet the requirement $requirement for $sketchname. Skipping."
exit 0
fi
done
fi

# Check if the sketch excludes any configuration options (OR)
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
if [[ "$requirements_or" != "null" && "$requirements_or" != "" ]]; then
found=false
for requirement in $requirements_or; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_DIR/$target/sdkconfig")
if [[ "$found_line" != "" ]]; then
found=true
break
fi
done
if [[ "$found" == "false" ]]; then
echo "Target $target meets none of the requirements in requires_any for $sketchname. Skipping."
exit 0
fi
local has_requirements=$(check_requirements "$sketchdir" "$SDKCONFIG_DIR/$target/sdkconfig")
if [ "$has_requirements" == "0" ]; then
echo "Target $target does not meet the requirements for $sketchname. Skipping."
exit 0
fi
fi

Expand Down Expand Up @@ -348,33 +366,9 @@ function count_sketches(){ # count_sketches <path> [target] [file] [ignore-requi
fi

if [ "$ignore_requirements" != "1" ]; then
# Check if the sketch requires any configuration options (AND)
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
if [[ "$requirements" != "null" && "$requirements" != "" ]]; then
for requirement in $requirements; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" $SDKCONFIG_DIR/$target/sdkconfig)
if [[ "$found_line" == "" ]]; then
continue 2
fi
done
fi

# Check if the sketch excludes any configuration options (OR)
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
if [[ "$requirements_or" != "null" && "$requirements_or" != "" ]]; then
found=false
for requirement in $requirements_or; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" $SDKCONFIG_DIR/$target/sdkconfig)
if [[ "$found_line" != "" ]]; then
found=true
break
fi
done
if [[ "$found" == "false" ]]; then
continue 2
fi
local has_requirements=$(check_requirements "$sketchdir" "$SDKCONFIG_DIR/$target/sdkconfig")
if [ "$has_requirements" == "0" ]; then
continue
fi
fi
fi
Expand Down Expand Up @@ -552,6 +546,7 @@ Available commands:
count: Count sketches.
build: Build a sketch.
chunk_build: Build a chunk of sketches.
check_requirements: Check if target meets sketch requirements.
"

cmd=$1
Expand All @@ -569,6 +564,8 @@ case "$cmd" in
;;
"chunk_build") build_sketches $*
;;
"check_requirements") check_requirements $*
;;
*)
echo "ERROR: Unrecognized command"
echo "$USAGE"
Expand Down
47 changes: 14 additions & 33 deletions .github/scripts/tests_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function run_test() {
local sketchname=$(basename $sketchdir)
local result=0
local error=0
local sdkconfig_path

if [ $options -eq 0 ] && [ -f $sketchdir/ci.json ]; then
len=`jq -r --arg target $target '.fqbn[$target] | length' $sketchdir/ci.json`
Expand All @@ -20,9 +21,9 @@ function run_test() {
fi

if [ $len -eq 1 ]; then
SDKCONFIG_PATH="$HOME/.arduino/tests/$sketchname/build.tmp/sdkconfig"
sdkconfig_path="$HOME/.arduino/tests/$sketchname/build.tmp/sdkconfig"
else
SDKCONFIG_PATH="$HOME/.arduino/tests/$sketchname/build0.tmp/sdkconfig"
sdkconfig_path="$HOME/.arduino/tests/$sketchname/build0.tmp/sdkconfig"
fi

if [ -f $sketchdir/ci.json ]; then
Expand All @@ -35,39 +36,19 @@ function run_test() {
printf "\n\n\n"
return 0
fi
fi

# Check if the sketch requires any configuration options (AND)
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
if [[ "$requirements" != "null" && "$requirements" != "" ]]; then
for requirement in $requirements; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_PATH")
if [[ "$found_line" == "" ]]; then
printf "\033[93mTarget $target does not meet the requirement $requirement for $sketchname. Skipping.\033[0m\n"
printf "\n\n\n"
return 0
fi
done
fi
if [ ! -f $sdkconfig_path ]; then
printf "\033[93mSketch $sketchname not built\nMight be due to missing target requirements or build failure\033[0m\n"
printf "\n\n\n"
return 0
fi

# Check if the sketch requires any configuration options (OR)
requirements_or=$(jq -r '.requires_any[]? // empty' $sketchdir/ci.json)
if [[ "$requirements_or" != "null" && "$requirements_or" != "" ]]; then
found=false
for requirement in $requirements_or; do
requirement=$(echo $requirement | xargs)
found_line=$(grep -E "^$requirement" "$SDKCONFIG_PATH")
if [[ "$found_line" != "" ]]; then
found=true
break
fi
done
if [[ "$found" == "false" ]]; then
printf "\033[93mTarget $target meets none of the requirements in requires_any for $sketchname. Skipping.\033[0m\n"
printf "\n\n\n"
return 0
fi
fi
local right_target=$(grep -E "^CONFIG_IDF_TARGET=\"$target\"$" "$sdkconfig_path")
if [ -z "$right_target" ]; then
printf "\033[91mError: Sketch $sketchname compiled for different target\n\033[0m\n"
printf "\n\n\n"
return 1
fi

if [ $len -eq 1 ]; then
Expand Down
5 changes: 3 additions & 2 deletions libraries/ArduinoOTA/examples/BasicOTA/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
5 changes: 3 additions & 2 deletions libraries/AsyncUDP/examples/AsyncUDPClient/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
5 changes: 3 additions & 2 deletions libraries/AsyncUDP/examples/AsyncUDPMulticastServer/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
5 changes: 3 additions & 2 deletions libraries/AsyncUDP/examples/AsyncUDPServer/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
5 changes: 3 additions & 2 deletions libraries/DNSServer/examples/CaptivePortal/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
5 changes: 3 additions & 2 deletions libraries/ESP32/examples/Time/SimpleTime/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
5 changes: 3 additions & 2 deletions libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"requires": [
"CONFIG_SOC_WIFI_SUPPORTED=y"
"requires_any": [
"CONFIG_SOC_WIFI_SUPPORTED=y",
"CONFIG_ESP_WIFI_REMOTE_ENABLED=y"
]
}
Loading
Loading