1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-15 11:04:13 +02:00

Added working workflow file

This commit is contained in:
Thomas Bui
2021-01-10 20:01:50 -08:00
parent d0d101a776
commit 3d2e655f81
6 changed files with 84 additions and 38 deletions

View File

@@ -230,3 +230,11 @@ def get_added_modified_svgs(files_added_json_path: str,
svgs.append(path)
return svgs
def write_to_file(path: str, value: any):
"""
Write the value to a JSON file.
"""
with open(path, "w") as file:
file.write(value)

View File

@@ -2,6 +2,7 @@ from typing import List
import xml.etree.ElementTree as et
from pathlib import Path
import os
import json
import platform
import sys
import traceback
@@ -24,6 +25,8 @@ def check_svgs(svg_file_paths: List[Path]):
The style must not contain any 'fill' declarations.
If any error is found, they will be thrown.
:param: svg_file_paths, the file paths to the svg to check for.
:return: None if there no errors. If there is, return a JSON.stringified
list with the error messages in it.
"""
# batch err messages together so user can fix everything at once
err_msgs = []
@@ -63,7 +66,8 @@ def check_svgs(svg_file_paths: List[Path]):
err_msgs.append("\n".join(err_msg))
if len(err_msgs) > 0:
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
return "\n\n".join(err_msgs)
return 'None'
def set_env_var(key: str, value: str, delimiter: str='~'):

View File

@@ -11,8 +11,8 @@ from build_assets import util
def main():
"""
Check the quality of the svgs.
If any error is found, set an environmental variable called SVG_ERR_MSGS
that will contains the error messages.
If any svg error is found, create a json file called 'svg_err_messages.json'
in the root folder that will contains the error messages.
"""
args = arg_getters.get_check_svgs_on_pr_args()
try:
@@ -21,10 +21,14 @@ def main():
args.files_modified_json_path)
print("SVGs to check: ", *svgs, sep='\n')
util.check_svgs(svgs)
print("All SVGs found were good. Task completed.")
if len(svgs) == 0:
print("No SVGs to check, ending script.")
return
err_messages = util.check_svgs(svgs)
filehandler.write_to_file("./svg_err_messages.txt", err_messages)
print("Task completed.")
except Exception as e:
util.set_env_var("SVG_ERR_MSGS", str(e))
util.exit_with_err(e)