diff --git a/.github/scripts/build_assets/filehandler.py b/.github/scripts/build_assets/filehandler.py index 788f4a2f..fb918019 100644 --- a/.github/scripts/build_assets/filehandler.py +++ b/.github/scripts/build_assets/filehandler.py @@ -214,6 +214,7 @@ def get_added_modified_svgs(files_changed_json_path: str): :return: a list of the svg file paths that were added/modified in this pr. """ files_dict = get_json_file_content(files_changed_json_path) + print(files_dict) svgs = [] for file in files_dict["added"]: path = Path(file) diff --git a/.github/scripts/build_assets/github_env.py b/.github/scripts/build_assets/github_env.py deleted file mode 100644 index 0afc6fff..00000000 --- a/.github/scripts/build_assets/github_env.py +++ /dev/null @@ -1,33 +0,0 @@ -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()) \ No newline at end of file diff --git a/.github/scripts/build_assets/svg_checker.py b/.github/scripts/build_assets/util.py similarity index 58% rename from .github/scripts/build_assets/svg_checker.py rename to .github/scripts/build_assets/util.py index 75a78f61..49f71ef9 100644 --- a/.github/scripts/build_assets/svg_checker.py +++ b/.github/scripts/build_assets/util.py @@ -1,6 +1,19 @@ from typing import List import xml.etree.ElementTree as et from pathlib import Path +import os +import platform +import sys +import traceback + + +def exit_with_err(err: Exception): + """ + Exit the current step and display the err. + :param: err, the error/exception encountered. + """ + traceback.print_exc() + sys.exit(str(err)) def check_svgs(svg_file_paths: List[Path]): @@ -50,4 +63,35 @@ 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)) \ No newline at end of file + raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs)) + + +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()) \ No newline at end of file diff --git a/.github/scripts/check_svgs_monthly.py b/.github/scripts/check_svgs_monthly.py index 042f282c..10a65754 100644 --- a/.github/scripts/check_svgs_monthly.py +++ b/.github/scripts/check_svgs_monthly.py @@ -1,11 +1,10 @@ -from pathlib import Path -import json +import traceback import sys # pycharm complains that build_assets is an unresolved ref # don't worry about it, the script still runs from build_assets import filehandler, arg_getters -from build_assets import svg_checker +from build_assets import util def main(): @@ -17,10 +16,11 @@ def main(): try: devicon_json = filehandler.get_json_file_content(args.devicon_json_path) svgs = filehandler.get_svgs_paths(devicon_json, args.icons_folder_path) - svg_checker.check_svgs(svgs) + util.check_svgs(svgs) print("All SVGs found were good. Task completed.") except Exception as e: - sys.exit(str(e)) + util.exit_with_err(e) + if __name__ == "__main__": diff --git a/.github/scripts/check_svgs_on_pr.py b/.github/scripts/check_svgs_on_pr.py index add1baa8..67472fd7 100644 --- a/.github/scripts/check_svgs_on_pr.py +++ b/.github/scripts/check_svgs_on_pr.py @@ -5,7 +5,7 @@ import time # pycharm complains that build_assets is an unresolved ref # don't worry about it, the script still runs from build_assets import filehandler, arg_getters -from build_assets import github_env, svg_checker +from build_assets import util def main(): @@ -19,11 +19,11 @@ def main(): # check the svgs svgs = filehandler.get_added_modified_svgs(args.files_changed_json_path) print("SVGs to check: ", *svgs, sep='\n') - svg_checker.check_svgs(svgs) + util.check_svgs(svgs) print("All SVGs found were good. Task completed.") except Exception as e: - github_env.set_env_var("SVG_ERR_MSGS", str(e)) - sys.exit(str(e)) + util.set_env_var("SVG_ERR_MSGS", str(e)) + util.exit_with_err(e) if __name__ == "__main__": diff --git a/.github/scripts/icomoon_build.py b/.github/scripts/icomoon_build.py index 96d49e73..ddca8c81 100644 --- a/.github/scripts/icomoon_build.py +++ b/.github/scripts/icomoon_build.py @@ -6,6 +6,7 @@ from selenium.common.exceptions import TimeoutException # don't worry about it, the script still runs from build_assets.SeleniumRunner import SeleniumRunner from build_assets import filehandler, arg_getters +from build_assets import util def main(): @@ -32,9 +33,9 @@ def main(): filehandler.rename_extracted_files(args.download_path) print("Task completed.") except TimeoutException as e: - sys.exit("Selenium Time Out Error: \n" + str(e)) + util.exit_with_err("Selenium Time Out Error: \n" + str(e)) except Exception as e: - sys.exit(str(e)) + util.exit_with_err(e) finally: runner.close() diff --git a/.github/scripts/icomoon_peek.py b/.github/scripts/icomoon_peek.py index 551b5848..445ef958 100644 --- a/.github/scripts/icomoon_peek.py +++ b/.github/scripts/icomoon_peek.py @@ -8,6 +8,7 @@ import xml.etree.ElementTree as et # don't worry about it, the script still runs from build_assets.SeleniumRunner import SeleniumRunner from build_assets import filehandler, arg_getters +from build_assets import util def main(): @@ -39,9 +40,9 @@ def main(): runner.upload_svgs(svgs, screenshot_folder) print("Task completed.") except TimeoutException as e: - sys.exit("Selenium Time Out Error: \n" + str(e)) + util.exit_with_err("Selenium Time Out Error: \n" + str(e)) except Exception as e: - sys.exit(str(e)) + util.exit_with_err(e) finally: runner.close()