Skip to content

Commit 4c397cf

Browse files
authored
Merge pull request #416 from devicons/TB_contributing
Updated CONTRIBUTING
2 parents a0d90ea + 1038b7a commit 4c397cf

6 files changed

Lines changed: 150 additions & 159 deletions

File tree

.github/scripts/build_assets/SeleniumRunner.py

Lines changed: 80 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,20 @@ def upload_icomoon(self, icomoon_json_path: str):
8989
:raises TimeoutException: happens when elements are not found.
9090
"""
9191
print("Uploading icomoon.json file...")
92-
try:
93-
self.click_hamburger_input()
94-
95-
# find the file input and enter the file path
96-
import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input")
97-
import_btn.send_keys(icomoon_json_path)
98-
except SeleniumTimeoutException as e:
99-
print(e.stacktrace)
100-
print("Selenium timed out. Couldn't find import button.")
101-
self.close()
102-
raise e
103-
except Exception as e:
104-
self.close()
105-
raise e
92+
self.click_hamburger_input()
93+
94+
# find the file input and enter the file path
95+
import_btn = self.driver.find_element(By.XPATH, "(//li[@class='file'])[1]//input")
96+
import_btn.send_keys(icomoon_json_path)
10697

10798
try:
10899
confirm_btn = WebDriverWait(self.driver, SeleniumRunner.MED_WAIT_IN_SEC).until(
109100
ec.element_to_be_clickable((By.XPATH, "//div[@class='overlay']//button[text()='Yes']"))
110101
)
111102
confirm_btn.click()
112103
except SeleniumTimeoutException as e:
113-
print(e.stacktrace)
114-
print("Cannot find the confirm button when uploading the icomoon.json",
115-
"Ensure that the icomoon.json is in the correct format for Icomoon.io",
116-
sep='\n')
117-
self.close()
104+
raise Exception("Cannot find the confirm button when uploading the icomoon.json" \
105+
"Ensure that the icomoon.json is in the correct format for Icomoon.io")
118106

119107
print("JSON file uploaded.")
120108

@@ -126,39 +114,29 @@ def upload_svgs(self, svgs: List[str], screenshot_folder: str=""):
126114
the value is provided, it means the user want to take a screenshot
127115
of each icon.
128116
"""
129-
try:
130-
print("Uploading SVGs...")
117+
print("Uploading SVGs...")
131118

132-
edit_mode_btn = self.driver.find_element_by_css_selector(
133-
"div.btnBar button i.icon-edit"
134-
)
135-
edit_mode_btn.click()
136-
137-
self.click_hamburger_input()
138-
139-
for i in range(len(svgs)):
140-
import_btn = self.driver.find_element_by_css_selector(
141-
"li.file input[type=file]"
142-
)
143-
import_btn.send_keys(svgs[i])
144-
print(f"Uploaded {svgs[i]}")
145-
self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss")
146-
self.click_on_just_added_icon(screenshot_folder, i)
147-
148-
# take a screenshot of the icons that were just added
149-
new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve())
150-
self.driver.save_screenshot(new_icons_path);
151-
152-
# select all the svgs so that the newly added svg are part of the collection
153-
self.click_hamburger_input()
154-
select_all_button = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
155-
ec.element_to_be_clickable((By.XPATH, "//button[text()='Select All']"))
119+
edit_mode_btn = self.driver.find_element_by_css_selector(
120+
"div.btnBar button i.icon-edit"
121+
)
122+
edit_mode_btn.click()
123+
124+
self.click_hamburger_input()
125+
126+
for i in range(len(svgs)):
127+
import_btn = self.driver.find_element_by_css_selector(
128+
"li.file input[type=file]"
156129
)
157-
select_all_button.click()
158-
print("Finished uploading the svgs...")
159-
except Exception as e:
160-
self.close()
161-
raise e
130+
import_btn.send_keys(svgs[i])
131+
print(f"Uploaded {svgs[i]}")
132+
self.test_for_possible_alert(self.SHORT_WAIT_IN_SEC, "Dismiss")
133+
self.click_on_just_added_icon(screenshot_folder, i)
134+
135+
# take a screenshot of the icons that were just added
136+
new_icons_path = str(Path(screenshot_folder, "new_icons.png").resolve())
137+
self.driver.save_screenshot(new_icons_path);
138+
139+
print("Finished uploading the svgs...")
162140

163141
def click_hamburger_input(self):
164142
"""
@@ -167,20 +145,16 @@ def click_hamburger_input(self):
167145
input two times before the menu appears.
168146
:return: None.
169147
"""
170-
try:
171-
hamburger_input = self.driver.find_element_by_xpath(
172-
"(//i[@class='icon-menu'])[2]"
173-
)
148+
hamburger_input = self.driver.find_element_by_xpath(
149+
"(//i[@class='icon-menu'])[2]"
150+
)
174151

175-
menu_appear_callback = ec.element_to_be_clickable(
176-
(By.CSS_SELECTOR, "h1 ul.menuList2")
177-
)
152+
menu_appear_callback = ec.element_to_be_clickable(
153+
(By.CSS_SELECTOR, "h1 ul.menuList2")
154+
)
178155

179-
while not menu_appear_callback(self.driver):
180-
hamburger_input.click()
181-
except Exception as e:
182-
self.close()
183-
raise e
156+
while not menu_appear_callback(self.driver):
157+
hamburger_input.click()
184158

185159
def test_for_possible_alert(self, wait_period: float, btn_text: str):
186160
"""
@@ -204,25 +178,21 @@ def click_on_just_added_icon(self, screenshot_folder: str, index: int):
204178
Click on the most recently added icon so we can remove the colors
205179
and take a snapshot if needed.
206180
"""
207-
try:
208-
recently_uploaded_icon = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
209-
ec.element_to_be_clickable((By.XPATH, "//div[@id='set0']//mi-box[1]//div"))
210-
)
211-
recently_uploaded_icon.click()
181+
recently_uploaded_icon = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
182+
ec.element_to_be_clickable((By.XPATH, "//div[@id='set0']//mi-box[1]//div"))
183+
)
184+
recently_uploaded_icon.click()
212185

213-
self.remove_color_from_icon()
186+
self.remove_color_from_icon()
214187

215-
if screenshot_folder:
216-
screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
217-
self.driver.save_screenshot(screenshot_path)
218-
print("Took screenshot and saved it at " + screenshot_path)
188+
if screenshot_folder:
189+
screenshot_path = str(Path(screenshot_folder, f"screenshot_{index}.png").resolve())
190+
self.driver.save_screenshot(screenshot_path)
191+
print("Took screenshot and saved it at " + screenshot_path)
219192

220-
close_btn = self.driver \
221-
.find_element_by_css_selector("div.overlayWindow i.icon-close")
222-
close_btn.click()
223-
except Exception as e:
224-
self.close()
225-
raise e
193+
close_btn = self.driver \
194+
.find_element_by_css_selector("div.overlayWindow i.icon-close")
195+
close_btn.click()
226196

227197
def remove_color_from_icon(self):
228198
"""
@@ -232,38 +202,45 @@ def remove_color_from_icon(self):
232202
The color removal is also necessary so that the Icomoon-generated
233203
icons fit within one font symbol/ligiature.
234204
"""
235-
color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until(
236-
ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet"))
237-
)
238-
color_tab.click()
205+
try:
206+
color_tab = WebDriverWait(self.driver, self.SHORT_WAIT_IN_SEC).until(
207+
ec.element_to_be_clickable((By.CSS_SELECTOR, "div.overlayWindow i.icon-droplet"))
208+
)
209+
color_tab.click()
239210

240-
remove_color_btn = self.driver \
241-
.find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
242-
remove_color_btn.click()
211+
remove_color_btn = self.driver \
212+
.find_element_by_css_selector("div.overlayWindow i.icon-droplet-cross")
213+
remove_color_btn.click()
214+
except SeleniumTimeoutException:
215+
pass # do nothing cause sometimes, the color tab doesn't appear in the site
243216

244217
def download_icomoon_fonts(self, zip_path: Path):
245218
"""
246219
Download the icomoon.zip from icomoon.io.
247220
:param zip_path: the path to the zip file after it's downloaded.
248221
"""
249-
try:
250-
print("Downloading Font files...")
251-
self.driver.find_element_by_css_selector(
252-
"a[href='#/select/font']"
253-
).click()
254-
255-
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
256-
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
257-
ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
258-
)
259-
download_btn.click()
260-
if self.wait_for_zip(zip_path):
261-
print("Font files downloaded.")
262-
else:
263-
raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.")
264-
except Exception as e:
265-
self.close()
266-
raise e
222+
# select all the svgs so that the newly added svg are part of the collection
223+
self.click_hamburger_input()
224+
select_all_button = WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
225+
ec.element_to_be_clickable((By.XPATH, "//button[text()='Select All']"))
226+
)
227+
select_all_button.click()
228+
229+
print("Downloading Font files...")
230+
font_tab = self.driver.find_element_by_css_selector(
231+
"a[href='#/select/font']"
232+
)
233+
font_tab.click()
234+
235+
self.test_for_possible_alert(self.MED_WAIT_IN_SEC, "Continue")
236+
download_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
237+
ec.presence_of_element_located((By.CSS_SELECTOR, "button.btn4 span"))
238+
)
239+
download_btn.click()
240+
if self.wait_for_zip(zip_path):
241+
print("Font files downloaded.")
242+
else:
243+
raise TimeoutError(f"Couldn't find {zip_path} after download button was clicked.")
267244

268245
def wait_for_zip(self, zip_path: Path) -> bool:
269246
"""

.github/scripts/icomoon_build.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
import sys
23
from selenium.common.exceptions import TimeoutException
34

45
# pycharm complains that build_assets is an unresolved ref
@@ -11,8 +12,7 @@ def main():
1112
args = arg_getters.get_selenium_runner_args()
1213
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
1314
if len(new_icons) == 0:
14-
print("No files need to be uploaded. Ending script...")
15-
return
15+
sys.exit("No files need to be uploaded. Ending script...")
1616

1717
# print list of new icons
1818
print("List of new icons:", *new_icons, sep = "\n")
@@ -32,10 +32,11 @@ def main():
3232
filehandler.rename_extracted_files(args.download_path)
3333
print("Task completed.")
3434
except TimeoutException as e:
35-
print(e)
36-
print(e.stacktrace)
35+
sys.exit("Selenium Time Out Error: \n" + str(e))
36+
except Exception as e:
37+
sys.exit(e)
3738
finally:
38-
runner.close()
39+
runner.close()
3940

4041

4142
if __name__ == "__main__":

.github/scripts/icomoon_peek.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def main():
3838
runner.upload_svgs(svgs, screenshot_folder)
3939
print("Task completed.")
4040
except TimeoutException as e:
41-
print("Selenium Time Out Error: ", e.stacktrace, sep='\n')
41+
sys.exit("Selenium Time Out Error: \n" + str(e))
4242
except Exception as e:
43-
print(e)
43+
sys.exit(e)
4444
finally:
45-
runner.close()
45+
runner.close()
4646

4747

4848
def find_object_added_in_this_pr(icons: List[dict], pr_title: str):

.github/workflows/build_icons.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: npm run build-css
3535
- name: Upload screenshot of the newly made icons
3636
id: imgur_step
37-
uses: devicons/public-upload-to-imgur@v2
37+
uses: devicons/public-upload-to-imgur@v2.1
3838
if: success()
3939
with:
4040
path: ./new_icons.png

.github/workflows/peek_icons.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ jobs:
99
runs-on: windows-2019
1010
steps:
1111
- uses: actions/checkout@v2
12-
with:
13-
ref: ${{ github.head_ref }}
14-
repository: ${{ github.event.pull_request.head.repo.full_name}}
1512
- name: Setup Python v3.8
1613
uses: actions/setup-python@v2
1714
with:
@@ -36,14 +33,14 @@ jobs:
3633
path: ./geckodriver.log
3734
- name: Upload screenshot of the newly made icons
3835
id: icons_overview_img_step
39-
uses: devicons/public-upload-to-imgur@v2
36+
uses: devicons/public-upload-to-imgur@v2.1
4037
if: success()
4138
with:
4239
path: ./screenshots/new_icons.png
4340
client_id: ${{secrets.IMGUR_CLIENT_ID}}
4441
- name: Upload zoomed in screenshot of the newly made icons
4542
id: icons_detailed_img_step
46-
uses: devicons/public-upload-to-imgur@v2
43+
uses: devicons/public-upload-to-imgur@v2.1
4744
if: success()
4845
with:
4946
path: ./screenshots/screenshot_*.png

0 commit comments

Comments
 (0)