ci(actions): Replace changed-files (#11130)

This commit is contained in:
Lucas Saavedra Vaz 2025-03-17 10:20:30 -03:00 committed by GitHub
parent f7c1efccaa
commit ba2ab1e4bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 120 additions and 62 deletions

View file

@ -2,6 +2,93 @@
build_all=false build_all=false
chunks_count=0 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 if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then
echo "Core files changed or not a PR. Building all." echo "Core files changed or not a PR. Building all."
@ -76,9 +163,9 @@ chunks+="]"
{ {
echo "build_all=$build_all" echo "build_all=$build_all"
echo "build_libraries=$BUILD_LIBRARIES" echo "build_libraries=$LIB_CHANGED"
echo "build_static_sketches=$BUILD_STATIC_SKETCHES" echo "build_static_sketches=$STATIC_SKETCHES_CHANGED"
echo "build_idf=$BUILD_IDF" echo "build_idf=$IDF_CHANGED"
echo "chunk_count=$chunks_count" echo "chunk_count=$chunks_count"
echo "chunks=$chunks" echo "chunks=$chunks"
} >> "$GITHUB_OUTPUT" } >> "$GITHUB_OUTPUT"

View file

@ -30,16 +30,16 @@ jobs:
echo "Make sure you are using a branch inside the repository and not a fork." echo "Make sure you are using a branch inside the repository and not a fork."
- name: Verify Python Tools Changed - name: Verify Python Tools Changed
uses: tj-actions/changed-files@v41
id: verify-changed-files id: verify-changed-files
with: run: |
fetch_depth: "2" 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)
since_last_remote_commit: "true" echo "all_changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT
files: | if [ -n "$CHANGED_FILES" ]; then
tools/get.py echo "any_changed=true" >> $GITHUB_OUTPUT
tools/espota.py else
tools/gen_esp32part.py echo "any_changed=false" >> $GITHUB_OUTPUT
tools/gen_insights_package.py fi
- name: List all changed files - name: List all changed files
shell: bash shell: bash
run: | run: |

View file

@ -58,7 +58,22 @@ jobs:
- name: Get changed files - name: Get changed files
id: 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 - 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 }} run: pre-commit run --color=always --show-diff-on-failure --files ${{ steps.changed-files.outputs.all_changed_files }}

View file

@ -45,12 +45,13 @@ on:
- "!.github/scripts/tests_*" - "!.github/scripts/tests_*"
- "!.github/scripts/upload_*" - "!.github/scripts/upload_*"
- "variants/esp32/**/*" - "variants/esp32/**/*"
- "variants/esp32s2/**/*"
- "variants/esp32s3/**/*"
- "variants/esp32c2/**/*" - "variants/esp32c2/**/*"
- "variants/esp32c3/**/*" - "variants/esp32c3/**/*"
- "variants/esp32c6/**/*" - "variants/esp32c6/**/*"
- "variants/esp32h2/**/*" - "variants/esp32h2/**/*"
- "variants/esp32p4/**/*"
- "variants/esp32s2/**/*"
- "variants/esp32s3/**/*"
concurrency: concurrency:
group: build-${{github.event.pull_request.number || github.ref}} group: build-${{github.event.pull_request.number || github.ref}}
@ -85,58 +86,13 @@ jobs:
with: with:
fetch-depth: 2 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 - name: Set chunks
id: set-chunks id: set-chunks
env: env:
LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }}
IS_PR: ${{ github.event_name == 'pull_request' }} IS_PR: ${{ github.event_name == 'pull_request' }}
PR_NUM: ${{ github.event.pull_request.number }}
MAX_CHUNKS: ${{ env.MAX_CHUNKS }} MAX_CHUNKS: ${{ env.MAX_CHUNKS }}
BUILD_IDF: ${{ steps.changed-files.outputs.idf_any_changed == 'true' }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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' }}
run: | run: |
bash ./.github/scripts/set_push_chunks.sh bash ./.github/scripts/set_push_chunks.sh