From 498b5b40e714e5f159669aea00cd2cb788e1bfd6 Mon Sep 17 00:00:00 2001 From: Dimitry Kh Date: Sat, 10 Aug 2024 10:06:58 +0200 Subject: [PATCH] simplify regex for gitdiff changed files detection --- .github/workflows/coverage.yaml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index cd0ef0d2f0..bf8c21a4c6 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -18,25 +18,30 @@ jobs: - name: Fetch github branches and detect introduces .py files run: | + py_files=() if [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then # Fetch changes when PR comes from remote repo git fetch origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:refs/remotes/origin/PR-${{ github.event.pull_request.number }} - files=$(git diff --name-status origin/${{ github.base_ref }}...origin/PR-${{ github.event.pull_request.number }} -- tests/ | grep -E '^[AM]' | grep '\.py$') + gitdiff=$(git diff --name-status origin/${{ github.base_ref }}...origin/PR-${{ github.event.pull_request.number }} -- tests/) else # Fetch the base branch and the head branch git fetch origin ${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} git fetch origin ${{ github.head_ref }}:refs/remotes/origin/${{ github.head_ref }} - files=$(git diff --name-status origin/${{ github.base_ref }}...origin/${{ github.head_ref }} -- tests/ | grep -E '^[AM]' | grep '\.py$') + + gitdiff=$(git diff --name-status origin/${{ github.base_ref }}...origin/${{ github.head_ref }} -- tests/) fi - # Eliminate git diff chars, select only .py paths - echo "Collect the changed .py files" - py_files=() - while read -r line; do - file_fixed=$(echo "$line" | cut -c 3-) - py_files+=("$file_fixed") - done <<< "$files" + echo "git diff:" + echo "$gitdiff" + paths=$(echo "$gitdiff" | grep -oE '/[^[:space:]]+') + while IFS= read -r line; do + py_files+=("tests$line") + done <<< "$paths" + echo "Extracted file paths:" + for path in "${py_files[@]}"; do + echo "$path" + done echo "Prepare the NEW_TESTS variable" py_files_str=$(IFS=,; echo "${py_files[*]}")