From 89be464ee41a668792295aa5ca5d409aa95a457a Mon Sep 17 00:00:00 2001 From: Lucas Saavedra Vaz <32426024+lucasssvaz@users.noreply.github.com> Date: Mon, 17 Mar 2025 01:29:58 -0300 Subject: [PATCH] ci(actions): Replace changed-files --- .github/scripts/set_push_chunks.sh | 93 +++++++++++++++++++++++++++- .github/workflows/build_py_tools.yml | 18 +++--- .github/workflows/pre-commit.yml | 17 ++++- .github/workflows/push.yml | 54 ++-------------- 4 files changed, 120 insertions(+), 62 deletions(-) diff --git a/.github/scripts/set_push_chunks.sh b/.github/scripts/set_push_chunks.sh index ff0af7da6e8..21ae83ddacd 100644 --- a/.github/scripts/set_push_chunks.sh +++ b/.github/scripts/set_push_chunks.sh @@ -2,6 +2,93 @@ build_all=false chunks_count=0 +last_check_files="" +last_check_result="" +gh_output="" + +# Define the file patterns +core_files=( + '\.github/.*' + 'cores/.*' + 'package/.*' + 'tools/.*' + 'platform\.txt' + 'programmers\.txt' + 'variants/esp32/.*' + 'variants/esp32c3/.*' + 'variants/esp32c6/.*' + 'variants/esp32h2/.*' + 'variants/esp32p4/.*' + 'variants/esp32s2/.*' + 'variants/esp32s3/.*' +) +library_files=( + 'libraries/.*/examples/.*' + 'libraries/.*/src/.*' +) +networking_files=( + 'libraries/Network/src/.*' +) +fs_files=( + 'libraries/FS/src/.*' +) +static_sketches_files=( + 'libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure\.ino' + 'libraries/BLE/examples/Server/Server\.ino' + 'libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer\.ino' + 'libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics\.ino' + 'libraries/NetworkClientSecure/src/.*' + 'libraries/BLE/src/.*' + 'libraries/Insights/src/.*' +) +idf_files=( + 'idf_component\.yml' + 'Kconfig\.projbuild' + 'CMakeLists\.txt' + 'variants/esp32c2/.*' +) + +# Function to check if any files match the patterns +check_files() { + local patterns=("$@") + local files_found="" + for pattern in "${patterns[@]}"; do + echo "Checking pattern: $pattern" + matched_files=$(echo "$gh_output" | grep -E "$pattern") + echo "matched_files: $matched_files" + files_found+="$matched_files " + done + + last_check_files=$(echo "$files_found" | xargs) + if [[ -n $last_check_files ]]; then + last_check_result="true" + else + last_check_result="false" + fi + echo "last_check_result: $last_check_result" +} + +if [[ $IS_PR != 'true' ]]; then + gh_output=$(gh api repos/espressif/arduino-esp32/commits/"$GITHUB_SHA" --jq '.files[].filename') +else + gh_output=$(gh pr diff "$PR_NUM" --name-only) +fi +echo "gh_output: $gh_output" + +# Output the results +check_files "${core_files[@]}" +CORE_CHANGED=$last_check_result +check_files "${library_files[@]}" +LIB_CHANGED=$last_check_result +LIB_FILES=$last_check_files +check_files "${networking_files[@]}" +NETWORKING_CHANGED=$last_check_result +check_files "${fs_files[@]}" +FS_CHANGED=$last_check_result +check_files "${static_sketches_files[@]}" +STATIC_SKETCHES_CHANGED=$last_check_result +check_files "${idf_files[@]}" +IDF_CHANGED=$last_check_result if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then echo "Core files changed or not a PR. Building all." @@ -76,9 +163,9 @@ chunks+="]" { echo "build_all=$build_all" - echo "build_libraries=$BUILD_LIBRARIES" - echo "build_static_sketches=$BUILD_STATIC_SKETCHES" - echo "build_idf=$BUILD_IDF" + echo "build_libraries=$LIB_CHANGED" + echo "build_static_sketches=$STATIC_SKETCHES_CHANGED" + echo "build_idf=$IDF_CHANGED" echo "chunk_count=$chunks_count" echo "chunks=$chunks" } >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/build_py_tools.yml b/.github/workflows/build_py_tools.yml index d4dfca9c8d1..ca13da03136 100644 --- a/.github/workflows/build_py_tools.yml +++ b/.github/workflows/build_py_tools.yml @@ -30,16 +30,16 @@ jobs: echo "Make sure you are using a branch inside the repository and not a fork." - name: Verify Python Tools Changed - uses: tj-actions/changed-files@v41 id: verify-changed-files - with: - fetch_depth: "2" - since_last_remote_commit: "true" - files: | - tools/get.py - tools/espota.py - tools/gen_esp32part.py - tools/gen_insights_package.py + run: | + CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r ^HEAD -- tools/get.py tools/espota.py tools/gen_esp32part.py tools/gen_insights_package.py | xargs) + echo "all_changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT + if [ -n "$CHANGED_FILES" ]; then + echo "any_changed=true" >> $GITHUB_OUTPUT + else + echo "any_changed=false" >> $GITHUB_OUTPUT + fi + - name: List all changed files shell: bash run: | diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index dc009e445da..6290b9ea908 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -58,7 +58,22 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v42.0.2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUM: ${{ github.event.pull_request.number }} + IS_PR: ${{ github.event_name == 'pull_request' }} + GITHUB_SHA: ${{ github.sha }} + run: | + if [[ $IS_PR != 'true' ]]; then + files_changed=$(gh api repos/espressif/arduino-esp32/commits/"$GITHUB_SHA" --jq '.files[].filename' | xargs) + else + files_changed=$(gh pr diff "$PR_NUM" --name-only | xargs) + fi + echo "all_changed_files=$files_changed" >> $GITHUB_OUTPUT + echo "Changed files:" + for file in $files_changed; do + echo " $file" + done - name: Run pre-commit hooks in changed files run: pre-commit run --color=always --show-diff-on-failure --files ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 211ed1658f9..feb32f95d03 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -45,12 +45,13 @@ on: - "!.github/scripts/tests_*" - "!.github/scripts/upload_*" - "variants/esp32/**/*" - - "variants/esp32s2/**/*" - - "variants/esp32s3/**/*" - "variants/esp32c2/**/*" - "variants/esp32c3/**/*" - "variants/esp32c6/**/*" - "variants/esp32h2/**/*" + - "variants/esp32p4/**/*" + - "variants/esp32s2/**/*" + - "variants/esp32s3/**/*" concurrency: group: build-${{github.event.pull_request.number || github.ref}} @@ -85,58 +86,13 @@ jobs: with: fetch-depth: 2 - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v44 - with: - files_yaml: | - core: - - '.github/**' - - 'cores/**' - - 'package/**' - - 'tools/**' - - 'platform.txt' - - 'programmers.txt' - - "variants/esp32/**/*" - - "variants/esp32s2/**/*" - - "variants/esp32s3/**/*" - - "variants/esp32c3/**/*" - - "variants/esp32c6/**/*" - - "variants/esp32h2/**/*" - libraries: - - 'libraries/**/examples/**' - - 'libraries/**/src/**' - networking: - - 'libraries/Network/src/**' - fs: - - 'libraries/FS/src/**' - static_sketeches: - - 'libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino' - - 'libraries/BLE/examples/Server/Server.ino' - - 'libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino' - - 'libraries/Insights/examples/MinimalDiagnostics/MinimalDiagnostics.ino' - - 'libraries/NetworkClientSecure/src/**' - - 'libraries/BLE/src/**' - - 'libraries/Insights/src/**' - idf: - - 'idf_component.yml' - - 'Kconfig.projbuild' - - 'CMakeLists.txt' - - "variants/esp32c2/**/*" - - name: Set chunks id: set-chunks env: - LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }} IS_PR: ${{ github.event_name == 'pull_request' }} + PR_NUM: ${{ github.event.pull_request.number }} MAX_CHUNKS: ${{ env.MAX_CHUNKS }} - BUILD_IDF: ${{ steps.changed-files.outputs.idf_any_changed == 'true' }} - BUILD_LIBRARIES: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }} - BUILD_STATIC_SKETCHES: ${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }} - FS_CHANGED: ${{ steps.changed-files.outputs.fs_any_changed == 'true' }} - NETWORKING_CHANGED: ${{ steps.changed-files.outputs.networking_any_changed == 'true' }} - CORE_CHANGED: ${{ steps.changed-files.outputs.core_any_changed == 'true' }} - LIB_CHANGED: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | bash ./.github/scripts/set_push_chunks.sh