1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-12 09:34:36 +02:00

Various bug fixes and reference update

This commit is contained in:
Thomas Bui
2020-12-29 15:11:28 -08:00
parent eb6884db84
commit 8a5ff05f01
8 changed files with 61 additions and 32 deletions

View File

@@ -1,7 +1,7 @@
from argparse import ArgumentParser
from build_assets.PathResolverAction import PathResolverAction
def get_commandline_args(peek_mode=False):
def get_selenium_runner_args(peek_mode=False):
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
parser.add_argument("--headless",
@@ -33,3 +33,12 @@ def get_commandline_args(peek_mode=False):
help="The title of the PR that we are peeking at")
return parser.parse_args()
def get_generate_markdown_args():
parser = ArgumentParser(description="Generate markdown for the image urls passed in.")
parser.add_argument("img_urls",
help="The urls of the images. Must be the string/JSON form of an array. Ex: '[1,2,3]'")
return parser.parse_args()

View File

@@ -147,7 +147,7 @@ def rename_extracted_files(extract_path: str):
print("Files renamed")
def create_screenshot_folder(dir, screenshot_name: str="screenshots"):
def create_screenshot_folder(dir, screenshot_name: str="screenshots/"):
"""
Create a screenshots folder in the dir.
:param dir, the dir where we want to create the folder.
@@ -158,5 +158,11 @@ def create_screenshot_folder(dir, screenshot_name: str="screenshots"):
folder = Path(dir).resolve()
if not folder.is_dir():
raise Exception(f"This is not a dir: {str(folder)}. \ndir must be a valid directory")
folder.mkdir(screenshot_name, exist_ok=True)
return str(folder)
screenshot_folder = Path(folder, screenshot_name)
try:
os.mkdir(screenshot_folder)
except FileExistsError:
print(f"{screenshot_folder} already exist. Script will do nothing.")
finally:
return str(screenshot_folder)

View File

@@ -1,5 +1,7 @@
from typing import List
from build_assets import arg_getters
def generate_screenshot_markdown(img_urls: List[str]):
"""
@@ -12,5 +14,6 @@ def generate_screenshot_markdown(img_urls: List[str]):
if __name__ == "__main__":
markdown = generate_screenshot_markdown()
args = arg_getters.get_generate_markdown_args()
markdown = generate_screenshot_markdown(args.img_urls)
print("\n\n".join(markdown)) # format it before printing

View File

@@ -4,11 +4,11 @@ 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, util
from build_assets import filehandler, arg_getters
def main():
args = util.get_commandline_args()
args = arg_getters.get_selenium_runner_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 uploaded. Ending script...")

View File

@@ -1,4 +1,3 @@
from os import sep
from typing import List
import re
from selenium.common.exceptions import TimeoutException
@@ -6,15 +5,12 @@ 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, util
from build_assets import filehandler, arg_getters
def main():
args = util.get_commandline_args(True)
args = arg_getters.get_selenium_runner_args(True)
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 uploaded. Ending script...")
return
# get only the icon object that has the name matching the pr title
filtered_icons = find_object_added_in_this_pr(new_icons, args.pr_title)
@@ -23,11 +19,19 @@ def main():
print("List of new icons:", *new_icons, sep = "\n")
print("Icons being uploaded:", *filtered_icons, sep = "\n")
if len(new_icons) == 0:
print("No files need to be uploaded. Ending script...")
return
screenshot_folder = filehandler.create_screenshot_folder("./")
if len(filtered_icons) == 0:
print("No icons found matching the icon name in the PR's title. Fallback to uploading all new icons found.")
screenshot_folder = ""
runner = None
try:
runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless)
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
screenshot_folder = filehandler.create_screenshot_folder("./")
runner.upload_svgs(svgs, screenshot_folder)
print("Task completed.")
except TimeoutException as e:

View File

@@ -25,22 +25,22 @@ jobs:
./devicon.json ./icons ./ --headless
- name: Upload geckodriver.log for debugging purposes
uses: actions/upload-artifact@v2
if: ${{failure()}}
if: failure()
with:
name: geckodriver-log
path: ./geckodriver.log
- name: Build devicon.min.css
if: ${{ success() }}
if: success()
run: npm run build-css
- name: Upload screenshot of the newly made icons
id: imgur_step
uses: devicons/public-upload-to-imgur@v1
if: ${{success()}}
uses: devicons/public-upload-to-imgur@v1.1.2
if: success()
with:
img_path: ./new_icons.png
path: ./new_icons.png
client_id: ${{secrets.IMGUR_CLIENT_ID}}
- name: Create Pull Request
if: ${{ success() }}
if: success()
uses: peter-evans/create-pull-request@v3
env:
MESSAGE: |

View File

@@ -23,35 +23,39 @@ jobs:
- name: Run icomoon_peek.py
env:
PR_TITLE: ${{ github.event.pull_request.title }}
shell: cmd
run: >
python ./.github/scripts/icomoon_peek.py
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json
./devicon.json ./icons ./ --headless --pr_title $PR_TITLE
./devicon.json ./icons ./ --headless --pr_title "%PR_TITLE%"
- name: Upload geckodriver.log for debugging purposes
uses: actions/upload-artifact@v2
if: ${{failure()}}
if: failure()
with:
name: geckodriver-log
path: ./geckodriver.log
- name: Upload screenshot of the newly made icons
id: new_icons_overview_step
uses: devicons/public-upload-to-imgur@v1.1
if: ${{success()}}
uses: devicons/public-upload-to-imgur@main
if: success()
with:
img_path: ./screenshots/new_icons.png
path: ./screenshots/new_icons.png
client_id: ${{secrets.IMGUR_CLIENT_ID}}
- name: Upload zoomed in screenshot of the newly made icons
id: new_icons_detailed_step
uses: devicons/public-upload-to-imgur@v1.1
if: ${{success()}}
uses: devicons/public-upload-to-imgur@main
if: success()
with:
img_path: ./screenshots/screenshot_*.png
path: ./screenshots/screenshot_*.png
client_id: ${{secrets.IMGUR_CLIENT_ID}}
- name: Generate the markdowns for the screenshot
- name: Generate the markdowns for the screenshot and put it in the DETAILED_IMGS_MARKDOWN env var
env:
IMG_URLS: ${{ steps.new_icons_detailed_step.outputs.img_url }}
run: |
echo "DETAILED_IMGS_MARKDOWN<<EOF" >> $GITHUB_ENV
python ./.github/scripts/generate_screenshot_markdown.py >> $GITHUB_ENV
python ./.github/scripts/generate_screenshot_markdown.py "%IMG_URLS%" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: cmd
- name: Comment on the PR about the result
uses: github-actions-up-and-running/pr-comment@v1.0.1
env:

View File

@@ -4,7 +4,10 @@
"description": "Programming related icons collection",
"main": "devicon.min.css",
"scripts": {
"build-css": "gulp updateCss && gulp clean"
"build-css": "gulp updateCss && gulp clean",
"peek-test": "python ./.github/scripts/icomoon_peek.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./ --pr_title \"%PR_TITLE%\"",
"build-test": "python ./.github/scripts/icomoon_build.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./"
},
"repository": {
"type": "git",