Skip to content

Commit f36869f

Browse files
committed
fix(ci): Use merge-base for correct target validation
The validation workflow was comparing changes against the wrong base, causing incorrect target detection when PR branches get out of sync. Now it uses git merge-base to find where the branch actually split off, so it only validates the targets that were actually changed in the PR. This is the same fix as sherlock-project#2588 in the upstream repo.
1 parent 1d2c4b1 commit f36869f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

.github/workflows/validate_modified_targets.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,39 @@ jobs:
1414
contents: read
1515
pull-requests: write
1616
steps:
17-
- name: Checkout repository
17+
- name: Checkout PR branch
1818
uses: actions/checkout@v5
1919
with:
20-
ref: ${{ github.base_ref }}
21-
fetch-depth: 1
20+
# Check out the actual PR code, not the base branch
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
# Fetch all history so we can find the common ancestor (merge-base)
23+
fetch-depth: 0
2224

2325
- name: Set up Python
2426
uses: actions/setup-python@v6
2527
with:
26-
python-version: '3.13'
28+
python-version: "3.13"
2729

2830
- name: Install Poetry
2931
uses: abatilo/actions-poetry@v4
3032
with:
31-
poetry-version: 'latest'
33+
poetry-version: "latest"
3234

3335
- name: Install dependencies
3436
run: |
3537
poetry install --no-interaction --with dev
3638
37-
- name: Drop in place updated manifest from base
39+
- name: Prepare JSON versions for comparison
3840
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
41+
# Fetch the target branch to ensure we can compare against it
42+
git fetch origin ${{ github.base_ref }}
43+
# Find the exact commit where this branch split from the target branch
44+
MERGE_BASE=$(git merge-base origin/${{ github.base_ref }} HEAD)
45+
echo "Comparing HEAD against merge-base commit: $MERGE_BASE"
46+
# Copy the version of the file from the current PR branch (HEAD)
4247
cp sherlock_project/resources/data.json data.json.head
48+
# Extract the version of the file from the merge-base commit
49+
git show $MERGE_BASE:sherlock_project/resources/data.json > data.json.base
4350
4451
- name: Discover modified targets
4552
id: discover-modified

0 commit comments

Comments
 (0)