Skip to content

Commit b9e28b9

Browse files
authored
Merge pull request #2588 from shreyasNaik0101/fix/correct-ci-diff
fix(ci): Use merge-base for correct target validation
2 parents d0e005d + 70e3c0d commit b9e28b9

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

.github/workflows/validate_modified_targets.yml

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,57 @@ jobs:
1717
- name: Checkout repository
1818
uses: actions/checkout@v5
1919
with:
20+
# Checkout the base branch but fetch all history to avoid a second fetch call
2021
ref: ${{ github.base_ref }}
21-
fetch-depth: 1
22+
fetch-depth: 0
2223

2324
- name: Set up Python
2425
uses: actions/setup-python@v6
2526
with:
26-
python-version: '3.13'
27+
python-version: "3.13"
2728

2829
- name: Install Poetry
2930
uses: abatilo/actions-poetry@v4
3031
with:
31-
poetry-version: 'latest'
32+
poetry-version: "latest"
3233

3334
- name: Install dependencies
3435
run: |
3536
poetry install --no-interaction --with dev
3637
37-
- name: Drop in place updated manifest from base
38+
- name: Prepare JSON versions for comparison
3839
run: |
39-
cp sherlock_project/resources/data.json data.json.base
40-
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr --depth=1
41-
git show pr:sherlock_project/resources/data.json > sherlock_project/resources/data.json
42-
cp sherlock_project/resources/data.json data.json.head
40+
# Fetch only the PR's branch head (single network call in this step)
41+
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr
42+
43+
# Find the merge-base commit between the target branch and the PR branch
44+
MERGE_BASE=$(git merge-base origin/${{ github.base_ref }} pr)
45+
echo "Comparing PR head against merge-base commit: $MERGE_BASE"
46+
47+
# Safely extract the file from the PR's head and the merge-base commit
48+
git show pr:sherlock_project/resources/data.json > data.json.head
49+
git show $MERGE_BASE:sherlock_project/resources/data.json > data.json.base
50+
51+
# CRITICAL FIX: Overwrite the checked-out data.json with the one from the PR
52+
# This ensures that pytest runs against the new, updated file.
53+
cp data.json.head sherlock_project/resources/data.json
4354
4455
- name: Discover modified targets
4556
id: discover-modified
4657
run: |
4758
CHANGED=$(
4859
python - <<'EOF'
4960
import json
50-
with open("data.json.base") as f: base = json.load(f)
51-
with open("data.json.head") as f: head = json.load(f)
61+
import sys
62+
try:
63+
with open("data.json.base") as f: base = json.load(f)
64+
with open("data.json.head") as f: head = json.load(f)
65+
except FileNotFoundError as e:
66+
print(f"Error: Could not find {e.filename}", file=sys.stderr)
67+
sys.exit(1)
68+
except json.JSONDecodeError as e:
69+
print(f"Error: Could not decode JSON from a file - {e}", file=sys.stderr)
70+
sys.exit(1)
5271
5372
changed = []
5473
for k, v in head.items():
@@ -63,6 +82,8 @@ jobs:
6382
echo -e ">>> Changed targets: \n$(echo $CHANGED | tr ',' '\n')"
6483
echo "changed_targets=$CHANGED" >> "$GITHUB_OUTPUT"
6584
85+
# --- The rest of the steps below are unchanged ---
86+
6687
- name: Validate modified targets
6788
if: steps.discover-modified.outputs.changed_targets != ''
6889
continue-on-error: true

0 commit comments

Comments
 (0)