diff --git a/.github/scripts/build_assets/SeleniumRunner.py b/.github/scripts/build_assets/SeleniumRunner.py index c0d200cf..596ea5b4 100644 --- a/.github/scripts/build_assets/SeleniumRunner.py +++ b/.github/scripts/build_assets/SeleniumRunner.py @@ -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 diff --git a/.github/scripts/icomoon_peek.py b/.github/scripts/icomoon_peek.py new file mode 100644 index 00000000..d2dea007 --- /dev/null +++ b/.github/scripts/icomoon_peek.py @@ -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() diff --git a/.github/scripts/icomoon_upload.py b/.github/scripts/icomoon_upload.py index f24423a3..68e49ab4 100644 --- a/.github/scripts/icomoon_upload.py +++ b/.github/scripts/icomoon_upload.py @@ -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) diff --git a/.github/workflows/build_icons.yml b/.github/workflows/build_icons.yml index fd3fa279..8d333172 100644 --- a/.github/workflows/build_icons.yml +++ b/.github/workflows/build_icons.yml @@ -11,6 +11,7 @@ jobs: - 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: diff --git a/.github/workflows/peek_icons.yml b/.github/workflows/peek_icons.yml new file mode 100644 index 00000000..5ebfa8a1 --- /dev/null +++ b/.github/workflows/peek_icons.yml @@ -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 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a630e382..c58f6c28 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,7 +63,7 @@ Some icons are really simple (like the Apple one), so the original version can b
  • The plain and line versions (with or without wordmark) need to stay as simple as possible. They must have only one color and the paths are united before exporting to svg.
  • Optimize/compress your SVGs. You can use a service like compressor or SVG Editor.
  • -
  • +
  • The icon's strokes and texts must be fills. We use Icomoon to make our icon, which has its requirements

  • diff --git a/gulpfile.js b/gulpfile.js index 9adce05c..2422acd5 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -101,13 +101,22 @@ function createColorsCSS(deviconJson) { font: fonts }, color, + aliases } = fontObj; if (fonts.length === 0 || typeof(color) !== "string") { console.log(`This object doesn't have a font or a color: ${name}`); return ""; } + + // process the icons in the font attr let cssClasses = fonts.map(font => `.devicon-${name}-${font}.colored`); + + // process the icons in the aliases attr + aliases.forEach(aliasObj => { + cssClasses.push(`.devicon-${name}-${aliasObj["alias"]}.colored`); + }); + return `${cssClasses.join(",")}{color: ${color}}`; }).join(" "); diff --git a/new_icons.png b/new_icons.png deleted file mode 100644 index f2a9aad6..00000000 Binary files a/new_icons.png and /dev/null differ