@@ -17,38 +17,57 @@ jobs:
17
17
- name : Checkout repository
18
18
uses : actions/checkout@v5
19
19
with :
20
+ # Checkout the base branch but fetch all history to avoid a second fetch call
20
21
ref : ${{ github.base_ref }}
21
- fetch-depth : 1
22
+ fetch-depth : 0
22
23
23
24
- name : Set up Python
24
25
uses : actions/setup-python@v6
25
26
with :
26
- python-version : ' 3.13'
27
+ python-version : " 3.13"
27
28
28
29
- name : Install Poetry
29
30
uses : abatilo/actions-poetry@v4
30
31
with :
31
- poetry-version : ' latest'
32
+ poetry-version : " latest"
32
33
33
34
- name : Install dependencies
34
35
run : |
35
36
poetry install --no-interaction --with dev
36
37
37
- - name : Drop in place updated manifest from base
38
+ - name : Prepare JSON versions for comparison
38
39
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
43
54
44
55
- name : Discover modified targets
45
56
id : discover-modified
46
57
run : |
47
58
CHANGED=$(
48
59
python - <<'EOF'
49
60
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)
52
71
53
72
changed = []
54
73
for k, v in head.items():
63
82
echo -e ">>> Changed targets: \n$(echo $CHANGED | tr ',' '\n')"
64
83
echo "changed_targets=$CHANGED" >> "$GITHUB_OUTPUT"
65
84
85
+ # --- The rest of the steps below are unchanged ---
86
+
66
87
- name : Validate modified targets
67
88
if : steps.discover-modified.outputs.changed_targets != ''
68
89
continue-on-error : true
0 commit comments