mirror of
https://github.com/konpa/devicon.git
synced 2025-08-12 09:34:36 +02:00
Added a peek script
This commit is contained in:
21
.github/scripts/build_assets/SeleniumRunner.py
vendored
21
.github/scripts/build_assets/SeleniumRunner.py
vendored
@@ -36,26 +36,26 @@ class SeleniumRunner:
|
||||
"""
|
||||
ICOMOON_URL = "https://icomoon.io/app/#/select"
|
||||
|
||||
def __init__(self, icomoon_json_path: str, download_path: str,
|
||||
geckodriver_path: str, headless):
|
||||
def __init__(self, download_path: str,
|
||||
geckodriver_path: str, headless: bool):
|
||||
"""
|
||||
Create a SeleniumRunner object.
|
||||
:param icomoon_json_path: a path to the iconmoon.json.
|
||||
:param download_path: the location where you want to download
|
||||
the icomoon.zip to.
|
||||
:param geckodriver_path: the path to the firefox executable.
|
||||
:param headless: whether to run browser in headless (no UI) mode.
|
||||
"""
|
||||
self.icomoon_json_path = icomoon_json_path
|
||||
self.download_path = download_path
|
||||
self.driver = None
|
||||
self.set_options(geckodriver_path, headless)
|
||||
self.set_options(download_path, geckodriver_path, headless)
|
||||
|
||||
def set_options(self, geckodriver_path: str, headless: bool):
|
||||
def set_options(self, download_path: str, geckodriver_path: str,
|
||||
headless: bool):
|
||||
"""
|
||||
Build the WebDriver with Firefox Options allowing downloads and
|
||||
set download to download_path.
|
||||
:param download_path: the location where you want to download
|
||||
:param geckodriver_path: the path to the firefox executable.
|
||||
the icomoon.zip to.
|
||||
:param headless: whether to run browser in headless (no UI) mode.
|
||||
|
||||
:raises AssertionError: if the page title does not contain
|
||||
@@ -69,16 +69,17 @@ class SeleniumRunner:
|
||||
|
||||
# set the default download path to downloadPath
|
||||
options.set_preference("browser.download.folderList", 2)
|
||||
options.set_preference("browser.download.dir", self.download_path)
|
||||
options.set_preference("browser.download.dir", download_path)
|
||||
options.headless = headless
|
||||
|
||||
self.driver = WebDriver(options=options, executable_path=geckodriver_path)
|
||||
self.driver.get(self.ICOMOON_URL)
|
||||
assert "IcoMoon App" in self.driver.title
|
||||
|
||||
def upload_icomoon(self):
|
||||
def upload_icomoon(self, icomoon_json_path: str):
|
||||
"""
|
||||
Upload the icomoon.json to icomoon.io.
|
||||
:param icomoon_json_path: a path to the iconmoon.json.
|
||||
:raises TimeoutException: happens when elements are not found.
|
||||
"""
|
||||
print("Uploading icomoon.json file...")
|
||||
@@ -87,7 +88,7 @@ class SeleniumRunner:
|
||||
import_btn = WebDriverWait(self.driver, SeleniumRunner.LONG_WAIT_IN_SEC).until(
|
||||
ec.presence_of_element_located((By.CSS_SELECTOR, "div#file input"))
|
||||
)
|
||||
import_btn.send_keys(self.icomoon_json_path)
|
||||
import_btn.send_keys(icomoon_json_path)
|
||||
except Exception as e:
|
||||
self.close()
|
||||
raise e
|
||||
|
63
.github/scripts/icomoon_peek.py
vendored
Normal file
63
.github/scripts/icomoon_peek.py
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
from pathlib import Path
|
||||
from argparse import ArgumentParser
|
||||
from selenium.common.exceptions import TimeoutException
|
||||
|
||||
# pycharm complains that build_assets is an unresolved ref
|
||||
# don't worry about it, the script still runs
|
||||
from build_assets.SeleniumRunner import SeleniumRunner
|
||||
from build_assets import filehandler
|
||||
from build_assets.PathResolverAction import PathResolverAction
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
|
||||
|
||||
parser.add_argument("--headless",
|
||||
help="Whether to run the browser in headless/no UI mode",
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("geckodriver_path",
|
||||
help="The path to the firefox executable file",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icomoon_json_path",
|
||||
help="The path to the icomoon.json aka the selection.json created by Icomoon",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("devicon_json_path",
|
||||
help="The path to the devicon.json",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("icons_folder_path",
|
||||
help="The path to the icons folder",
|
||||
action=PathResolverAction)
|
||||
|
||||
parser.add_argument("download_path",
|
||||
help="The path where you'd like to download the Icomoon files to",
|
||||
action=PathResolverAction)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
|
||||
if len(new_icons) == 0:
|
||||
print("No files need to be peek. Ending script...")
|
||||
return
|
||||
|
||||
# print list of new icons, separated by comma
|
||||
print("List of new icons:")
|
||||
print(*new_icons, sep = "\n")
|
||||
try:
|
||||
runner = SeleniumRunner(args.download_path,
|
||||
args.geckodriver_path, args.headless)
|
||||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
|
||||
runner.upload_svgs(svgs)
|
||||
runner.close()
|
||||
print("Task completed.")
|
||||
except TimeoutException as e:
|
||||
print(e)
|
||||
print(e.stacktrace)
|
||||
runner.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
4
.github/scripts/icomoon_upload.py
vendored
4
.github/scripts/icomoon_upload.py
vendored
@@ -47,9 +47,9 @@ def main():
|
||||
print("List of new icons:")
|
||||
print(*new_icons, sep = "\n")
|
||||
try:
|
||||
runner = SeleniumRunner(args.icomoon_json_path, args.download_path,
|
||||
runner = SeleniumRunner(args.download_path,
|
||||
args.geckodriver_path, args.headless)
|
||||
runner.upload_icomoon()
|
||||
runner.upload_icomoon(args.icomoon_json_path)
|
||||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
|
||||
runner.upload_svgs(svgs)
|
||||
|
||||
|
40
.github/workflows/peek_icons.yml
vendored
Normal file
40
.github/workflows/peek_icons.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Peek Icons
|
||||
on:
|
||||
pull_request:
|
||||
types: [labeled]
|
||||
jobs:
|
||||
build:
|
||||
name: Get Fonts From Icomoon
|
||||
if: contains(github.event.pull_request.labels.*.name, 'bot:peek')
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name}}
|
||||
- name: Setup Python v3.8
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.8
|
||||
- name: Install dependencies (python, pip, npm)
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r ./.github/scripts/requirements.txt
|
||||
npm install
|
||||
- name: Run icomoon_peek.py
|
||||
run: >
|
||||
python ./.github/scripts/icomoon_peek.py
|
||||
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe
|
||||
./icomoon.json ./devicon.json ./icons ./ --headless
|
||||
- name: Upload geckodriver.log for debugging purposes
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{failure()}}
|
||||
with:
|
||||
name: geckodriver-log
|
||||
path: ./geckodriver.log
|
||||
- name: Upload screenshot of the newly made icons
|
||||
uses: actions/upload-artifact@v2
|
||||
if: ${{success()}}
|
||||
with:
|
||||
name: new_icons
|
||||
path: ./new_icons.png
|
Reference in New Issue
Block a user