Skip to content

Commit 738df6c

Browse files
committed
chore: add error message to the codesandbox
2 parents 4706323 + 83a38db commit 738df6c

19 files changed

+941
-289
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
### REPOSITORY
2-
/.github/CODEOWNERS @sdushantha
2+
/.github/CODEOWNERS @sdushantha @ppfeister
33
/.github/FUNDING.yml @sdushantha
44
/LICENSE @sdushantha
55

.github/workflows/exclusions.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Exclusions Updater
2+
3+
on:
4+
schedule:
5+
#- cron: '0 5 * * 0' # Runs at 05:00 every Sunday
6+
- cron: '0 5 * * *' # Runs at 05:00 every day
7+
workflow_dispatch:
8+
9+
jobs:
10+
update-exclusions:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v5
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v6
18+
with:
19+
python-version: '3.13'
20+
21+
- name: Install Poetry
22+
uses: abatilo/actions-poetry@v4
23+
with:
24+
poetry-version: 'latest'
25+
26+
- name: Install dependencies
27+
run: |
28+
poetry install --no-interaction --with dev
29+
30+
- name: Run false positive tests
31+
run: |
32+
$(poetry env activate)
33+
pytest -q --tb no -m validate_targets_fp -n 20 | tee fp_test_results.txt
34+
deactivate
35+
36+
- name: Parse false positive detections by desired categories
37+
run: |
38+
grep -oP '(?<=test_false_pos\[)[^\]]+(?=\].*result was Claimed)' fp_test_results.txt \
39+
| sort -u > false_positive_exclusions.txt
40+
grep -oP '(?<=test_false_pos\[)[^\]]+(?=\].*result was WAF)' fp_test_results.txt \
41+
| sort -u > waf_hits.txt
42+
43+
- name: Detect if exclusions list changed
44+
id: detect_changes
45+
run: |
46+
git fetch origin exclusions || true
47+
48+
if git show origin/exclusions:false_positive_exclusions.txt >/dev/null 2>&1; then
49+
# If the exclusions branch and file exist, compare
50+
if git diff --quiet origin/exclusions -- false_positive_exclusions.txt; then
51+
echo "exclusions_changed=false" >> "$GITHUB_OUTPUT"
52+
else
53+
echo "exclusions_changed=true" >> "$GITHUB_OUTPUT"
54+
fi
55+
else
56+
# If the exclusions branch or file do not exist, treat as changed
57+
echo "exclusions_changed=true" >> "$GITHUB_OUTPUT"
58+
fi
59+
60+
- name: Quantify and display results
61+
run: |
62+
FP_COUNT=$(wc -l < false_positive_exclusions.txt | xargs)
63+
WAF_COUNT=$(wc -l < waf_hits.txt | xargs)
64+
echo ">>> Found $FP_COUNT false positives and $WAF_COUNT WAF hits."
65+
echo ">>> False positive exclusions:" && cat false_positive_exclusions.txt
66+
echo ">>> WAF hits:" && cat waf_hits.txt
67+
68+
- name: Commit and push exclusions list
69+
if: steps.detect_changes.outputs.exclusions_changed == 'true'
70+
run: |
71+
git config user.name "Paul Pfeister (automation)"
72+
git config user.email "[email protected]"
73+
74+
mv false_positive_exclusions.txt false_positive_exclusions.txt.tmp
75+
76+
git add -f false_positive_exclusions.txt.tmp # -f required to override .gitignore
77+
git stash push -m "stash false positive exclusion list" -- false_positive_exclusions.txt.tmp
78+
79+
git fetch origin exclusions || true # Allows creation of branch if deleted
80+
git checkout -B exclusions origin/exclusions || (git checkout --orphan exclusions && git rm -rf .)
81+
82+
git stash pop || true
83+
84+
mv false_positive_exclusions.txt.tmp false_positive_exclusions.txt
85+
86+
git rm -f false_positive_exclusions.txt.tmp || true
87+
git add false_positive_exclusions.txt
88+
git commit -m "auto: update exclusions list" || echo "No changes to commit"
89+
git push origin exclusions

.github/workflows/regression.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- '**/*.py'
1212
- '**/*.ini'
1313
- '**/*.toml'
14+
- 'Dockerfile'
1415
push:
1516
branches:
1617
- master
@@ -21,11 +22,13 @@ on:
2122
- '**/*.py'
2223
- '**/*.ini'
2324
- '**/*.toml'
25+
- 'Dockerfile'
2426

2527
jobs:
2628
tox-lint:
27-
# Linting is ran through tox to ensure that the same linter is used by local runners
2829
runs-on: ubuntu-latest
30+
# Linting is ran through tox to ensure that the same linter
31+
# is used by local runners
2932
steps:
3033
- uses: actions/checkout@v4
3134
- name: Set up linting environment
@@ -41,18 +44,19 @@ jobs:
4144
tox-matrix:
4245
runs-on: ${{ matrix.os }}
4346
strategy:
44-
fail-fast: false # We want to know what specicic versions it fails on
47+
# We want to know what specicic versions it fails on
48+
fail-fast: false
4549
matrix:
4650
os: [
4751
ubuntu-latest,
4852
windows-latest,
4953
macos-latest,
5054
]
5155
python-version: [
52-
'3.9',
5356
'3.10',
5457
'3.11',
5558
'3.12',
59+
'3.13',
5660
]
5761
steps:
5862
- uses: actions/checkout@v4
@@ -67,3 +71,22 @@ jobs:
6771
pip install tox-gh-actions
6872
- name: Run tox
6973
run: tox
74+
docker-build-test:
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Checkout code
78+
uses: actions/checkout@v4
79+
- name: Set up Docker Buildx
80+
uses: docker/setup-buildx-action@v3
81+
- name: Get version from pyproject.toml
82+
id: get-version
83+
run: |
84+
VERSION=$(grep -m1 'version = ' pyproject.toml | cut -d'"' -f2)
85+
echo "version=$VERSION" >> $GITHUB_OUTPUT
86+
- name: Build Docker image
87+
run: |
88+
docker build \
89+
--build-arg VERSION_TAG=${{ steps.get-version.outputs.version }} \
90+
-t sherlock-test:latest .
91+
- name: Test Docker image runs
92+
run: docker run --rm sherlock-test:latest --version
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Modified Target Validation
2+
3+
on:
4+
pull_request_target:
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+
permissions:
14+
contents: read
15+
pull-requests: write
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v5
19+
with:
20+
ref: ${{ github.base_ref }}
21+
fetch-depth: 1
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v6
25+
with:
26+
python-version: '3.13'
27+
28+
- name: Install Poetry
29+
uses: abatilo/actions-poetry@v4
30+
with:
31+
poetry-version: 'latest'
32+
33+
- name: Install dependencies
34+
run: |
35+
poetry install --no-interaction --with dev
36+
37+
- name: Drop in place updated manifest from base
38+
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
43+
44+
- name: Discover modified targets
45+
id: discover-modified
46+
run: |
47+
CHANGED=$(
48+
python - <<'EOF'
49+
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)
52+
53+
changed = []
54+
for k, v in head.items():
55+
if k not in base or base[k] != v:
56+
changed.append(k)
57+
58+
print(",".join(sorted(changed)))
59+
EOF
60+
)
61+
62+
# Preserve changelist
63+
echo -e ">>> Changed targets: \n$(echo $CHANGED | tr ',' '\n')"
64+
echo "changed_targets=$CHANGED" >> "$GITHUB_OUTPUT"
65+
66+
- name: Validate modified targets
67+
if: steps.discover-modified.outputs.changed_targets != ''
68+
continue-on-error: true
69+
run: |
70+
poetry run pytest -q --tb no -rA -m validate_targets -n 20 \
71+
--chunked-sites "${{ steps.discover-modified.outputs.changed_targets }}" \
72+
--junitxml=validation_results.xml
73+
74+
- name: Prepare validation summary
75+
if: steps.discover-modified.outputs.changed_targets != ''
76+
id: prepare-summary
77+
run: |
78+
summary=$(
79+
poetry run python devel/summarize_site_validation.py validation_results.xml || echo "Failed to generate summary of test results"
80+
)
81+
echo "$summary" > validation_summary.md
82+
83+
- name: Announce validation results
84+
if: steps.discover-modified.outputs.changed_targets != ''
85+
uses: actions/github-script@v8
86+
with:
87+
script: |
88+
const fs = require('fs');
89+
const body = fs.readFileSync('validation_summary.md', 'utf8');
90+
await github.rest.issues.createComment({
91+
issue_number: context.payload.pull_request.number,
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
body: body,
95+
});
96+
97+
- name: This step shows as ran when no modifications are found
98+
if: steps.discover-modified.outputs.changed_targets == ''
99+
run: |
100+
echo "No modified targets found"

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# 1. Update the version tag in the Dockerfile to match the version in sherlock/__init__.py
33
# 2. Update the VCS_REF tag to match the tagged version's FULL commit hash
44
# 3. Build image with BOTH latest and version tags
5-
# i.e. `docker build -t sherlock/sherlock:0.15.0 -t sherlock/sherlock:latest .`
5+
# i.e. `docker build -t sherlock/sherlock:0.16.0 -t sherlock/sherlock:latest .`
66

7-
FROM python:3.12-slim-bullseye as build
7+
FROM python:3.12-slim-bullseye AS build
88
WORKDIR /sherlock
99

1010
RUN pip3 install --no-cache-dir --upgrade pip

devel/summarize_site_validation.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python
2+
# This module summarizes the results of site validation tests queued by
3+
# workflow validate_modified_targets for presentation in Issue comments.
4+
5+
from defusedxml import ElementTree as ET
6+
import sys
7+
from pathlib import Path
8+
9+
def summarize_junit_xml(xml_path: Path) -> str:
10+
tree = ET.parse(xml_path)
11+
root = tree.getroot()
12+
suite = root.find('testsuite')
13+
14+
pass_message: str = ":heavy_check_mark: &nbsp; Pass"
15+
fail_message: str = ":x: &nbsp; Fail"
16+
17+
if suite is None:
18+
raise ValueError("Invalid JUnit XML: No testsuite found")
19+
20+
summary_lines: list[str] = []
21+
summary_lines.append("#### Automatic validation of changes\n")
22+
summary_lines.append("| Target | F+ Check | F- Check |")
23+
summary_lines.append("|---|---|---|")
24+
25+
failures = int(suite.get('failures', 0))
26+
errors_detected: bool = False
27+
28+
results: dict[str, dict[str, str]] = {}
29+
30+
for testcase in suite.findall('testcase'):
31+
test_name = testcase.get('name').split('[')[0]
32+
site_name = testcase.get('name').split('[')[1].rstrip(']')
33+
failure = testcase.find('failure')
34+
error = testcase.find('error')
35+
36+
if site_name not in results:
37+
results[site_name] = {}
38+
39+
if test_name == "test_false_neg":
40+
results[site_name]['F- Check'] = pass_message if failure is None and error is None else fail_message
41+
elif test_name == "test_false_pos":
42+
results[site_name]['F+ Check'] = pass_message if failure is None and error is None else fail_message
43+
44+
if error is not None:
45+
errors_detected = True
46+
47+
for result in results:
48+
summary_lines.append(f"| {result} | {results[result].get('F+ Check', 'Error!')} | {results[result].get('F- Check', 'Error!')} |")
49+
50+
if failures > 0:
51+
summary_lines.append("\n___\n" +
52+
"\nFailures were detected on at least one updated target. Commits containing accuracy failures" +
53+
" will often not be merged (unless a rationale is provided, such as false negatives due to regional differences).")
54+
55+
if errors_detected:
56+
summary_lines.append("\n___\n" +
57+
"\n**Errors were detected during validation. Please review the workflow logs.**")
58+
59+
return "\n".join(summary_lines)
60+
61+
if __name__ == "__main__":
62+
if len(sys.argv) != 2:
63+
print("Usage: summarize_site_validation.py <junit-xml-file>")
64+
sys.exit(1)
65+
66+
xml_path: Path = Path(sys.argv[1])
67+
if not xml_path.is_file():
68+
print(f"Error: File '{xml_path}' does not exist.")
69+
sys.exit(1)
70+
71+
summary: str = summarize_junit_xml(xml_path)
72+
print(summary)

docs/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<p align=center>
1+
<p align="center">
22
<br>
3-
<a href="https://sherlock-project.github.io/" target="_blank"><img src="images/sherlock-logo.png"/></a>
3+
<a href="https://sherlock-project.github.io/" target="_blank"><img src="images/sherlock-logo.png" alt="sherlock"/></a>
44
<br>
55
<span>Hunt down social media accounts by username across <a href="https://sherlockproject.xyz/sites">400+ social networks</a></span>
66
<br>
@@ -15,8 +15,7 @@
1515
</p>
1616

1717
<p align="center">
18-
<img width="70%" height="70%" src="images/demo.png"/>
19-
</a>
18+
<img width="70%" height="70%" src="images/demo.png" alt="demo"/>
2019
</p>
2120

2221

@@ -115,14 +114,14 @@ $ echo '{"usernames":["user123"]}' | apify call -so netmilk/sherlock
115114
}]
116115
```
117116

118-
Read more about the [Sherlock Actor](../.actor/README.md), including how to use it programmaticaly via the Apify [API](https://apify.com/netmilk/sherlock/api?fpr=sherlock), [CLI](https://docs.apify.com/cli/?fpr=sherlock) and [JS/TS and Python SDKs](https://docs.apify.com/sdk?fpr=sherlock).
117+
Read more about the [Sherlock Actor](../.actor/README.md), including how to use it programmatically via the Apify [API](https://apify.com/netmilk/sherlock/api?fpr=sherlock), [CLI](https://docs.apify.com/cli/?fpr=sherlock) and [JS/TS and Python SDKs](https://docs.apify.com/sdk?fpr=sherlock).
119118

120119
## Credits
121120

122121
Thank you to everyone who has contributed to Sherlock! ❤️
123122

124123
<a href="https://github.com/sherlock-project/sherlock/graphs/contributors">
125-
<img src="https://contrib.rocks/image?&columns=25&max=10000&&repo=sherlock-project/sherlock" noZoom />
124+
<img src="https://contrib.rocks/image?&columns=25&max=10000&&repo=sherlock-project/sherlock" alt="contributors"/>
126125
</a>
127126

128127
## Star history

0 commit comments

Comments
 (0)