Skip to content

Commit c66222c

Browse files
refactor: enhance file fetching logic in PR validation workflow
1 parent b4459af commit c66222c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

.github/workflows/validate-pr.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ jobs:
1717
with:
1818
fetch-depth: 0
1919

20+
- name: Fetch PR head ref
21+
run: |
22+
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-head
23+
2024
- name: Set up Python
2125
uses: actions/setup-python@v4
2226
with:
@@ -30,8 +34,14 @@ jobs:
3034
- name: Get changed files
3135
id: changed-files
3236
run: |
33-
# Get changed files but exclude .github directory
34-
echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -v '^\.github/' | grep '\.ya\?ml$' | tr '\n' ' ')" >> $GITHUB_OUTPUT
37+
set -euo pipefail
38+
BASE_SHA=${{ github.event.pull_request.base.sha }}
39+
HEAD_REF=pr-head
40+
MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_REF")
41+
echo "Diffing $MERGE_BASE...$HEAD_REF"
42+
files=$(git diff --name-only "$MERGE_BASE" "$HEAD_REF" | grep -v '^\.github/' | grep -E '\.ya?ml$' || true)
43+
files=$(echo "$files" | tr '\n' ' ' | sed -e 's/[[:space:]]*$//')
44+
echo "files=$files" >> $GITHUB_OUTPUT
3545
3646
- name: Validate changes
3747
id: validate

0 commit comments

Comments
 (0)