Skip to content

Commit fe95532

Browse files
committed
Improve image runner for list of disallowed image domains for GitHub Actions
Improve image runner for list of disallowed image domains for GitHub Actions
1 parent 5ccb2e0 commit fe95532

2 files changed

Lines changed: 94 additions & 2 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# This file contains a list of disallowed image domains for GitHub Actions
2+
3+
# Social Media Platforms
4+
facebook.com
5+
fbcdn.net
6+
instagram.com
7+
cdninstagram.com
8+
linkedin.com
9+
licdn.com
10+
pinterest.com
11+
pinimg.com
12+
threads.net
13+
cdnthreads.com
14+
tumblr.com
15+
media.tumblr.com
16+
twitter.com
17+
pbs.twimg.com
18+
19+
# Video & Streaming Platforms
20+
vimeo.com
21+
vimeocdn.com
22+
youtube.com
23+
ytimg.com
24+
googleusercontent.com
25+
26+
# Image & Photo Sharing Platforms
27+
pixelfed.org
28+
files.pixelfed.org
29+
30+
# Chat & Messaging Platforms
31+
discord.com
32+
discordapp.com
33+
discordapp.net
34+
discordcdn.com
35+
slack.com
36+
slack-edge.com
37+
snapchat.com
38+
sc-cdn.net
39+
telegram.org
40+
t.me
41+
telegra.ph
42+
telegram-cdn.org
43+
wechat.com
44+
wx.qq.com
45+
46+
# Short Video & Entertainment Platforms
47+
tiktok.com
48+
bytecdn.com
49+
tiktokcdn.com
50+
51+
# Forums & Community Platforms
52+
reddit.com
53+
redditmedia.com
54+
redd.it
55+
56+
# Blogging & Publishing Platforms
57+
medium.com
58+
cdn-images-1.medium.com
59+
mastodon.social
60+
files.mastodon.social
61+
62+
# Other Platforms (General purpose / Multi-use)
63+
qq.com
64+
qlogo.cn

.github/scripts/validate_images.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
'en': os.path.join('docs', 'en'),
1111
}
1212

13+
# Path to disallowed domains file
14+
DISALLOWED_DOMAINS_FILE = os.path.join('.github', 'ci', 'disallowed_image_domains.txt')
15+
1316
# Timeouts for external image check (in seconds)
1417
HTTP_TIMEOUT = 3
1518

@@ -32,6 +35,21 @@
3235
'TE': 'Trailers',
3336
}
3437

38+
def load_disallowed_domains(file_path):
39+
"""Load disallowed domains from a text file into a set."""
40+
disallowed_domains = set()
41+
if os.path.exists(file_path):
42+
with open(file_path, 'r', encoding='utf-8') as f:
43+
for line in f:
44+
line = line.strip()
45+
if line and not line.startswith("#"):
46+
disallowed_domains.add(line.lower())
47+
return disallowed_domains
48+
49+
def is_disallowed_url(path, disallowed_domains):
50+
"""Return True if the URL contains any disallowed domain."""
51+
return any(domain in path.lower() for domain in disallowed_domains)
52+
3553
def find_markdown_files(base_dirs):
3654
"""Recursively find all markdown files in given directories."""
3755
md_files = []
@@ -109,7 +127,7 @@ def validate_external_image(path, checked_urls):
109127
checked_urls[path] = 'timeout'
110128
return 'timeout'
111129

112-
def validate_images(md_files):
130+
def validate_images(md_files, disallowed_domains):
113131
"""Validate all image references in markdown files."""
114132
issues = []
115133
checked_urls = {}
@@ -121,6 +139,12 @@ def validate_images(md_files):
121139
# Checking external image
122140
print(f"🔵 Checking external image {path}")
123141

142+
if is_disallowed_url(path, disallowed_domains):
143+
description = 'disallowed domain'
144+
issues.append((lang, md_file, line_num, path, description))
145+
print(f"❌ Disallowed domain detected {path}")
146+
continue
147+
124148
if path in checked_urls:
125149
error_desc = checked_urls[path]
126150
else:
@@ -141,12 +165,16 @@ def validate_images(md_files):
141165
if __name__ == "__main__":
142166
print("🔍 Scanning markdown files for image references in: " + ", ".join([f"{lang} ({dir})" for lang, dir in DOCS_DIRS.items()]))
143167

168+
disallowed_domains = load_disallowed_domains(DISALLOWED_DOMAINS_FILE)
169+
if disallowed_domains:
170+
print(f"ℹ️ Loaded {len(disallowed_domains)} disallowed domains from {DISALLOWED_DOMAINS_FILE}")
171+
144172
md_files = find_markdown_files(DOCS_DIRS)
145173
if not md_files:
146174
print("⚠️ No Markdown files found in specified directories.")
147175
sys.exit(0)
148176

149-
issues = validate_images(md_files)
177+
issues = validate_images(md_files, disallowed_domains)
150178

151179
print("\n🔎 Validation Results:")
152180

0 commit comments

Comments
 (0)