mirror of
https://github.com/konpa/devicon.git
synced 2025-08-12 01:24:42 +02:00
Added check script for the icons and fix icons with fill or viewBox issues (#460)
* Added script to check svg fill and viewBox * Fix cucumber-plain-wordmark * Fix various fill and viewBox issues in svgs * Added check for height and width attr * Added check_svgs workflow * Fix an issue where the error is not log properly * Added on push for testing * Updated trigger so it now runs whenever PR is update * Added sleep to script to make logs nicer * Added script that create env var * Updated the github_env to accomodate ubuntu * Change format of log and allow filehandler to return Path * Updated logging messages * Updated refs for the checkout action * Make logging nicer * Updated fix messaging so it's more clear * fix icons: icons/cucumber/cucumber-plain-wordmark.svg, icons/intellij/intellij-plain-wordmark.svg, icons/jenkins/jenkins-plain.svg, icons/twitter/twitter-original.svg, icons/yunohost/yunohost-plain.svg
This commit is contained in:
23
.github/scripts/build_assets/arg_getters.py
vendored
23
.github/scripts/build_assets/arg_getters.py
vendored
@@ -3,6 +3,10 @@ from build_assets.PathResolverAction import PathResolverAction
|
||||
|
||||
|
||||
def get_selenium_runner_args(peek_mode=False):
|
||||
"""
|
||||
Get the commandline arguments for the icomoon_peek.py and
|
||||
icomoon_build.py.
|
||||
"""
|
||||
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
|
||||
|
||||
parser.add_argument("--headless",
|
||||
@@ -33,4 +37,23 @@ def get_selenium_runner_args(peek_mode=False):
|
||||
parser.add_argument("--pr_title",
|
||||
help="The title of the PR that we are peeking at")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def get_check_svgs_args():
|
||||
"""
|
||||
Get the commandline arguments for the chec_svgs.py.
|
||||
"""
|
||||
parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct.")
|
||||
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)
|
||||
return parser.parse_args()
|
37
.github/scripts/build_assets/drafts/check_devicon_object.py
vendored
Normal file
37
.github/scripts/build_assets/drafts/check_devicon_object.py
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
from typing import List
|
||||
|
||||
# abandoned since it's not too hard to check devicon objects using our eyes
|
||||
# however, still keep in case we need it in the future
|
||||
|
||||
def check_devicon_objects(icons: List[dict]):
|
||||
"""
|
||||
Check that the devicon objects added is up to standard.
|
||||
"""
|
||||
err_msgs = []
|
||||
for icon in icons:
|
||||
if type(icon["name"]) != str:
|
||||
err_msgs.append("'name' must be a string, not: " + str(icon["name"]))
|
||||
|
||||
try:
|
||||
for tag in icon["tags"]:
|
||||
if type(tag) != str:
|
||||
raise TypeError()
|
||||
except TypeError:
|
||||
err_msgs.append("'tags' must be an array of strings, not: " + str(icon["tags"]))
|
||||
break
|
||||
|
||||
|
||||
if type(icon["versions"]["svg"]) != list or len(icon["versions"]["svg"]) == 0:
|
||||
err_msgs.append("Icon name must be a string")
|
||||
|
||||
if type(icon["versions"]["font"]) != list or len(icon["versions"]["svg"]) == 0:
|
||||
err_msgs.append("Icon name must be a string")
|
||||
|
||||
if type(icon["color"]) != str or "#" not in icon["color"]:
|
||||
err_msgs.append("'color' must be a string in the format '#abcdef'")
|
||||
|
||||
if type(icon["aliases"]) != list:
|
||||
err_msgs.append("'aliases' must be an array of dicts")
|
||||
|
||||
if len(err_msgs) > 0:
|
||||
raise Exception("Error found in devicon.json: \n" + "\n".join(err_msgs))
|
75
.github/scripts/build_assets/filehandler.py
vendored
75
.github/scripts/build_assets/filehandler.py
vendored
@@ -44,12 +44,16 @@ def is_not_in_icomoon_json(icon, icomoon_json) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def get_svgs_paths(new_icons: List[dict], icons_folder_path: str) -> List[str]:
|
||||
def get_svgs_paths(new_icons: List[dict], icons_folder_path: str,
|
||||
icon_versions_only: bool=False, as_str: bool=True) -> List[str] or List[Path]:
|
||||
"""
|
||||
Get all the suitable svgs file path listed in the devicon.json.
|
||||
:param new_icons, a list containing the info on the new icons.
|
||||
:param icons_folder_path, the path where the function can find the
|
||||
listed folders.
|
||||
:param icon_versions_only, whether to only get the svgs that can be
|
||||
made into an icon.
|
||||
:param: as_str, whether to add the path as a string or as a Path.
|
||||
:return: a list of svg file paths that can be uploaded to Icomoon.
|
||||
"""
|
||||
file_paths = []
|
||||
@@ -59,29 +63,58 @@ def get_svgs_paths(new_icons: List[dict], icons_folder_path: str) -> List[str]:
|
||||
if not folder_path.is_dir():
|
||||
raise ValueError(f"Invalid path. This is not a directory: {folder_path}.")
|
||||
|
||||
# TODO: remove the try-except when the devicon.json is upgraded
|
||||
try:
|
||||
aliases = icon_info["aliases"]
|
||||
except KeyError:
|
||||
aliases = [] # create empty list of aliases if not provided in devicon.json
|
||||
|
||||
for font_version in icon_info["versions"]["font"]:
|
||||
# if it's an alias, we don't want to make it into an icon
|
||||
if is_alias(font_version, aliases):
|
||||
print(f"Not exist {icon_info['name']}-{font_version}.svg")
|
||||
continue
|
||||
|
||||
file_name = f"{icon_info['name']}-{font_version}.svg"
|
||||
path = Path(folder_path, file_name)
|
||||
|
||||
if path.exists():
|
||||
file_paths.append(str(path))
|
||||
else:
|
||||
raise ValueError(f"This path doesn't exist: {path}")
|
||||
|
||||
if icon_versions_only:
|
||||
get_icon_svgs_paths(folder_path, icon_info, file_paths, as_str)
|
||||
else:
|
||||
get_all_svgs_paths(folder_path, icon_info, file_paths, as_str)
|
||||
return file_paths
|
||||
|
||||
|
||||
def get_icon_svgs_paths(folder_path: Path, icon_info: dict,
|
||||
file_paths: List[str], as_str: bool):
|
||||
"""
|
||||
Get only the svg file paths that can be made into an icon from the icon_info.
|
||||
:param: folder_path, the folder where we can find the icons.
|
||||
:param: icon_info, an icon object in the devicon.json.
|
||||
:param: file_paths, an array containing all the file paths found.
|
||||
:param: as_str, whether to add the path as a string or as a Path.
|
||||
"""
|
||||
aliases = icon_info["aliases"]
|
||||
|
||||
for font_version in icon_info["versions"]["font"]:
|
||||
# if it's an alias, we don't want to make it into an icon
|
||||
if is_alias(font_version, aliases):
|
||||
print(f"Skipping this font since it's an alias: {icon_info['name']}-{font_version}.svg")
|
||||
continue
|
||||
|
||||
file_name = f"{icon_info['name']}-{font_version}.svg"
|
||||
path = Path(folder_path, file_name)
|
||||
|
||||
if path.exists():
|
||||
file_paths.append(str(path) if as_str else path)
|
||||
else:
|
||||
raise ValueError(f"This path doesn't exist: {path}")
|
||||
|
||||
|
||||
def get_all_svgs_paths(folder_path: Path, icon_info: dict,
|
||||
file_paths: List[str], as_str: bool):
|
||||
"""
|
||||
Get all the svg file paths of an icon.
|
||||
:param: folder_path, the folder where we can find the icons.
|
||||
:param: icon_info, an icon object in the devicon.json.
|
||||
:param: file_paths, an array containing all the file paths found.
|
||||
:param: as_str, whether to add the path as a string or as a Path.
|
||||
"""
|
||||
for font_version in icon_info["versions"]["svg"]:
|
||||
file_name = f"{icon_info['name']}-{font_version}.svg"
|
||||
path = Path(folder_path, file_name)
|
||||
|
||||
if path.exists():
|
||||
file_paths.append(str(path) if as_str else path)
|
||||
else:
|
||||
raise ValueError(f"This path doesn't exist: {path}")
|
||||
|
||||
|
||||
def is_alias(font_version: str, aliases: List[dict]):
|
||||
"""
|
||||
Check whether the font version is an alias of another version.
|
||||
|
33
.github/scripts/build_assets/github_env.py
vendored
Normal file
33
.github/scripts/build_assets/github_env.py
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
import platform
|
||||
|
||||
|
||||
def set_env_var(key: str, value: str, delimiter: str='~'):
|
||||
"""
|
||||
Set the GitHub env variable of 'key' to 'value' using
|
||||
the method specified here:
|
||||
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
||||
Support both Windows and Ubuntu machines provided by GitHub Actions.
|
||||
|
||||
:param: key, the name of the env variable.
|
||||
:param: value, the value of the env variable.
|
||||
:param: delimiter, the delimiter that you want to use
|
||||
to write to the file. Only applicable if the 'value' contains
|
||||
'\n' character aka a multiline string.
|
||||
"""
|
||||
if platform.system() == "Windows":
|
||||
if "\n" in value:
|
||||
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%')
|
||||
os.system(f'echo "{value}" >> %GITHUB_ENV%')
|
||||
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%')
|
||||
else:
|
||||
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%')
|
||||
elif platform.system() == "Linux":
|
||||
if "\n" in value:
|
||||
os.system(f'echo "{key}<<{delimiter}" >> $GITHUB_ENV')
|
||||
os.system(f'echo "{value}" >> $GITHUB_ENV')
|
||||
os.system(f'echo "{delimiter}" >> $GITHUB_ENV')
|
||||
else:
|
||||
os.system(f'echo "{key}={value}" >> $GITHUB_ENV')
|
||||
else:
|
||||
raise Exception("This function doesn't support this platform: " + platform.system())
|
Reference in New Issue
Block a user