Skip to content

Commit

Permalink
simplify regex for gitdiff changed files detection
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Aug 10, 2024
1 parent b20719e commit 498b5b4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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[*]}")
Expand Down

0 comments on commit 498b5b4

Please sign in to comment.