From 6c20c90da1a0c7933b2ff4c3d28e803c3e214951 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:06:51 -0300 Subject: [PATCH 1/6] ci(tests): Swap cache to artifacts to avoid errors between OSes --- .github/workflows/hw.yml | 12 +++++------- .github/workflows/qemu.yml | 10 +++------- .github/workflows/wokwi.yml | 10 +++------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/.github/workflows/hw.yml b/.github/workflows/hw.yml index 8c7dc0dffb2..b401f0f3f07 100644 --- a/.github/workflows/hw.yml +++ b/.github/workflows/hw.yml @@ -77,18 +77,16 @@ jobs: run: | pip install -U pip pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi + apt update + apt install -y jq - name: Get binaries - id: cache-build-binaries - uses: actions/cache/restore@v4 if: ${{ steps.check-tests.outputs.enabled == 'true' }} + uses: actions/download-artifact@v4 with: - fail-on-cache-miss: true - key: tests-${{ env.id }}-bin + name: tests-bin-${{ inputs.chip }}-${{ inputs.type }} path: | - ~/.arduino/tests/**/build*.tmp/*.bin - ~/.arduino/tests/**/build*.tmp/*.elf - ~/.arduino/tests/**/build*.tmp/*.json + ~/.arduino/tests - name: Run Tests if: ${{ steps.check-tests.outputs.enabled == 'true' }} diff --git a/.github/workflows/qemu.yml b/.github/workflows/qemu.yml index 1aa155129c8..da31054aeef 100644 --- a/.github/workflows/qemu.yml +++ b/.github/workflows/qemu.yml @@ -113,15 +113,11 @@ jobs: - name: Get binaries if: ${{ steps.check-tests.outputs.enabled == 'true' }} - id: cache-build-binaries - uses: actions/cache/restore@v4 + uses: actions/download-artifact@v4 with: - fail-on-cache-miss: true - key: tests-${{ env.id }}-bin + name: tests-bin-${{ inputs.chip }}-${{ inputs.type }} path: | - ~/.arduino/tests/**/build*.tmp/*.bin - ~/.arduino/tests/**/build*.tmp/*.elf - ~/.arduino/tests/**/build*.tmp/*.json + ~/.arduino/tests - name: Run Tests if: ${{ steps.check-tests.outputs.enabled == 'true' }} diff --git a/.github/workflows/wokwi.yml b/.github/workflows/wokwi.yml index 84b0acf06b4..f9eee85f95f 100644 --- a/.github/workflows/wokwi.yml +++ b/.github/workflows/wokwi.yml @@ -91,15 +91,11 @@ jobs: - name: Get binaries if: ${{ steps.check-tests.outputs.enabled == 'true' }} - id: cache-build-binaries - uses: actions/cache/restore@v4 + uses: actions/download-artifact@v4 with: - fail-on-cache-miss: true - key: tests-${{ env.id }}-bin + name: tests-bin-${{ inputs.chip }}-${{ inputs.type }} path: | - ~/.arduino/tests/**/build*.tmp/*.bin - ~/.arduino/tests/**/build*.tmp/*.elf - ~/.arduino/tests/**/build*.tmp/*.json + ~/.arduino/tests - name: Run Tests if: ${{ steps.check-tests.outputs.enabled == 'true' }} From fce8bd8057b463578b4b715197b76217b3259c5b Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:08:14 -0300 Subject: [PATCH 2/6] ci(push): Fix chunk generation for compilation --- .github/scripts/on-push.sh | 2 +- .github/scripts/set_push_chunks.sh | 81 ++++++++++++++++++++++++++++ .github/scripts/sketch_utils.sh | 7 +-- .github/workflows/push.yml | 86 ++++++------------------------ 4 files changed, 101 insertions(+), 75 deletions(-) create mode 100644 .github/scripts/set_push_chunks.sh diff --git a/.github/scripts/on-push.sh b/.github/scripts/on-push.sh index 7abe3600d80..f925390da13 100755 --- a/.github/scripts/on-push.sh +++ b/.github/scripts/on-push.sh @@ -108,7 +108,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then if [ "$BUILD_LOG" -eq 1 ]; then #remove last comma from the last JSON object - sed -i '$ s/.$//' "$sizes_file" + sed -i '$ s/,$//' "$sizes_file" #echo end of JSON array echo "]}" >> $sizes_file fi diff --git a/.github/scripts/set_push_chunks.sh b/.github/scripts/set_push_chunks.sh new file mode 100644 index 00000000000..eb6023f5784 --- /dev/null +++ b/.github/scripts/set_push_chunks.sh @@ -0,0 +1,81 @@ +build_all=false +chunks_count=0 + +if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then + echo "Core files changed or not a PR. Building all." + build_all=true + chunks_count=$MAX_CHUNKS +elif [[ $LIB_CHANGED == 'true' ]]; then + echo "Libraries changed. Building only affected sketches." + if [[ $NETWORKING_CHANGED == 'true' ]]; then + echo "Networking libraries changed. Building networking related sketches." + networking_sketches="$(find libraries/WiFi -name *.ino) " + networking_sketches+="$(find libraries/Ethernet -name *.ino) " + networking_sketches+="$(find libraries/PPP -name *.ino) " + networking_sketches+="$(find libraries/NetworkClientSecure -name *.ino) " + networking_sketches+="$(find libraries/WebServer -name *.ino) " + fi + if [[ $FS_CHANGED == 'true' ]]; then + echo "FS libraries changed. Building FS related sketches." + fs_sketches="$(find libraries/SD -name *.ino) " + fs_sketches+="$(find libraries/SD_MMC -name *.ino) " + fs_sketches+="$(find libraries/SPIFFS -name *.ino) " + fs_sketches+="$(find libraries/LittleFS -name *.ino) " + fs_sketches+="$(find libraries/FFat -name *.ino) " + fi + sketches="$networking_sketches $fs_sketches" + for file in $LIB_FILES; do + if [[ $file == *.ino ]]; then + # If file ends with .ino, add it to the list of sketches + echo "Sketch found: $file" + sketches+="$file " + elif [[ $(basename $(dirname $file)) == "src" ]]; then + # If file is in a src directory, find all sketches in the parent/examples directory + echo "Library src file found: $file" + lib=$(dirname $(dirname $file)) + if [[ -d $lib/examples ]]; then + lib_sketches=$(find $lib/examples -name *.ino) + sketches+="$lib_sketches " + echo "Library sketches: $lib_sketches" + fi + else + # If file is in a example folder but it is not a sketch, find all sketches in the current directory + echo "File in example folder found: $file" + sketch=$(find $(dirname $file) -name *.ino) + sketches+="$sketch " + echo "Sketch in example folder: $sketch" + fi + echo "" + done +fi + +if [[ -n $sketches ]]; then + # Remove duplicates + sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq) + for sketch in $sketches; do + echo $sketch >> sketches_found.txt + chunks_count=$((chunks_count+1)) + done + echo "Number of sketches found: $chunks_count" + echo "Sketches:" + echo "$sketches" + + if [[ $chunks_count -gt $MAX_CHUNKS ]]; then + echo "More sketches than the allowed number of chunks found. Limiting to $MAX_CHUNKS chunks." + chunks_count=$MAX_CHUNKS + fi +fi + +chunks='["0"' +for i in $(seq 1 $(( $chunks_count - 1 )) ); do + chunks+=",\"$i\"" +done +chunks+="]" + +echo "build_all=$build_all" >> $GITHUB_OUTPUT +echo "build_libraries=$BUILD_LIBRARIES" >> $GITHUB_OUTPUT +echo "build_static_sketches=$BUILD_STATIC_SKETCHES" >> $GITHUB_OUTPUT +echo "build_idf=$BUILD_IDF" >> $GITHUB_OUTPUT +echo "build_platformio=$BUILD_PLATFORMIO" >> $GITHUB_OUTPUT +echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT +echo "chunks=$chunks" >> $GITHUB_OUTPUT diff --git a/.github/scripts/sketch_utils.sh b/.github/scripts/sketch_utils.sh index 1b43ced1480..cdf334a4fc6 100755 --- a/.github/scripts/sketch_utils.sh +++ b/.github/scripts/sketch_utils.sh @@ -192,7 +192,7 @@ function build_sketch(){ # build_sketch [ex exit_status=$? if [ $exit_status -ne 0 ]; then - echo ""ERROR: Compilation failed with error code $exit_status"" + echo "ERROR: Compilation failed with error code $exit_status" exit $exit_status fi @@ -236,7 +236,7 @@ function build_sketch(){ # build_sketch [ex exit_status=$? if [ $exit_status -ne 0 ]; then - echo ""ERROR: Compilation failed with error code $exit_status"" + echo "ERROR: Compilation failed with error code $exit_status" exit $exit_status fi # $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \ @@ -398,6 +398,7 @@ function build_sketches(){ # build_sketches > sketches_found.txt - chunks_count=$((chunks_count+1)) - done - echo "Number of sketches found: $chunks_count" - echo "Sketches: $sketches" - - if [[ $chunks_count -gt ${{ env.MAX_CHUNKS }} ]]; then - echo "More sketches than the allowed number of chunks found. Limiting to ${{ env.MAX_CHUNKS }} chunks." - chunks_count=${{ env.MAX_CHUNKS }} - fi - fi - - chunks='["0"' - for i in $(seq 1 $(( $chunks_count - 1 )) ); do - chunks+=",\"$i\"" - done - chunks+="]" - - echo "build_all=$build_all" >> $GITHUB_OUTPUT - echo "build_libraries=$build_libraries" >> $GITHUB_OUTPUT - echo "build_static_sketches=$build_static_sketches" >> $GITHUB_OUTPUT - echo "build_idf=$build_idf" >> $GITHUB_OUTPUT - echo "build_platformio=$build_platformio" >> $GITHUB_OUTPUT - echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT - echo "chunks=$chunks" >> $GITHUB_OUTPUT + bash ./.github/scripts/set_push_chunks.sh - name: Upload sketches found if: ${{ steps.set-chunks.outputs.build_all == 'false' && steps.set-chunks.outputs.build_libraries == 'true' }} From 81d44994054160cd922d56b75cb91870a678c9c4 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 11 Jun 2024 16:37:35 -0300 Subject: [PATCH 3/6] ci(tests): Fix error code propagation --- .github/scripts/tests_run.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/scripts/tests_run.sh b/.github/scripts/tests_run.sh index bb90373b56c..d5c6f1f35c3 100755 --- a/.github/scripts/tests_run.sh +++ b/.github/scripts/tests_run.sh @@ -95,13 +95,12 @@ function run_test() { 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 + printf "\033[91mFailed test: $sketchname -- Config: $i\033[0m\n\n" error=$result fi fi done - printf "Test return code: $error\n" return $error } @@ -250,7 +249,6 @@ else exit_code=0 run_test $target $sketch $options $erase || exit_code=$? - echo "Sketch $sketch exit code: $exit_code" if [ $exit_code -ne 0 ]; then error=$exit_code fi From c4c258bc834d927f9c528ba11688908a4baa8965 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:26:50 -0300 Subject: [PATCH 4/6] ci(push): Add shebang to new script --- .github/scripts/set_push_chunks.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/set_push_chunks.sh b/.github/scripts/set_push_chunks.sh index eb6023f5784..472205f0c38 100644 --- a/.github/scripts/set_push_chunks.sh +++ b/.github/scripts/set_push_chunks.sh @@ -1,3 +1,5 @@ +#!/bin/bash + build_all=false chunks_count=0 From 8ca89438be6da965b7854aac4858f9a24df85a92 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:49:23 -0300 Subject: [PATCH 5/6] ci(push): Fix sizes upload if there is no changes --- .github/workflows/push.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 85fcd6ddb9e..97f11238b24 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -280,6 +280,7 @@ jobs: - name: Commit json files to gh-pages if on master if: github.event_name == 'push' && github.ref == 'refs/heads/master' + continue-on-error: true run: | git config user.name github-actions git config user.email github-actions@github.com From fa89bfb1dd5a5bc7fa9b2522cf0e34501fc175f1 Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Wed, 12 Jun 2024 08:53:23 -0300 Subject: [PATCH 6/6] ci(bot): Fix GitHub actions bot commit info --- .github/workflows/lib.yml | 4 ++-- .github/workflows/publishsizes-2.x.yml | 8 ++++---- .github/workflows/push.yml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lib.yml b/.github/workflows/lib.yml index 342c877416a..894df61f4fd 100644 --- a/.github/workflows/lib.yml +++ b/.github/workflows/lib.yml @@ -120,8 +120,8 @@ jobs: - name: Push to github repo run: | - git config user.name github-actions - git config user.email github-actions@github.com + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add ${{ env.RESULT_LIBRARY_TEST_FILE }} git commit -m "Generated External Libraries Test Results" git push origin HEAD:gh-pages diff --git a/.github/workflows/publishsizes-2.x.yml b/.github/workflows/publishsizes-2.x.yml index 9c5583d02ab..bdd2fc311e4 100644 --- a/.github/workflows/publishsizes-2.x.yml +++ b/.github/workflows/publishsizes-2.x.yml @@ -32,22 +32,22 @@ jobs: run: | mv master_cli_compile/*.json artifacts/sizes-report/pr/ mv v2.x_cli_compile/*.json artifacts/sizes-report/master/ - + - name: Report results uses: P-R-O-C-H-Y/report-size-deltas@sizes_v2 with: sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }} github-token: ${{ env.GITHUB_TOKEN }} destination-file: ${{ env.RESULT_SIZES_TEST_FILE }} - + - name: Append file with action URL run: echo "/ [GitHub Action Link](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})" >> ${{ env.RESULT_SIZES_TEST_FILE }} - name: Push to github repo run: | - git config user.name github-actions - git config user.email github-actions@github.com + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add ${{ env.RESULT_SIZES_TEST_FILE }} git commit -m "Generated Sizes Results (master-v2.x)" git push origin HEAD:gh-pages diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 97f11238b24..2f14a6fb62f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -282,8 +282,8 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/master' continue-on-error: true run: | - git config user.name github-actions - git config user.email github-actions@github.com + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add --all git commit -m "Updated cli compile json files" git push origin HEAD:gh-pages