Skip to content

Commit bfe1569

Browse files
committed
Added a peek script
1 parent 96231aa commit bfe1569

4 files changed

Lines changed: 116 additions & 12 deletions

File tree

.github/scripts/build_assets/SeleniumRunner.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ class SeleniumRunner:
3636
"""
3737
ICOMOON_URL = "https://icomoon.io/app/#/select"
3838

39-
def __init__(self, icomoon_json_path: str, download_path: str,
40-
geckodriver_path: str, headless):
39+
def __init__(self, download_path: str,
40+
geckodriver_path: str, headless: bool):
4141
"""
4242
Create a SeleniumRunner object.
43-
:param icomoon_json_path: a path to the iconmoon.json.
4443
:param download_path: the location where you want to download
4544
the icomoon.zip to.
4645
:param geckodriver_path: the path to the firefox executable.
4746
:param headless: whether to run browser in headless (no UI) mode.
4847
"""
49-
self.icomoon_json_path = icomoon_json_path
50-
self.download_path = download_path
5148
self.driver = None
52-
self.set_options(geckodriver_path, headless)
49+
self.set_options(download_path, geckodriver_path, headless)
5350

54-
def set_options(self, geckodriver_path: str, headless: bool):
51+
def set_options(self, download_path: str, geckodriver_path: str,
52+
headless: bool):
5553
"""
5654
Build the WebDriver with Firefox Options allowing downloads and
5755
set download to download_path.
56+
:param download_path: the location where you want to download
5857
:param geckodriver_path: the path to the firefox executable.
58+
the icomoon.zip to.
5959
:param headless: whether to run browser in headless (no UI) mode.
6060
6161
:raises AssertionError: if the page title does not contain
@@ -69,16 +69,17 @@ def set_options(self, geckodriver_path: str, headless: bool):
6969

7070
# set the default download path to downloadPath
7171
options.set_preference("browser.download.folderList", 2)
72-
options.set_preference("browser.download.dir", self.download_path)
72+
options.set_preference("browser.download.dir", download_path)
7373
options.headless = headless
7474

7575
self.driver = WebDriver(options=options, executable_path=geckodriver_path)
7676
self.driver.get(self.ICOMOON_URL)
7777
assert "IcoMoon App" in self.driver.title
7878

79-
def upload_icomoon(self):
79+
def upload_icomoon(self, icomoon_json_path: str):
8080
"""
8181
Upload the icomoon.json to icomoon.io.
82+
:param icomoon_json_path: a path to the iconmoon.json.
8283
:raises TimeoutException: happens when elements are not found.
8384
"""
8485
print("Uploading icomoon.json file...")
@@ -87,7 +88,7 @@ def upload_icomoon(self):
8788
import_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
8889
ec.presence_of_element_located((By.CSS_SELECTOR, "div#file input"))
8990
)
90-
import_btn.send_keys(self.icomoon_json_path)
91+
import_btn.send_keys(icomoon_json_path)
9192
except Exception as e:
9293
self.close()
9394
raise e

.github/scripts/icomoon_peek.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from pathlib import Path
2+
from argparse import ArgumentParser
3+
from selenium.common.exceptions import TimeoutException
4+
5+
# pycharm complains that build_assets is an unresolved ref
6+
# don't worry about it, the script still runs
7+
from build_assets.SeleniumRunner import SeleniumRunner
8+
from build_assets import filehandler
9+
from build_assets.PathResolverAction import PathResolverAction
10+
11+
12+
def main():
13+
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
14+
15+
parser.add_argument("--headless",
16+
help="Whether to run the browser in headless/no UI mode",
17+
action="store_true")
18+
19+
parser.add_argument("geckodriver_path",
20+
help="The path to the firefox executable file",
21+
action=PathResolverAction)
22+
23+
parser.add_argument("icomoon_json_path",
24+
help="The path to the icomoon.json aka the selection.json created by Icomoon",
25+
action=PathResolverAction)
26+
27+
parser.add_argument("devicon_json_path",
28+
help="The path to the devicon.json",
29+
action=PathResolverAction)
30+
31+
parser.add_argument("icons_folder_path",
32+
help="The path to the icons folder",
33+
action=PathResolverAction)
34+
35+
parser.add_argument("download_path",
36+
help="The path where you'd like to download the Icomoon files to",
37+
action=PathResolverAction)
38+
39+
args = parser.parse_args()
40+
41+
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
42+
if len(new_icons) == 0:
43+
print("No files need to be peek. Ending script...")
44+
return
45+
46+
# print list of new icons, separated by comma
47+
print("List of new icons:")
48+
print(*new_icons, sep = "\n")
49+
try:
50+
runner = SeleniumRunner(args.download_path,
51+
args.geckodriver_path, args.headless)
52+
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
53+
runner.upload_svgs(svgs)
54+
runner.close()
55+
print("Task completed.")
56+
except TimeoutException as e:
57+
print(e)
58+
print(e.stacktrace)
59+
runner.close()
60+
61+
62+
if __name__ == "__main__":
63+
main()

.github/scripts/icomoon_upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def main():
4747
print("List of new icons:")
4848
print(*new_icons, sep = "\n")
4949
try:
50-
runner = SeleniumRunner(args.icomoon_json_path, args.download_path,
50+
runner = SeleniumRunner(args.download_path,
5151
args.geckodriver_path, args.headless)
52-
runner.upload_icomoon()
52+
runner.upload_icomoon(args.icomoon_json_path)
5353
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
5454
runner.upload_svgs(svgs)
5555

.github/workflows/peek_icons.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Peek Icons
2+
on:
3+
pull_request:
4+
types: [labeled]
5+
jobs:
6+
build:
7+
name: Get Fonts From Icomoon
8+
if: contains(github.event.pull_request.labels.*.name, 'bot:peek')
9+
runs-on: windows-2019
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.head_ref }}
14+
repository: ${{ github.event.pull_request.head.repo.full_name}}
15+
- name: Setup Python v3.8
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: 3.8
19+
- name: Install dependencies (python, pip, npm)
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r ./.github/scripts/requirements.txt
23+
npm install
24+
- name: Run icomoon_peek.py
25+
run: >
26+
python ./.github/scripts/icomoon_peek.py
27+
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe
28+
./icomoon.json ./devicon.json ./icons ./ --headless
29+
- name: Upload geckodriver.log for debugging purposes
30+
uses: actions/upload-artifact@v2
31+
if: ${{failure()}}
32+
with:
33+
name: geckodriver-log
34+
path: ./geckodriver.log
35+
- name: Upload screenshot of the newly made icons
36+
uses: actions/upload-artifact@v2
37+
if: ${{success()}}
38+
with:
39+
name: new_icons
40+
path: ./new_icons.png

0 commit comments

Comments
 (0)