|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +build_all=false |
| 4 | +chunks_count=0 |
| 5 | + |
| 6 | +if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then |
| 7 | + echo "Core files changed or not a PR. Building all." |
| 8 | + build_all=true |
| 9 | + chunks_count=$MAX_CHUNKS |
| 10 | +elif [[ $LIB_CHANGED == 'true' ]]; then |
| 11 | + echo "Libraries changed. Building only affected sketches." |
| 12 | + if [[ $NETWORKING_CHANGED == 'true' ]]; then |
| 13 | + echo "Networking libraries changed. Building networking related sketches." |
| 14 | + networking_sketches="$(find libraries/WiFi -name *.ino) " |
| 15 | + networking_sketches+="$(find libraries/Ethernet -name *.ino) " |
| 16 | + networking_sketches+="$(find libraries/PPP -name *.ino) " |
| 17 | + networking_sketches+="$(find libraries/NetworkClientSecure -name *.ino) " |
| 18 | + networking_sketches+="$(find libraries/WebServer -name *.ino) " |
| 19 | + fi |
| 20 | + if [[ $FS_CHANGED == 'true' ]]; then |
| 21 | + echo "FS libraries changed. Building FS related sketches." |
| 22 | + fs_sketches="$(find libraries/SD -name *.ino) " |
| 23 | + fs_sketches+="$(find libraries/SD_MMC -name *.ino) " |
| 24 | + fs_sketches+="$(find libraries/SPIFFS -name *.ino) " |
| 25 | + fs_sketches+="$(find libraries/LittleFS -name *.ino) " |
| 26 | + fs_sketches+="$(find libraries/FFat -name *.ino) " |
| 27 | + fi |
| 28 | + sketches="$networking_sketches $fs_sketches" |
| 29 | + for file in $LIB_FILES; do |
| 30 | + if [[ $file == *.ino ]]; then |
| 31 | + # If file ends with .ino, add it to the list of sketches |
| 32 | + echo "Sketch found: $file" |
| 33 | + sketches+="$file " |
| 34 | + elif [[ $(basename $(dirname $file)) == "src" ]]; then |
| 35 | + # If file is in a src directory, find all sketches in the parent/examples directory |
| 36 | + echo "Library src file found: $file" |
| 37 | + lib=$(dirname $(dirname $file)) |
| 38 | + if [[ -d $lib/examples ]]; then |
| 39 | + lib_sketches=$(find $lib/examples -name *.ino) |
| 40 | + sketches+="$lib_sketches " |
| 41 | + echo "Library sketches: $lib_sketches" |
| 42 | + fi |
| 43 | + else |
| 44 | + # If file is in a example folder but it is not a sketch, find all sketches in the current directory |
| 45 | + echo "File in example folder found: $file" |
| 46 | + sketch=$(find $(dirname $file) -name *.ino) |
| 47 | + sketches+="$sketch " |
| 48 | + echo "Sketch in example folder: $sketch" |
| 49 | + fi |
| 50 | + echo "" |
| 51 | + done |
| 52 | +fi |
| 53 | + |
| 54 | +if [[ -n $sketches ]]; then |
| 55 | + # Remove duplicates |
| 56 | + sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq) |
| 57 | + for sketch in $sketches; do |
| 58 | + echo $sketch >> sketches_found.txt |
| 59 | + chunks_count=$((chunks_count+1)) |
| 60 | + done |
| 61 | + echo "Number of sketches found: $chunks_count" |
| 62 | + echo "Sketches:" |
| 63 | + echo "$sketches" |
| 64 | + |
| 65 | + if [[ $chunks_count -gt $MAX_CHUNKS ]]; then |
| 66 | + echo "More sketches than the allowed number of chunks found. Limiting to $MAX_CHUNKS chunks." |
| 67 | + chunks_count=$MAX_CHUNKS |
| 68 | + fi |
| 69 | +fi |
| 70 | + |
| 71 | +chunks='["0"' |
| 72 | +for i in $(seq 1 $(( $chunks_count - 1 )) ); do |
| 73 | + chunks+=",\"$i\"" |
| 74 | +done |
| 75 | +chunks+="]" |
| 76 | + |
| 77 | +echo "build_all=$build_all" >> $GITHUB_OUTPUT |
| 78 | +echo "build_libraries=$BUILD_LIBRARIES" >> $GITHUB_OUTPUT |
| 79 | +echo "build_static_sketches=$BUILD_STATIC_SKETCHES" >> $GITHUB_OUTPUT |
| 80 | +echo "build_idf=$BUILD_IDF" >> $GITHUB_OUTPUT |
| 81 | +echo "build_platformio=$BUILD_PLATFORMIO" >> $GITHUB_OUTPUT |
| 82 | +echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT |
| 83 | +echo "chunks=$chunks" >> $GITHUB_OUTPUT |
0 commit comments