Skip to content

Commit 05afac7

Browse files
authored
Merge pull request sherlock-project#2548 from sherlock-project/feature/automatic-testing
Automatically test modified targets upon PR
2 parents 96aa12c + ae362b0 commit 05afac7

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Modified Target Validation
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- "sherlock_project/resources/data.json"
9+
10+
jobs:
11+
validate-modified-targets:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v5
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v6
21+
with:
22+
python-version: '3.13'
23+
24+
- name: Install Poetry
25+
uses: abatilo/actions-poetry@v4
26+
with:
27+
poetry-version: 'latest'
28+
29+
- name: Install dependencies
30+
run: |
31+
poetry install --no-interaction --with dev
32+
33+
- name: Discover modified targets
34+
id: discover-modified
35+
run: |
36+
# Fetch the upstream branch
37+
git fetch origin ${{ github.base_ref }} --depth=1
38+
39+
# Discover changes
40+
git show origin/${{ github.base_ref }}:sherlock_project/resources/data.json > data.json.base
41+
CHANGED=$(
42+
jq --slurpfile base data.json.base --slurpfile head sherlock_project/resources/data.json '
43+
[
44+
($head[0] | keys_unsorted[]) as $key
45+
| select(($base[0][$key] != $head[0][$key]) or ($base[0][$key] | not))
46+
| $key
47+
] | unique | join(",")'
48+
)
49+
50+
# Preserve changelist
51+
echo ">>> Changed targets: \n$(echo $CHANGED | tr ',' '\n')"
52+
echo "changed_targets=$CHANGED" >> "$GITHUB_OUTPUT"
53+
54+
- name: Validate modified targets
55+
if: steps.discover-modified.outputs.changed_targets != ''
56+
run: |
57+
$(poetry env activate)
58+
pytest -q --tb no -rA -m validate_targets -n 20 --chunked-sites "${{ steps.discover-modified.outputs.changed_targets }}"
59+
deactivate
60+
61+
- name: Announce skip if no modified targets
62+
if: steps.discover-modified.outputs.changed_targets == ''
63+
run: |
64+
echo "No modified targets found"

tests/conftest.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def fetch_local_manifest(honor_exclusions: bool = True) -> dict[str, dict[str, str]]:
88
sites_obj = SitesInformation(data_file_path=os.path.join(os.path.dirname(__file__), "../sherlock_project/resources/data.json"), honor_exclusions=honor_exclusions)
9-
sites_iterable = {site.name: site.information for site in sites_obj}
9+
sites_iterable: dict[str, dict[str, str]] = {site.name: site.information for site in sites_obj}
1010
return sites_iterable
1111

1212
@pytest.fixture()
@@ -25,9 +25,27 @@ def remote_schema():
2525
schemadat = json.load(remoteschema)
2626
yield schemadat
2727

28+
def pytest_addoption(parser):
29+
parser.addoption(
30+
"--chunked-sites",
31+
action="store",
32+
default=None,
33+
help="For tests utilizing chunked sites, include only the (comma-separated) site(s) specified.",
34+
)
35+
2836
def pytest_generate_tests(metafunc):
2937
if "chunked_sites" in metafunc.fixturenames:
3038
sites_info = fetch_local_manifest(honor_exclusions=False)
39+
40+
# Ingest and apply site selections
41+
site_filter: str | None = metafunc.config.getoption("--chunked-sites")
42+
if site_filter:
43+
selected_sites: list[str] = [site.strip() for site in site_filter.split(",")]
44+
sites_info = {
45+
site: data for site, data in sites_info.items()
46+
if site in selected_sites
47+
}
48+
3149
params = [{name: data} for name, data in sites_info.items()]
3250
ids = list(sites_info.keys())
3351
metafunc.parametrize("chunked_sites", params, ids=ids)

0 commit comments

Comments
 (0)