Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions .github/workflows/validate_modified_targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,58 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v5
with:
# This is the original, secure checkout of the base branch.
ref: ${{ github.base_ref }}
fetch-depth: 1

- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
python-version: "3.13"

- name: Install Poetry
uses: abatilo/actions-poetry@v4
with:
poetry-version: 'latest'
poetry-version: "latest"

- name: Install dependencies
run: |
poetry install --no-interaction --with dev

- name: Drop in place updated manifest from base
- name: Prepare JSON versions for comparison
run: |
cp sherlock_project/resources/data.json data.json.base
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr --depth=1
git show pr:sherlock_project/resources/data.json > sherlock_project/resources/data.json
cp sherlock_project/resources/data.json data.json.head
# Fetch the PR's branch head and give it a local name 'pr'
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr

# The initial checkout may be shallow. To find a merge-base,
# we need more history. We can 'unshallow' the repository if needed.
git fetch --unshallow || true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be just a single command, rather than making two net calls?

If there's a good reason not to, all ears ofc


# Find the merge-base commit between the target branch (master) and the PR branch (pr)
MERGE_BASE=$(git merge-base origin/${{ github.base_ref }} pr)
echo "Comparing PR head against merge-base commit: $MERGE_BASE"

# Safely extract the version of the file from the PR's head without checking it out
git show pr:sherlock_project/resources/data.json > data.json.head

# Safely extract the version of the file from the merge-base commit
git show $MERGE_BASE:sherlock_project/resources/data.json > data.json.base

- name: Discover modified targets
id: discover-modified
run: |
CHANGED=$(
python - <<'EOF'
import json
with open("data.json.base") as f: base = json.load(f)
with open("data.json.head") as f: head = json.load(f)
import sys
try:
with open("data.json.base") as f: base = json.load(f)
with open("data.json.head") as f: head = json.load(f)
except FileNotFoundError as e:
print(f"Error: Could not find {e.filename}", file=sys.stderr)
sys.exit(1)
except json.JSONDecodeError as e:
print(f"Error: Could not decode JSON from a file - {e}", file=sys.stderr)
sys.exit(1)

changed = []
for k, v in head.items():
Expand Down