From c97a0bb00ab4f2a3132eff2868165784bbd0e305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kalsnes=20Hagen?= <43886029+Snailedlt@users.noreply.github.com> Date: Fri, 14 Apr 2023 19:25:41 +0200 Subject: [PATCH] Only check stroke for icons in devicon.json's font objects (#1491) Co-authored-by: David Leal --- .github/scripts/build_assets/util.py | 15 ++++++++++++++- .github/scripts/check_icon_pr.py | 13 +++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/scripts/build_assets/util.py b/.github/scripts/build_assets/util.py index a4c0c755..e98b2a90 100644 --- a/.github/scripts/build_assets/util.py +++ b/.github/scripts/build_assets/util.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import re from typing import List import platform @@ -71,11 +72,23 @@ def find_object_added_in_pr(icons: List[dict], pr_title: str): raise Exception(message) +def is_svg_in_font_attribute(svg_file_path: Path, devicon_object: dict): + """ + Check if svg is in devicon.json's font attribute. + :param svg_file_path, the path to a single svg icon + :devicon_object, an object for a single icon inside devicon.json + :return true if the svg exists in the devicon_object's font attribute, false if it doesn't + """ + icon_version = Path(svg_file_path).stem.split('-', 1)[1] + font_object = devicon_object["versions"]["font"] + return icon_version in font_object + + valid_svg_filename_pattern = re.compile(r"-(original|plain|line)(-wordmark)?\.svg$") def is_svg_name_valid(filename: str): return valid_svg_filename_pattern.search(filename) is not None + valid_svg_version_pattern = re.compile(r"^(original|plain|line)(-wordmark)?$") def is_svg_version_valid(version): return valid_svg_version_pattern.search(version) is not None - diff --git a/.github/scripts/check_icon_pr.py b/.github/scripts/check_icon_pr.py index 662c8c99..dc5eec77 100644 --- a/.github/scripts/check_icon_pr.py +++ b/.github/scripts/check_icon_pr.py @@ -42,7 +42,7 @@ def main(): print("No SVGs to check, ending script.") svg_err_msg = "Error checking SVGs: no SVGs to check. Might be caused by above issues." else: - svg_err_msg = check_svgs(svgs) + svg_err_msg = check_svgs(svgs, filtered_icon) err_msg = [] if devicon_err_msg != []: @@ -163,7 +163,7 @@ def check_devicon_object(icon: dict): return "" -def check_svgs(svg_file_paths: List[Path]): +def check_svgs(svg_file_paths: List[Path], devicon_object: dict): """ Check the width, height, viewBox and style of each svgs passed in. The viewBox must be '0 0 128 128'. @@ -195,10 +195,11 @@ def check_svgs(svg_file_paths: List[Path]): err_msg.append("- 'viewBox' is not '0 0 128 128' -> Set it or scale the file using https://www.iloveimg.com/resize-image/resize-svg.") # goes through all elems and check for strokes - for child in tree.iter(): - if child.get("stroke") != None: - err_msg.append("- SVG contains `stroke` property. This will get ignored by Icomoon. Please convert them to fills.") - break + if util.is_svg_in_font_attribute(svg_path, devicon_object): + for child in tree.iter(): + if child.get("stroke") != None: + err_msg.append("- SVG contains `stroke` property. This will get ignored by Icomoon. Please convert them to fills.") + break if len(err_msg) > 1: err_msgs.append("\n".join(err_msg))