Skip to content

Commit

Permalink
ci(refactor): Refactor workflows and skip files
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasssvaz committed May 27, 2024
1 parent d45f35a commit c74f66f
Show file tree
Hide file tree
Showing 534 changed files with 1,859 additions and 677 deletions.
8 changes: 6 additions & 2 deletions .github/scripts/install-platformio-esp32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ function count_sketches(){ # count_sketches <examples-path>
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
continue
fi
if [[ -f "$sketchdir/.test.skip" ]]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [[ "$is_target" == "false" ]]; then
continue
fi
echo $sketch >> sketches.txt
Expand Down Expand Up @@ -161,8 +163,10 @@ function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-
local sketchdir=$(dirname $sketch)
local sketchdirname=$(basename $sketchdir)
local sketchname=$(basename $sketch)
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [ "${sketchdirname}.ino" != "$sketchname" ] \
|| [ -f "$sketchdir/.test.skip" ]; then
|| [[ "$is_target" == "false" ]]; then
continue
fi
sketchnum=$(($sketchnum + 1))
Expand Down
1 change: 0 additions & 1 deletion .github/scripts/on-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ fi

SCRIPTS_DIR="./.github/scripts"
if [ "$BUILD_PIO" -eq 0 ]; then
#source ${SCRIPTS_DIR}/install-arduino-ide.sh
source ${SCRIPTS_DIR}/install-arduino-cli.sh
source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh

Expand Down
55 changes: 36 additions & 19 deletions .github/scripts/sketch_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
done

xtra_opts=$*
len=0

if [ -z $sketchdir ]; then
echo "ERROR: Sketch directory not provided"
Expand All @@ -64,26 +65,30 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
# precedence. Note that the following logic also falls to the default
# parameters if no arguments were passed and no file was found.

if [ -z $options ] && [ -f $sketchdir/cfg.json ]; then
if [ -z $options ] && [ -f $sketchdir/ci.json ]; then
# The config file could contain multiple FQBNs for one chip. If
# that's the case we build one time for every FQBN.

len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
fqbn=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn' $sketchdir/cfg.json`
else
len=`jq -r --arg target $target '.fqbn[$target] | length' $sketchdir/ci.json`
if [ $len -gt 0 ]; then
fqbn=`jq -r --arg target $target '.fqbn[$target] | sort' $sketchdir/ci.json`
fi
fi

if [ ! -z $options ] || [ $len -eq 0 ]; then
# Since we are passing options, we will end up with only one FQBN to
# build.

len=1

# Default FQBN options if none were passed in the command line.

esp32_opts="FlashMode=dio,PSRAM=enabled,PartitionScheme=huge_app"
esp32s2_opts="PSRAM=enabled,PartitionScheme=huge_app"
esp32s3_opts="PSRAM=opi,USBMode=default,PartitionScheme=huge_app"
esp32c3_opts="FlashMode=dio,PartitionScheme=huge_app"
esp32c6_opts="PartitionScheme=huge_app"
esp32h2_opts="PartitionScheme=huge_app"
esp32_opts="PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dio"
esp32s2_opts="PSRAM=enabled,PartitionScheme=huge_app,FlashMode=dio"
esp32s3_opts="PSRAM=opi,USBMode=default,PartitionScheme=huge_app,FlashMode=dio"
esp32c3_opts="PartitionScheme=huge_app,FlashMode=dio"
esp32c6_opts="PartitionScheme=huge_app,FlashMode=dio"
esp32h2_opts="PartitionScheme=huge_app,FlashMode=dio"

# Select the common part of the FQBN based on the target. The rest will be
# appended depending on the passed options.
Expand Down Expand Up @@ -135,7 +140,14 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex

sketchname=$(basename $sketchdir)

if [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
else
is_target="true"
fi

if [[ "$is_target" == "false" ]]; then
echo "Skipping $sketchname for target $target"
exit 0
fi
Expand Down Expand Up @@ -270,12 +282,19 @@ function count_sketches(){ # count_sketches <path> [target]
local sketchname=$(basename $sketch)
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
continue
elif [[ -n $target ]] && [[ -f "$sketchdir/.skip.$target" ]]; then
continue
else
echo $sketch >> sketches.txt
sketchnum=$(($sketchnum + 1))
elif [[ -n $target ]]; then
# If the target is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
else
is_target="true"
fi
if [[ "$is_target" == "false" ]]; then
continue
fi
fi
echo $sketch >> sketches.txt
sketchnum=$(($sketchnum + 1))
done
return $sketchnum
}
Expand Down Expand Up @@ -339,7 +358,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
return 1
fi

if [ "$chunk_index" -gt "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
if [ "$chunk_index" -gt "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
chunk_index=$chunk_max
fi

Expand All @@ -364,8 +383,6 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
else
start_index=$(( $chunk_index * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
echo "Skipping job"
touch ~/.build_skipped
return 0
fi

Expand Down
3 changes: 1 addition & 2 deletions .github/scripts/tests_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ while [ ! -z "$1" ]; do
shift
done

#source ${SCRIPTS_DIR}/install-arduino-ide.sh
source ${SCRIPTS_DIR}/install-arduino-cli.sh
source ${SCRIPTS_DIR}/install-arduino-core-esp32.sh

Expand All @@ -72,7 +71,7 @@ fi

if [ $chunk_build -eq 1 ]; then
BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"
args+=" -p $test_folder"
args+=" -p $test_folder -i 0 -m 1"
else
BUILD_CMD="${SCRIPTS_DIR}/sketch_utils.sh build"
args+=" -s $test_folder/$sketch"
Expand Down
76 changes: 54 additions & 22 deletions .github/scripts/tests_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,60 @@ function run_test() {
local sketchdir=$(dirname $sketch)
local sketchname=$(basename $sketchdir)
local result=0
local error=0

if [[ -f "$sketchdir/.skip.$platform" ]] || [[ -f "$sketchdir/.skip.$target" ]] || [[ -f "$sketchdir/.skip.$platform.$target" ]]; then
echo "Skipping $sketchname test for $target, platform: $platform"
skipfile="$sketchdir/.test_skipped"
touch $skipfile
exit 0
# If the target or platform is listed as false, skip the sketch. Otherwise, include it.
if [ -f $sketchdir/ci.json ]; then
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
selected_platform=$(jq -r --arg platform $platform '.platforms[$platform]' $sketchdir/ci.json)
else
is_target="true"
selected_platform="true"
fi

if [[ $is_target == "false" ]] || [[ $selected_platform == "false" ]]; then
printf "\033[93mSkipping $sketchname test for $target, platform: $platform\033[0m\n"
printf "\n\n\n"
return 0
fi

if [ $options -eq 0 ] && [ -f $sketchdir/cfg.json ]; then
len=`jq -r --arg chip $target '.targets[] | select(.name==$chip) | .fqbn | length' $sketchdir/cfg.json`
if [ $options -eq 0 ] && [ -f $sketchdir/ci.json ]; then
len=`jq -r --arg target $target '.fqbn[$target] | length' $sketchdir/ci.json`
if [ $len -eq 0 ]; then
len=1
fi
else
len=1
fi

if [ $len -eq 1 ]; then
# build_dir="$sketchdir/build"
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
report_file="$sketchdir/$sketchname.xml"
report_file="$sketchdir/$target/$sketchname.xml"
fi

for i in `seq 0 $(($len - 1))`
do
echo "Running test: $sketchname -- Config: $i"
fqbn="Default"

if [ $len -ne 1 ]; then
fqbn=`jq -r --arg target $target --argjson i $i '.fqbn[$target] | sort | .[$i]' $sketchdir/ci.json`
elif [ -f $sketchdir/ci.json ]; then
has_fqbn=`jq -r --arg target $target '.fqbn[$target]' $sketchdir/ci.json`
if [ "$has_fqbn" != "null" ]; then
fqbn=`jq -r --arg target $target '.fqbn[$target] | .[0]' $sketchdir/ci.json`
fi
fi

printf "\033[95mRunning test: $sketchname -- Config: $fqbn\033[0m\n"
if [ $erase_flash -eq 1 ]; then
esptool.py -c $target erase_flash
fi

if [ $len -ne 1 ]; then
# build_dir="$sketchdir/build$i"
build_dir="$HOME/.arduino/tests/$sketchname/build$i.tmp"
report_file="$sketchdir/$sketchname$i.xml"
report_file="$sketchdir/$target/$sketchname$i.xml"
fi

if [ $platform == "wokwi" ]; then
Expand All @@ -55,27 +78,31 @@ function run_test() {
elif [ $target == "esp32c3" ]; then
extra_args+=" --qemu-prog-path qemu-system-riscv32 --qemu-cli-args=\"-machine $target -icount 3 -nographic\""
else
echo "Unsupported QEMU target: $target"
printf "\033[91mUnsupported QEMU target: $target\033[0m\n"
exit 1
fi
else
extra_args="--embedded-services esp,arduino"
fi

result=0
echo "pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args"
printf "\033[95mpytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args\033[0m\n"
bash -c "set +e; pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args; exit \$?" || result=$?
result=$?
printf "\n"
if [ $result -ne 0 ]; then
result=0
echo "Retrying test: $sketchname -- Config: $i"
printf "\033[95mRetrying test: $sketchname -- Config: $i\033[0m\n"
printf "\033[95mpytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args\033[0m\n"
bash -c "set +e; pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args; exit \$?" || result=$?
printf "\n"
result=$?
if [ $result -ne 0 ]; then
exit $result
error=$result
fi
fi
done
printf "\n"
return $error
}

SCRIPTS_DIR="./.github/scripts"
Expand All @@ -92,14 +119,14 @@ while [ ! -z "$1" ]; do
-c )
chunk_run=1
;;
-q )
-Q )
if [ ! -d $QEMU_PATH ]; then
echo "QEMU path $QEMU_PATH does not exist"
exit 1
fi
platform="qemu"
;;
-w )
-W )
shift
wokwi_timeout=$1
platform="wokwi"
Expand Down Expand Up @@ -165,6 +192,7 @@ if [ $chunk_run -eq 0 ]; then
exit 1
fi
run_test $target $test_folder/$sketch/$sketch.ino $options $erase
exit $?
else
if [ "$chunk_max" -le 0 ]; then
echo "ERROR: Chunks count must be positive number"
Expand Down Expand Up @@ -197,8 +225,6 @@ else
else
start_index=$(( $chunk_index * $chunk_size ))
if [ "$sketchcount" -le "$start_index" ]; then
echo "Skipping job"
touch $PWD/tests/.test_skipped
exit 0
fi

Expand All @@ -210,6 +236,7 @@ else

start_num=$(( $start_index + 1 ))
sketchnum=0
error=0

for sketch in $sketches; do

Expand All @@ -218,9 +245,14 @@ else
|| [ "$sketchnum" -gt "$end_index" ]; then
continue
fi
echo ""
echo "Sketch Index $(($sketchnum - 1))"

run_test $target $sketch $options $erase
printf "\033[95mSketch Index $(($sketchnum - 1))\033[0m\n"

exit_code=0
run_test $target $sketch $options $erase || exit_code=$?
if [ $exit_code -ne 0 ]; then
error=$exit_code
fi
done
exit $error
fi
10 changes: 5 additions & 5 deletions .github/scripts/upload_py_tools.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash
CHANGED_FILES=$1
echo "Pushing '$CHANGED_FILES' as $GITHUB_ACTOR"
git config --global github.user "$GITHUB_ACTOR"
git config --global user.name "$GITHUB_ACTOR"
git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
echo "Pushing '$CHANGED_FILES' as github-actions[bot]"
git config --global github.user "github-actions[bot]"
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
for tool in $CHANGED_FILES; do
git add tools/$tool.exe
done
git commit -m "Push binary to tools"
git commit -m "change(tools): Push generated binaries to PR"
git push
6 changes: 5 additions & 1 deletion .github/workflows/boards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: Boards Test
# The workflow will run on schedule and labeled pull requests
on:
pull_request:
paths:
- 'boards.txt'
- 'libraries/ESP32/examples/CI/CIBoardsTest/CIBoardsTest.ino'
- '.github/workflows/boards.yml'

env:
# It's convenient to set variables for values used multiple times in the workflow
Expand All @@ -24,7 +28,7 @@ jobs:
uses: dcarbone/[email protected]

- name: Get board name
run:
run:
bash .github/scripts/find_new_boards.sh ${{ github.repository }} ${{github.event.number}}

test-boards:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build_py_tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.TOOLS_UPLOAD_PAT }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python 3.8
# Skip setting python on ARM because of missing compatibility: https://github.com/actions/setup-python/issues/108
Expand All @@ -107,7 +108,7 @@ jobs:
pyinstaller --distpath ./${{ env.DISTPATH }} -F --icon=.github/pytools/espressif.ico tools/$tool.py
done
- name: Sign binaries
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-latest' && env.CERTIFICATE != '' && env.CERTIFICATE_PASSWORD != ''
env:
CERTIFICATE: ${{ secrets.CERTIFICATE }}
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
Expand Down
Loading

0 comments on commit c74f66f

Please sign in to comment.