Skip to content

Commit d773208

Browse files
committed
Add color checking to peek-bot
1 parent 63f3b57 commit d773208

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

.github/scripts/build_assets/selenium_runner/PeekSeleniumRunner.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
from build_assets.selenium_runner.enums import IcomoonPage, IcomoonAlerts
66

77
class PeekSeleniumRunner(SeleniumRunner):
8-
def peek(self, svgs: List[str], screenshot_folder: str):
8+
def peek(self, svgs: List[str], screenshot_folder: str, icon_info: dict):
99
"""
1010
Upload the SVGs and peek at how Icomoon interpret its SVGs and
1111
font versions.
1212
:param svgs: a list of svg Paths that we'll upload to icomoon.
1313
:param screenshot_folder: the name of the screenshot_folder.
14+
:param icon_info: a dictionary containing info on an icon. Taken from the devicon.json.
1415
:return an array of svgs with strokes as strings. These show which icon
1516
contains stroke.
1617
"""
1718
messages = self.peek_svgs(svgs, screenshot_folder)
18-
self.peek_icons(svgs, screenshot_folder)
19+
self.peek_icons(screenshot_folder, icon_info)
1920
return messages
2021

2122
def peek_svgs(self, svgs: List[str], screenshot_folder: str):
@@ -61,10 +62,11 @@ def peek_svgs(self, svgs: List[str], screenshot_folder: str):
6162
print("Finished peeking the svgs...")
6263
return svgs_with_strokes
6364

64-
def peek_icons(self, svgs: List[str], screenshot_folder: str):
65+
def peek_icons(self, screenshot_folder: str, icon_info: dict):
6566
"""
6667
Peek at the icon versions of the SVGs that were uploaded.
6768
:param screenshot_folder: the name of the screenshot_folder.
69+
:param icon_info: a dictionary containing info on an icon. Taken from the devicon.json.
6870
"""
6971
print("Begin peeking at the icons...")
7072
# ensure all icons in the set is selected.
@@ -85,7 +87,7 @@ def peek_icons(self, svgs: List[str], screenshot_folder: str):
8587
main_content = self.driver.find_element_by_xpath(main_content_xpath)
8688
main_content.screenshot(new_icons_path);
8789

88-
# go downward so we get the oldest icon first
90+
# go in reverse order so we get the oldest icon first
8991
icon_divs_xpath = f'//div[@id="glyphSet0"]/div'
9092
icon_divs = self.driver.find_elements_by_xpath(icon_divs_xpath)
9193
icon_divs.reverse()
@@ -98,6 +100,23 @@ def peek_icons(self, svgs: List[str], screenshot_folder: str):
98100
Path(screenshot_folder, f"new_icon_{i}.png").resolve()
99101
)
100102
icon_div.screenshot(icon_screenshot)
103+
104+
i += 1
105+
106+
# test the colors
107+
style = "#glyphSet0 span:first-of-type {color: " + icon_info["color"] + "}"
108+
script = f"document.styleSheets[0].insertRule({style}, 0)"
109+
self.driver.execute_script(script)
110+
i = 0
111+
for icon_div in icon_divs:
112+
if not icon_div.is_displayed():
113+
continue
114+
115+
icon_screenshot = str(
116+
Path(screenshot_folder, f"new_colored_icon_{i}.png").resolve()
117+
)
118+
icon_div.screenshot(icon_screenshot)
119+
101120
i += 1
102121

103122
print("Finished peeking the icons...")

.github/scripts/build_assets/selenium_runner/SeleniumRunner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def edit_svg(self, screenshot_folder: str=None, index: int=None):
303303
except SeleniumTimeoutException:
304304
pass # do nothing cause sometimes, the color tab doesn't appear in the site
305305

306-
if screenshot_folder != None and index != None:
306+
if screenshot_folder is not None and index is not None:
307307
edit_screen_selector = "div.overlay div.overlayWindow"
308308
screenshot_path = str(
309309
Path(screenshot_folder, f"new_svg_{index}.png").resolve()

.github/scripts/icomoon_peek.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ def main():
77
runner = None
88
try:
99
args = arg_getters.get_selenium_runner_args(peek_mode=True)
10-
new_icons = filehandler.get_json_file_content(args.devicon_json_path)
10+
all_icons = filehandler.get_json_file_content(args.devicon_json_path)
1111

1212
# get only the icon object that has the name matching the pr title
13-
filtered_icon = util.find_object_added_in_pr(new_icons, args.pr_title)
13+
filtered_icon = util.find_object_added_in_pr(all_icons, args.pr_title)
1414
check_devicon_object(filtered_icon)
1515
print("Icon being checked:", filtered_icon, sep = "\n", end='\n\n')
1616

1717
runner = PeekSeleniumRunner(args.download_path, args.geckodriver_path, args.headless)
1818
svgs = filehandler.get_svgs_paths([filtered_icon], args.icons_folder_path, True)
1919
screenshot_folder = filehandler.create_screenshot_folder("./")
20-
svgs_with_strokes = runner.peek(svgs, screenshot_folder)
20+
svgs_with_strokes = runner.peek(svgs, screenshot_folder, filtered_icon)
2121
print("Task completed.")
2222

2323
message = ""
@@ -36,6 +36,7 @@ def main():
3636
def check_devicon_object(icon: dict):
3737
"""
3838
Check that the devicon object added is up to standard.
39+
:param icon: a dictionary containing info on an icon. Taken from the devicon.json.
3940
:return a string containing the error messages if any.
4041
"""
4142
err_msgs = []

.github/workflows/post_peek_screenshot.yml

+15-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ jobs:
7272
path: ./screenshots/new_icon_*.png
7373
client_id: ${{secrets.IMGUR_CLIENT_ID}}
7474

75+
- name: Upload zoomed in screenshot of the colored icons gotten from the artifacts
76+
id: colored_icons_detailed_img_step
77+
uses: devicons/[email protected]
78+
if: env.PEEK_STATUS == 'success' && success()
79+
with:
80+
path: ./screenshots/new_colored_icon_*.png
81+
client_id: ${{secrets.IMGUR_CLIENT_ID}}
82+
7583
- name: Comment on the PR about the result - Success
7684
uses: jungwinter/comment@v1 # let us comment on a specific PR
7785
if: env.PEEK_STATUS == 'success' && success()
@@ -84,15 +92,18 @@ jobs:
8492
Here are the SVGs as intepreted by Icomoon when we upload the files:
8593
{0}
8694
87-
Here are the zoomed-in screenshots of the added icons as **SVGs**. This is how Icomoon intepret the uploaded SVGs:
95+
Here are the zoomed-in screenshots of the added icons as **SVGs**:
8896
{1}
8997
9098
Here are the icons that will be generated by Icomoon:
9199
{2}
92100
93-
Here are the zoomed-in screenshots of the added icons as **icons**. This is what the font will look like:
101+
Here are the zoomed-in screenshots of the added icons as **icons**:
94102
{3}
103+
104+
Here are the colored versions:
95105
{4}
106+
{5}
96107
97108
The maintainers will now check for:
98109
1. The number of Glyphs matches the number of SVGs that were selected.
@@ -103,7 +114,7 @@ jobs:
103114
104115
Thank you for contributing to Devicon! I hope that your icons are accepted into the repository.
105116
106-
Note: If the images don't show up, it's probably because it has been autodeleted by Imgur after 6 months due to our API choice.
117+
Note: If the images don't show up, it has been autodeleted by Imgur after 6 months due to our API choice.
107118
108119
Cheers,
109120
Peek Bot :blush:
@@ -119,6 +130,7 @@ jobs:
119130
join(fromJSON(steps.svgs_detailed_img_step.outputs.markdown_urls), ' '),
120131
fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0],
121132
join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), ' '),
133+
join(fromJSON(steps.colored_icons_detailed_img_step.outputs.markdown_urls), ' '),
122134
steps.err_message_reader.outputs.content
123135
)
124136
}}

0 commit comments

Comments
 (0)