From b7ae338d2f42ec0e6ed9fb9ed3c986fbf6c64266 Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Fri, 8 Jan 2021 12:07:47 -0800 Subject: [PATCH 1/8] Create a monthly script that checks all svgs --- .github/scripts/build_assets/arg_getters.py | 17 +++++--- .github/scripts/build_assets/filehandler.py | 43 +++++++++++++++---- .../svg_checker.py} | 40 +---------------- .github/scripts/check_all_icons.py | 18 -------- .github/scripts/check_svgs_monthly.py | 27 ++++++++++++ .github/scripts/check_svgs_on_pr.py | 30 +++++++++++++ .github/workflows/check_svgs_monthly.yml | 35 +++++++++++++++ .../{check_svgs.yml => check_svgs_on_pr.yml} | 21 ++++++--- 8 files changed, 156 insertions(+), 75 deletions(-) rename .github/scripts/{check_svgs.py => build_assets/svg_checker.py} (67%) delete mode 100644 .github/scripts/check_all_icons.py create mode 100644 .github/scripts/check_svgs_monthly.py create mode 100644 .github/scripts/check_svgs_on_pr.py create mode 100644 .github/workflows/check_svgs_monthly.yml rename .github/workflows/{check_svgs.yml => check_svgs_on_pr.yml} (73%) diff --git a/.github/scripts/build_assets/arg_getters.py b/.github/scripts/build_assets/arg_getters.py index 4e1d59c06..afff14f0d 100644 --- a/.github/scripts/build_assets/arg_getters.py +++ b/.github/scripts/build_assets/arg_getters.py @@ -40,15 +40,22 @@ def get_selenium_runner_args(peek_mode=False): return parser.parse_args() -def get_check_svgs_args(): +def get_check_svgs_on_pr_args(): """ - Get the commandline arguments for the chec_svgs.py. + Get the commandline arguments for the check_svgs_on_pr.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", + parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run whenever a PR is opened") + parser.add_argument("files_changed_json_path", + help="The path to the files.json created by the gh-action-get-changed-files@2.1.4", action=PathResolverAction) + return parser.parse_args() + +def get_check_svgs_monthly_args(): + """ + Get the commandline arguments for the check_svgs_monthly.py. + """ + parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run monthly.") parser.add_argument("devicon_json_path", help="The path to the devicon.json", action=PathResolverAction) diff --git a/.github/scripts/build_assets/filehandler.py b/.github/scripts/build_assets/filehandler.py index 496a5e0b5..788f4a2f4 100644 --- a/.github/scripts/build_assets/filehandler.py +++ b/.github/scripts/build_assets/filehandler.py @@ -6,7 +6,7 @@ import re -def find_new_icons(devicon_json_path: str, icomoon_json_path: str) -> List[dict]: +def find_new_icons(devicon_json_path: str, icomoon_json_path: str): """ Find the newly added icons by finding the difference between the devicon.json and the icomoon.json. @@ -14,11 +14,8 @@ def find_new_icons(devicon_json_path: str, icomoon_json_path: str) -> List[dict] :param icomoon_json_path: a path to the iconmoon.json. :return: a list of the new icons as JSON objects. """ - with open(devicon_json_path) as json_file: - devicon_json = json.load(json_file) - - with open(icomoon_json_path) as json_file: - icomoon_json = json.load(json_file) + devicon_json = get_json_file_content(devicon_json_path) + icomoon_json = get_json_file_content(icomoon_json_path) new_icons = [] for icon in devicon_json: @@ -28,7 +25,17 @@ def find_new_icons(devicon_json_path: str, icomoon_json_path: str) -> List[dict] return new_icons -def is_not_in_icomoon_json(icon, icomoon_json) -> bool: +def get_json_file_content(json_path: str): + """ + Get the json content of the json_path. + :param: json_path, the path to the json file. + :return: a dict representing the file content. + """ + with open(json_path) as json_file: + return json.load(json_file) + + +def is_not_in_icomoon_json(icon, icomoon_json): """ Checks whether the icon's name is not in the icomoon_json. :param icon: the icon object we are searching for. @@ -45,7 +52,7 @@ def is_not_in_icomoon_json(icon, icomoon_json) -> bool: 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]: + icon_versions_only: bool=False, as_str: bool=True): """ Get all the suitable svgs file path listed in the devicon.json. :param new_icons, a list containing the info on the new icons. @@ -199,3 +206,23 @@ def create_screenshot_folder(dir, screenshot_name: str="screenshots/"): print(f"{screenshot_folder} already exist. Script will do nothing.") finally: return str(screenshot_folder) + +def get_added_modified_svgs(files_changed_json_path: str): + """ + Get the svgs added and modified from the files_changed_json_path. + :param: the path to the files.json created by the gh-action-get-changed-files@2.1.4 + :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) + svgs = [] + for file in files_dict["added"]: + path = Path(file) + if path.suffix.lower() == ".svg": + svgs.append(file) + + for file in files_dict["modified"]: + path = Path(file) + if path.suffix.lower() == ".svg": + svgs.append(file) + + return svgs diff --git a/.github/scripts/check_svgs.py b/.github/scripts/build_assets/svg_checker.py similarity index 67% rename from .github/scripts/check_svgs.py rename to .github/scripts/build_assets/svg_checker.py index 460ee3535..75a78f61f 100644 --- a/.github/scripts/check_svgs.py +++ b/.github/scripts/build_assets/svg_checker.py @@ -1,42 +1,8 @@ from typing import List -import sys import xml.etree.ElementTree as et -import time from pathlib import Path -# 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 - - -def main(): - """ - Check the quality of the svgs. - If any error is found, set an environmental variable called ERR_MSGS - that will contains the error messages. - """ - args = arg_getters.get_check_svgs_args() - new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path) - - if len(new_icons) == 0: - sys.exit("No files need to be uploaded. Ending script...") - - # print list of new icons - print("SVGs being checked:", *new_icons, sep = "\n", end='\n\n') - - time.sleep(1) # do this so the logs stay clean - try: - # check the svgs - svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, as_str=False) - check_svgs(svgs) - print("All SVGs found were good.\nTask completed.") - except Exception as e: - github_env.set_env_var("ERR_MSGS", str(e)) - sys.exit(str(e)) - - def check_svgs(svg_file_paths: List[Path]): """ Check the width, height, viewBox and style of each svgs passed in. @@ -84,8 +50,4 @@ 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)) - - -if __name__ == "__main__": - main() + raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs)) \ No newline at end of file diff --git a/.github/scripts/check_all_icons.py b/.github/scripts/check_all_icons.py deleted file mode 100644 index 914e7c49e..000000000 --- a/.github/scripts/check_all_icons.py +++ /dev/null @@ -1,18 +0,0 @@ -from pathlib import Path -import json - - -# pycharm complains that build_assets is an unresolved ref -# don't worry about it, the script still runs -from build_assets import filehandler - - -if __name__ == "__main__": - """ - Use as a cmd line script to check all the icons of the devicon.json. - """ - devicon_json_path = str(Path("./devicon.json").resolve()) - icons_folder_path = str(Path("./icons").resolve()) - with open(devicon_json_path) as json_file: - devicon_json = json.load(json_file) - svgs = filehandler.get_svgs_paths(devicon_json, icons_folder_path) \ No newline at end of file diff --git a/.github/scripts/check_svgs_monthly.py b/.github/scripts/check_svgs_monthly.py new file mode 100644 index 000000000..042f282c4 --- /dev/null +++ b/.github/scripts/check_svgs_monthly.py @@ -0,0 +1,27 @@ +from pathlib import Path +import json +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 + + +def main(): + """ + Check the quality of the svgs of the whole icons folder. + """ + args = arg_getters.get_check_svgs_monthly_args() + + 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) + print("All SVGs found were good. Task completed.") + except Exception as e: + sys.exit(str(e)) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/.github/scripts/check_svgs_on_pr.py b/.github/scripts/check_svgs_on_pr.py new file mode 100644 index 000000000..add1baa84 --- /dev/null +++ b/.github/scripts/check_svgs_on_pr.py @@ -0,0 +1,30 @@ +import sys +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 + + +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. + """ + args = arg_getters.get_check_svgs_on_pr_args() + try: + # 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) + 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)) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/check_svgs_monthly.yml b/.github/workflows/check_svgs_monthly.yml new file mode 100644 index 000000000..49f284af0 --- /dev/null +++ b/.github/workflows/check_svgs_monthly.yml @@ -0,0 +1,35 @@ +name: Check SVGs Monthly +on: workflow_dispatch + # schedule: + # - cron: '0 0 1 * *' +jobs: + check_develop: + name: Check the SVGs' quality in the `develop` branch + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + with: + ref: develop + - name: Setup Python v3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: python -m pip install --upgrade pip + - name: Run the check_svg script + run: > + python ./.github/scripts/check_svgs_monthly.py ./devicon.json ./icons + check_master: + name: Check the SVGs' quality in the `master` branch + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 # check out default branch, which is master + - name: Setup Python v3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: python -m pip install --upgrade pip + - name: Run the check_svg script + run: > + python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons \ No newline at end of file diff --git a/.github/workflows/check_svgs.yml b/.github/workflows/check_svgs_on_pr.yml similarity index 73% rename from .github/workflows/check_svgs.yml rename to .github/workflows/check_svgs_on_pr.yml index b3fe29256..5058eeea4 100644 --- a/.github/workflows/check_svgs.yml +++ b/.github/workflows/check_svgs_on_pr.yml @@ -1,20 +1,32 @@ -name: Check SVGs -on: pull_request +name: Check SVGs On PR +on: + pull_request: + paths: + - '**.svg' # runs only when a svg is added in the PR jobs: check: name: Check the SVGs' quality runs-on: ubuntu-18.04 steps: +<<<<<<< HEAD:.github/workflows/check_svgs.yml - uses: actions/checkout@v2 +======= + - uses: actions/checkout@v2 # check out the merge branch of the PR and base +>>>>>>> 132dff5... Create a monthly script that checks all svgs:.github/workflows/check_svgs_on_pr.yml - name: Setup Python v3.8 uses: actions/setup-python@v2 with: python-version: 3.8 - name: Install dependencies run: python -m pip install --upgrade pip + - name: Find files added in this PR + uses: lots0logs/gh-action-get-changed-files@2.1.4 + with: + token: ${{ secrets.GITHUB_TOKEN }} - name: Run the check_svg script + shell: bash run: > - python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons + python ./.github/scripts/check_svgs_on_pr.py $HOME/files.json - name: Comment on the PR about the result - Success if: success() uses: github-actions-up-and-running/pr-comment@v1.0.1 @@ -30,7 +42,6 @@ jobs: with: repo-token: ${{ secrets.GITHUB_TOKEN }} message: ${{ env.MESSAGE }} - - name: Comment on the PR about the result - Failed if: failure() uses: github-actions-up-and-running/pr-comment@v1.0.1 @@ -55,4 +66,4 @@ jobs: PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out. with: repo-token: ${{ secrets.GITHUB_TOKEN }} - message: ${{ format(env.MESSAGE, env.ERR_MSGS)}} + message: ${{ format(env.MESSAGE, env.SVG_ERR_MSGS)}} From b1922925b70ca4d89e00fa77211f400db26d10b7 Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Fri, 8 Jan 2021 15:36:05 -0800 Subject: [PATCH 2/8] Python now print traceback --- .github/scripts/build_assets/filehandler.py | 1 + .github/scripts/build_assets/github_env.py | 33 ------------- .../build_assets/{svg_checker.py => util.py} | 46 ++++++++++++++++++- .github/scripts/check_svgs_monthly.py | 10 ++-- .github/scripts/check_svgs_on_pr.py | 8 ++-- .github/scripts/icomoon_build.py | 5 +- .github/scripts/icomoon_peek.py | 5 +- 7 files changed, 61 insertions(+), 47 deletions(-) delete mode 100644 .github/scripts/build_assets/github_env.py rename .github/scripts/build_assets/{svg_checker.py => util.py} (58%) diff --git a/.github/scripts/build_assets/filehandler.py b/.github/scripts/build_assets/filehandler.py index 788f4a2f4..fb9180195 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 0afc6fff7..000000000 --- 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 75a78f61f..49f71ef99 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 042f282c4..10a65754d 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 add1baa84..67472fd76 100644 --- a/.github/scripts/check_svgs_on_pr.py +++ b/.github/scripts/check_svgs_on_pr.py @@ -5,7 +5,7 @@ # 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 96d49e737..ddca8c81f 100644 --- a/.github/scripts/icomoon_build.py +++ b/.github/scripts/icomoon_build.py @@ -6,6 +6,7 @@ # 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 551b58482..445ef9588 100644 --- a/.github/scripts/icomoon_peek.py +++ b/.github/scripts/icomoon_peek.py @@ -8,6 +8,7 @@ # 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() From c9b19346b2aefcfea11d12eb72e09725b0c65270 Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Fri, 8 Jan 2021 15:53:42 -0800 Subject: [PATCH 3/8] Updated file names in check_svgs_on_pr --- .github/scripts/build_assets/arg_getters.py | 8 ++++++-- .github/scripts/build_assets/filehandler.py | 21 ++++++++++++--------- .github/scripts/build_assets/util.py | 2 +- .github/scripts/check_svgs_monthly.py | 1 - .github/scripts/check_svgs_on_pr.py | 4 +++- .github/workflows/check_svgs_on_pr.yml | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/scripts/build_assets/arg_getters.py b/.github/scripts/build_assets/arg_getters.py index afff14f0d..51c5d557f 100644 --- a/.github/scripts/build_assets/arg_getters.py +++ b/.github/scripts/build_assets/arg_getters.py @@ -45,8 +45,12 @@ def get_check_svgs_on_pr_args(): Get the commandline arguments for the check_svgs_on_pr.py. """ parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run whenever a PR is opened") - parser.add_argument("files_changed_json_path", - help="The path to the files.json created by the gh-action-get-changed-files@2.1.4", + parser.add_argument("files_added_json_path", + help="The path to the files_added.json created by the gh-action-get-changed-files@2.1.4", + action=PathResolverAction) + + parser.add_argument("files_modified_json_path", + help="The path to the files_modified.json created by the gh-action-get-changed-files@2.1.4", action=PathResolverAction) return parser.parse_args() diff --git a/.github/scripts/build_assets/filehandler.py b/.github/scripts/build_assets/filehandler.py index fb9180195..3cfe2c753 100644 --- a/.github/scripts/build_assets/filehandler.py +++ b/.github/scripts/build_assets/filehandler.py @@ -207,23 +207,26 @@ def create_screenshot_folder(dir, screenshot_name: str="screenshots/"): finally: return str(screenshot_folder) -def get_added_modified_svgs(files_changed_json_path: str): +def get_added_modified_svgs(files_added_json_path: str, + files_modified_json_path: str): """ Get the svgs added and modified from the files_changed_json_path. - :param: the path to the files.json created by the gh-action-get-changed-files@2.1.4 - :return: a list of the svg file paths that were added/modified in this pr. + :param: files_added_json_path, the path to the files_added.json created by the gh-action-get-changed-files@2.1.4 + :param: files_modified_json_path, the path to the files_modified.json created by the gh-action-get-changed-files@2.1.4 + :return: a list of the svg file paths that were added/modified in this pr as Path. """ - files_dict = get_json_file_content(files_changed_json_path) - print(files_dict) + files_added = get_json_file_content(files_added_json_path) + files_modified = get_json_file_content(files_modified_json_path) + svgs = [] - for file in files_dict["added"]: + for file in files_added: path = Path(file) if path.suffix.lower() == ".svg": - svgs.append(file) + svgs.append(path) - for file in files_dict["modified"]: + for file in files_modified: path = Path(file) if path.suffix.lower() == ".svg": - svgs.append(file) + svgs.append(path) return svgs diff --git a/.github/scripts/build_assets/util.py b/.github/scripts/build_assets/util.py index 49f71ef99..68ea98bd1 100644 --- a/.github/scripts/build_assets/util.py +++ b/.github/scripts/build_assets/util.py @@ -13,7 +13,7 @@ def exit_with_err(err: Exception): :param: err, the error/exception encountered. """ traceback.print_exc() - sys.exit(str(err)) + sys.exit(1) def check_svgs(svg_file_paths: List[Path]): diff --git a/.github/scripts/check_svgs_monthly.py b/.github/scripts/check_svgs_monthly.py index 10a65754d..440e2fcb5 100644 --- a/.github/scripts/check_svgs_monthly.py +++ b/.github/scripts/check_svgs_monthly.py @@ -22,6 +22,5 @@ def main(): util.exit_with_err(e) - if __name__ == "__main__": main() \ No newline at end of file diff --git a/.github/scripts/check_svgs_on_pr.py b/.github/scripts/check_svgs_on_pr.py index 67472fd76..3516219ec 100644 --- a/.github/scripts/check_svgs_on_pr.py +++ b/.github/scripts/check_svgs_on_pr.py @@ -17,8 +17,10 @@ def main(): args = arg_getters.get_check_svgs_on_pr_args() try: # check the svgs - svgs = filehandler.get_added_modified_svgs(args.files_changed_json_path) + svgs = filehandler.get_added_modified_svgs(args.files_added_json_path, + args.files_modified_json_path) print("SVGs to check: ", *svgs, sep='\n') + util.check_svgs(svgs) print("All SVGs found were good. Task completed.") except Exception as e: diff --git a/.github/workflows/check_svgs_on_pr.yml b/.github/workflows/check_svgs_on_pr.yml index 5058eeea4..a1a93c611 100644 --- a/.github/workflows/check_svgs_on_pr.yml +++ b/.github/workflows/check_svgs_on_pr.yml @@ -26,7 +26,7 @@ jobs: - name: Run the check_svg script shell: bash run: > - python ./.github/scripts/check_svgs_on_pr.py $HOME/files.json + python ./.github/scripts/check_svgs_on_pr.py $HOME/files_added.json $HOME/files_modified.json - name: Comment on the PR about the result - Success if: success() uses: github-actions-up-and-running/pr-comment@v1.0.1 From 2e49bfa1e16ad659bb73c3d1cea96622d40977ed Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Sat, 9 Jan 2021 13:25:56 -0800 Subject: [PATCH 4/8] Change comment action to a new action --- .github/workflows/check_svgs_on_pr.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check_svgs_on_pr.yml b/.github/workflows/check_svgs_on_pr.yml index a1a93c611..9433ca916 100644 --- a/.github/workflows/check_svgs_on_pr.yml +++ b/.github/workflows/check_svgs_on_pr.yml @@ -8,11 +8,7 @@ jobs: name: Check the SVGs' quality runs-on: ubuntu-18.04 steps: -<<<<<<< HEAD:.github/workflows/check_svgs.yml - - uses: actions/checkout@v2 -======= - uses: actions/checkout@v2 # check out the merge branch of the PR and base ->>>>>>> 132dff5... Create a monthly script that checks all svgs:.github/workflows/check_svgs_on_pr.yml - name: Setup Python v3.8 uses: actions/setup-python@v2 with: @@ -29,7 +25,7 @@ jobs: python ./.github/scripts/check_svgs_on_pr.py $HOME/files_added.json $HOME/files_modified.json - name: Comment on the PR about the result - Success if: success() - uses: github-actions-up-and-running/pr-comment@v1.0.1 + uses: NejcZdovc/comment-pr@v1.1.1 env: MESSAGE: | Hi! @@ -40,11 +36,11 @@ jobs: Have a nice day, SVG-Checker Bot :grin: with: - repo-token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} message: ${{ env.MESSAGE }} - name: Comment on the PR about the result - Failed if: failure() - uses: github-actions-up-and-running/pr-comment@v1.0.1 + uses: NejcZdovc/comment-pr@v1.1.1 env: MESSAGE: | Hi! @@ -65,5 +61,5 @@ jobs: PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out. with: - repo-token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} message: ${{ format(env.MESSAGE, env.SVG_ERR_MSGS)}} From 5bcd269f00b947bf787066da6516ff51fc271dcc Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Sun, 10 Jan 2021 16:38:53 -0800 Subject: [PATCH 5/8] Redo the workflow archs so we can comment on pr --- .github/workflows/build_icons.yml | 10 +- .github/workflows/check_svgs_monthly.yml | 17 +++- .github/workflows/check_svgs_on_pr.yml | 64 ++++-------- .github/workflows/peek_icons.yml | 43 ++++---- .github/workflows/post_check_svgs_comment.yml | 78 +++++++++++++++ .github/workflows/post_peek_screenshot.yml | 97 +++++++++++++++++++ 6 files changed, 233 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/post_check_svgs_comment.yml create mode 100644 .github/workflows/post_peek_screenshot.yml diff --git a/.github/workflows/build_icons.yml b/.github/workflows/build_icons.yml index 7133afd44..6584e2766 100644 --- a/.github/workflows/build_icons.yml +++ b/.github/workflows/build_icons.yml @@ -6,29 +6,34 @@ jobs: runs-on: windows-2019 steps: - uses: actions/checkout@v2 - - name: Setup Python v3.8 - uses: actions/setup-python@v2 + + - uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Install dependencies (python, pip, npm) run: | python -m pip install --upgrade pip pip install -r ./.github/scripts/requirements.txt npm install + - name: Executing build and create fonts via icomoon run: > python ./.github/scripts/icomoon_build.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./ --headless + - name: Upload geckodriver.log for debugging purposes uses: actions/upload-artifact@v2 if: failure() with: name: geckodriver-log path: ./geckodriver.log + - name: Build devicon.min.css if: success() run: npm run build-css + - name: Upload screenshot of the newly made icons id: imgur_step uses: devicons/public-upload-to-imgur@v2.1.1 @@ -36,6 +41,7 @@ jobs: with: path: ./new_icons.png client_id: ${{secrets.IMGUR_CLIENT_ID}} + - name: Create Pull Request if: success() uses: peter-evans/create-pull-request@v3 diff --git a/.github/workflows/check_svgs_monthly.yml b/.github/workflows/check_svgs_monthly.yml index 49f284af0..1ef671cf8 100644 --- a/.github/workflows/check_svgs_monthly.yml +++ b/.github/workflows/check_svgs_monthly.yml @@ -7,29 +7,36 @@ jobs: name: Check the SVGs' quality in the `develop` branch runs-on: ubuntu-18.04 steps: + - uses: actions/checkout@v2 with: ref: develop - - name: Setup Python v3.8 - uses: actions/setup-python@v2 + + - uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Install dependencies run: python -m pip install --upgrade pip + - name: Run the check_svg script run: > python ./.github/scripts/check_svgs_monthly.py ./devicon.json ./icons + check_master: name: Check the SVGs' quality in the `master` branch runs-on: ubuntu-18.04 steps: + - uses: actions/checkout@v2 # check out default branch, which is master - - name: Setup Python v3.8 - uses: actions/setup-python@v2 + + - uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Install dependencies run: python -m pip install --upgrade pip + - name: Run the check_svg script run: > - python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons \ No newline at end of file + python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons diff --git a/.github/workflows/check_svgs_on_pr.yml b/.github/workflows/check_svgs_on_pr.yml index 9433ca916..5dff028ce 100644 --- a/.github/workflows/check_svgs_on_pr.yml +++ b/.github/workflows/check_svgs_on_pr.yml @@ -1,65 +1,39 @@ name: Check SVGs On PR -on: - pull_request: - paths: - - '**.svg' # runs only when a svg is added in the PR +on: pull_request jobs: check: name: Check the SVGs' quality runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 # check out the merge branch of the PR and base + - uses: actions/checkout@v2 - name: Setup Python v3.8 uses: actions/setup-python@v2 with: python-version: 3.8 - name: Install dependencies run: python -m pip install --upgrade pip - - name: Find files added in this PR - uses: lots0logs/gh-action-get-changed-files@2.1.4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: Run the check_svg script - shell: bash run: > - python ./.github/scripts/check_svgs_on_pr.py $HOME/files_added.json $HOME/files_modified.json - - name: Comment on the PR about the result - Success - if: success() - uses: NejcZdovc/comment-pr@v1.1.1 - env: - MESSAGE: | - Hi! - I'm Devicons' SVG-Checker Bot and I just checked all the SVGs in this branch. + python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons - Everything looks great. Good job! + - name: Save the error messages in an artifact + shell: bash + run: echo $SVG_ERR_MSGS > err_messages.txt # the $SVG_ERR_MSGS is set by the python script above - Have a nice day, - SVG-Checker Bot :grin: + - name: Upload the err messages + uses: actions/upload-artifact@v2 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - message: ${{ env.MESSAGE }} - - name: Comment on the PR about the result - Failed - if: failure() - uses: NejcZdovc/comment-pr@v1.1.1 - env: - MESSAGE: | - Hi! + name: err_messages + path: ./err_messages.txt - I'm Devicons' SVG-Checker Bot and it seems we've ran into a problem. I'm supposed to check your svgs but I couldn't do my task due to an issue. - - Here is what went wrong: - ``` - {0} - ``` - - For more reference, check out our [CONTRIBUTING guide](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards) - - Please address these issues. When you update this PR, I will check your SVGs again. + - name: Save the pr num in an artifact + shell: bash + env: + PR_NUM: ${{ github.event.number }} + run: echo $PR_NUM > pr_num.txt - Thanks for your help, - SVG-Checker Bot :smile: - - PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out. + - name: Upload the pr num + uses: actions/upload-artifact@v2 with: - github_token: ${{ secrets.GITHUB_TOKEN }} - message: ${{ format(env.MESSAGE, env.SVG_ERR_MSGS)}} + name: pr_num + path: ./pr_num.txt diff --git a/.github/workflows/peek_icons.yml b/.github/workflows/peek_icons.yml index fbb996a82..ac5062bdb 100644 --- a/.github/workflows/peek_icons.yml +++ b/.github/workflows/peek_icons.yml @@ -5,18 +5,21 @@ on: jobs: build: name: Peek Icons - if: contains(github.event.pull_request.labels.*.name, 'bot:peek') + if: github.event.label.name == 'bot:peek' runs-on: windows-2019 steps: - uses: actions/checkout@v2 + - name: Setup Python v3.8 uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r ./.github/scripts/requirements.txt + - name: Run icomoon_peek.py env: PR_TITLE: ${{ github.event.pull_request.title }} @@ -25,37 +28,29 @@ jobs: 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%" + - name: Upload screenshots for comments uses: actions/upload-artifact@v2 if: success() with: name: screenshots path: ./screenshots/*.png + + - name: Save the pr num in an artifact + shell: bash + env: + PR_NUM: ${{ github.event.number }} + run: echo $PR_NUM > pr_num.txt + + - name: Upload the pr num + uses: actions/upload-artifact@v2 + with: + name: pr_num + path: ./pr_num.txt + - name: Upload geckodriver.log for debugging purposes uses: actions/upload-artifact@v2 if: failure() with: name: geckodriver-log - path: ./geckodriver.log - - name: Comment on the PR about the result - if: failure() - uses: github-actions-up-and-running/pr-comment@v1.0.1 - env: - MESSAGE: | - ~Hi - - I'm Devicons' Peek Bot and it seems we've ran into a problem (sorry!). - - Please double check and fix the possible issues below: - - - Your svgs are named and added correctly to the /icons folder as seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#orgGuidelines). - - Your icon information has been added to the `devicon.json` as seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#updateDevicon) - - Your PR title follows the format seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#overview) - - Once everything is fixed, I will try. If I still fail (sorry!), the maintainers will investigate further. - - Best of luck, - Peek Bot :relaxed: - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - message: ${{env.MESSAGE}} + path: ./geckodriver.log \ No newline at end of file diff --git a/.github/workflows/post_check_svgs_comment.yml b/.github/workflows/post_check_svgs_comment.yml new file mode 100644 index 000000000..9dd80e984 --- /dev/null +++ b/.github/workflows/post_check_svgs_comment.yml @@ -0,0 +1,78 @@ +name: Post the screenshots into a comment from Peek Icons workflow +on: + workflow_run: + workflows: ["Check SVGs On PR"] + types: + - completed +jobs: + post_screenshots_in_comment: + name: Post the screenshot + runs-on: ubuntu-18.04 + steps: + - name: Fail the workflow if trigger failed so we can still comment on PR + if: ${{ github.event.workflow_run.conclusion != 'success' }} + run: echo "::error ::Check SVGs On PR workflow failed. Failing script" + + - name: Download workflow artifact + uses: dawidd6/action-download-artifact@v2.11.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: peek_icons.yml + run_id: ${{ github.event.workflow_run.id }} + + - name: Get the PR number and save it in $PR_NUM + run: | + echo 'PR_NUM<> $GITHUB_ENV + cat ./pr_num/pr_num.txt >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Get the error messages and save it in $SVG_ERR_MSGS + run: | + echo 'SVG_ERR_MSGS<> $GITHUB_ENV + cat ./err_messages/err_messages.txt >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Comment on the PR about the result - Success + uses: jungwinter/comment@v1 # let us comment on a specific PR + id: create + env: + MESSAGE: | + Hi! + I'm Devicons' SVG-Checker Bot and I just checked all the SVGs in this branch. + + Everything looks great. Good job! + + Have a nice day, + SVG-Checker Bot :grin: + with: + type: create + issue_number: ${{ env.PR_NUM }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ env.MESSAGE }} + + - name: Comment on the PR about the result - Failure + uses: jungwinter/comment@v1 # let us comment on a specific PR + env: + MESSAGE: | + Hi! + + I'm Devicons' SVG-Checker Bot and it seems we've ran into a problem. I'm supposed to check your svgs but I couldn't do my task due to an issue. + + Here is what went wrong: + ``` + {0} + ``` + + For more reference, check out our [CONTRIBUTING guide](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards) + + Please address these issues. When you update this PR, I will check your SVGs again. + + Thanks for your help, + SVG-Checker Bot :smile: + + PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out. + with: + type: create + issue_number: ${{ env.PR_NUM }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ format(env.MESSAGE, env.SVG_ERR_MSGS)}} diff --git a/.github/workflows/post_peek_screenshot.yml b/.github/workflows/post_peek_screenshot.yml new file mode 100644 index 000000000..b6d85b7eb --- /dev/null +++ b/.github/workflows/post_peek_screenshot.yml @@ -0,0 +1,97 @@ +name: Post the screenshots into a comment from Peek Icons workflow +on: + workflow_run: + workflows: ["Peek Icons"] + types: + - completed +jobs: + post_screenshots_in_comment: + name: Post the screenshot + runs-on: ubuntu-18.04 + steps: + - name: Fail the workflow if trigger failed so we can still comment on PR + if: ${{ github.event.workflow_run.conclusion != 'success' }} + run: echo "::error ::Peek Icons workflow failed. Failing script" + + - name: Download workflow artifact + uses: dawidd6/action-download-artifact@v2.11.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: peek_icons.yml + run_id: ${{ github.event.workflow_run.id }} + + - name: Get the PR number and save it in $PR_NUM + run: | + echo 'PR_NUM<> $GITHUB_ENV + cat ./pr_num/pr_num.txt >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Upload screenshot of the newly made icons gotten from the artifacts + id: icons_overview_img_step + uses: devicons/public-upload-to-imgur@v2.2.0 + with: + path: ./screenshots/new_icons.png + client_id: ${{secrets.IMGUR_CLIENT_ID}} + + - name: Upload zoomed in screenshot of the newly made icons gotten from the artifacts + id: icons_detailed_img_step + uses: devicons/public-upload-to-imgur@v2.2.0 + if: success() + with: + path: ./screenshots/screenshot_*.png + client_id: ${{secrets.IMGUR_CLIENT_ID}} + + - name: Comment on the PR about the result - Success + uses: jungwinter/comment@v1 # let us comment on a specific PR + env: + OVERVIEW_IMG_URL: ${{ fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0] }} + DETAILED_IMGS_URL: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '\n') }} + MESSAGE: | + Hi there, + + I'm Devicons' Peek Bot and I just peeked at the icons that you wanted to add using [icomoon.io](https://icomoon.io/app/#/select). + Here is the result below: + + ![Peeked Icons (top left)]({0}) + + Here are the zoomed-in screenshots of the added icons: + {1} + + Note: If the images don't show up, it's probably because it has been autodeleted by Imgur after 6 months due to our API choice. + + **The maintainers will now take a look at it and decide whether to merge your PR.** + + Thank you for contributing to Devicon! I hope everything works out and your icons are accepted into the repo. + + Cheers, + Peek Bot :blush: + with: + type: create + issue_number: ${{ env.PR_NUM }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{format(env.MESSAGE, env.OVERVIEW_IMG_MARKDOWN, env.DETAILED_IMGS_MARKDOWN)}} + + - name: Comment on the PR about the result - Failure + if: failure() + uses: jungwinter/comment@v1 # let us comment on a specific PR + env: + MESSAGE: | + Hi there, + + I'm Devicons' Peek Bot and it seems we've ran into a problem (sorry!). + + Please double check and fix the possible issues below: + + - Your svgs are named and added correctly to the /icons folder as seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#orgGuidelines). + - Your icon information has been added to the `devicon.json` as seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#updateDevicon) + - Your PR title follows the format seen [here](https://github.com/devicons/devicon/blob/master/CONTRIBUTING.md#overview) + + Once everything is fixed, I will try. If I still fail (sorry!), the maintainers will investigate further. + + Best of luck, + Peek Bot :relaxed: + with: + type: create + issue_number: ${{ env.PR_NUM }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ env.MESSAGE }} From d0d101a77614e4a1441f4ecbfd4c6a5f3adec12a Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Sun, 10 Jan 2021 17:23:09 -0800 Subject: [PATCH 6/8] Moved check_svgs_monthly to draft --- .../{scripts/build_assets => }/drafts/check_devicon_object.py | 0 .github/{scripts => drafts}/check_svgs_monthly.py | 0 .github/{workflows => drafts}/check_svgs_monthly.yml | 2 +- .github/{scripts/build_assets => }/drafts/peek_icons imgur.yml | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename .github/{scripts/build_assets => }/drafts/check_devicon_object.py (100%) rename .github/{scripts => drafts}/check_svgs_monthly.py (100%) rename .github/{workflows => drafts}/check_svgs_monthly.yml (91%) rename .github/{scripts/build_assets => }/drafts/peek_icons imgur.yml (100%) diff --git a/.github/scripts/build_assets/drafts/check_devicon_object.py b/.github/drafts/check_devicon_object.py similarity index 100% rename from .github/scripts/build_assets/drafts/check_devicon_object.py rename to .github/drafts/check_devicon_object.py diff --git a/.github/scripts/check_svgs_monthly.py b/.github/drafts/check_svgs_monthly.py similarity index 100% rename from .github/scripts/check_svgs_monthly.py rename to .github/drafts/check_svgs_monthly.py diff --git a/.github/workflows/check_svgs_monthly.yml b/.github/drafts/check_svgs_monthly.yml similarity index 91% rename from .github/workflows/check_svgs_monthly.yml rename to .github/drafts/check_svgs_monthly.yml index 1ef671cf8..5e0655aaf 100644 --- a/.github/workflows/check_svgs_monthly.yml +++ b/.github/drafts/check_svgs_monthly.yml @@ -39,4 +39,4 @@ jobs: - name: Run the check_svg script run: > - python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons + python ./.github/scripts/check_svgs_monthly.py ./icomoon.json ./devicon.json ./icons diff --git a/.github/scripts/build_assets/drafts/peek_icons imgur.yml b/.github/drafts/peek_icons imgur.yml similarity index 100% rename from .github/scripts/build_assets/drafts/peek_icons imgur.yml rename to .github/drafts/peek_icons imgur.yml From 3d2e655f817492223552564bbc08609e57531f65 Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Sun, 10 Jan 2021 20:01:50 -0800 Subject: [PATCH 7/8] Added working workflow file --- .github/scripts/build_assets/filehandler.py | 8 +++ .github/scripts/build_assets/util.py | 6 ++- .github/scripts/check_svgs_on_pr.py | 14 +++-- .github/workflows/check_svgs_on_pr.yml | 24 +++++---- .github/workflows/post_check_svgs_comment.yml | 51 ++++++++++++++----- .github/workflows/post_peek_screenshot.yml | 19 +++---- 6 files changed, 84 insertions(+), 38 deletions(-) diff --git a/.github/scripts/build_assets/filehandler.py b/.github/scripts/build_assets/filehandler.py index 3cfe2c753..cd4848cb8 100644 --- a/.github/scripts/build_assets/filehandler.py +++ b/.github/scripts/build_assets/filehandler.py @@ -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) diff --git a/.github/scripts/build_assets/util.py b/.github/scripts/build_assets/util.py index 68ea98bd1..f8e990b0b 100644 --- a/.github/scripts/build_assets/util.py +++ b/.github/scripts/build_assets/util.py @@ -2,6 +2,7 @@ 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='~'): diff --git a/.github/scripts/check_svgs_on_pr.py b/.github/scripts/check_svgs_on_pr.py index 3516219ec..a49a2bbad 100644 --- a/.github/scripts/check_svgs_on_pr.py +++ b/.github/scripts/check_svgs_on_pr.py @@ -11,8 +11,8 @@ 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) diff --git a/.github/workflows/check_svgs_on_pr.yml b/.github/workflows/check_svgs_on_pr.yml index 5dff028ce..70dd42446 100644 --- a/.github/workflows/check_svgs_on_pr.yml +++ b/.github/workflows/check_svgs_on_pr.yml @@ -6,34 +6,40 @@ jobs: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 - - name: Setup Python v3.8 - uses: actions/setup-python@v2 + + - uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Install dependencies run: python -m pip install --upgrade pip + + - name: Get Changed Files and generate files_added.json & files_modified.json + uses: lots0logs/gh-action-get-changed-files@2.1.4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Run the check_svg script run: > - python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons - - - name: Save the error messages in an artifact - shell: bash - run: echo $SVG_ERR_MSGS > err_messages.txt # the $SVG_ERR_MSGS is set by the python script above + python ./.github/scripts/check_svgs_on_pr.py $HOME/files_added.json $HOME/files_modified.json - name: Upload the err messages uses: actions/upload-artifact@v2 + if: success() with: - name: err_messages - path: ./err_messages.txt + name: svg_err_messages + path: ./svg_err_messages.txt - name: Save the pr num in an artifact shell: bash + if: success() env: PR_NUM: ${{ github.event.number }} run: echo $PR_NUM > pr_num.txt - name: Upload the pr num uses: actions/upload-artifact@v2 + if: success() with: name: pr_num path: ./pr_num.txt diff --git a/.github/workflows/post_check_svgs_comment.yml b/.github/workflows/post_check_svgs_comment.yml index 9dd80e984..b7d712205 100644 --- a/.github/workflows/post_check_svgs_comment.yml +++ b/.github/workflows/post_check_svgs_comment.yml @@ -1,7 +1,7 @@ -name: Post the screenshots into a comment from Peek Icons workflow +name: Post the result of a SVG Check into its PR. on: workflow_run: - workflows: ["Check SVGs On PR"] + workflows: ['Check SVGs On PR'] types: - completed jobs: @@ -9,9 +9,10 @@ jobs: name: Post the screenshot runs-on: ubuntu-18.04 steps: - - name: Fail the workflow if trigger failed so we can still comment on PR - if: ${{ github.event.workflow_run.conclusion != 'success' }} - run: echo "::error ::Check SVGs On PR workflow failed. Failing script" + - name: Check if the trigger run worked. If it failed, fail the current run. + # this is done cause this script should only post the err message if trigger run failed + if: success() && github.event.workflow_run.conclusion != 'success' + uses: cutenode/action-always-fail@v1.0.1 - name: Download workflow artifact uses: dawidd6/action-download-artifact@v2.11.0 @@ -21,20 +22,22 @@ jobs: run_id: ${{ github.event.workflow_run.id }} - name: Get the PR number and save it in $PR_NUM + if: success() run: | echo 'PR_NUM<> $GITHUB_ENV cat ./pr_num/pr_num.txt >> $GITHUB_ENV echo 'EOF' >> $GITHUB_ENV - - name: Get the error messages and save it in $SVG_ERR_MSGS - run: | - echo 'SVG_ERR_MSGS<> $GITHUB_ENV - cat ./err_messages/err_messages.txt >> $GITHUB_ENV - echo 'EOF' >> $GITHUB_ENV + - name: Read the message file + if: success() + id: message_reader + uses: juliangruber/read-file-action@v1.0.0 + with: + path: ./svg_err_messages/svg_err_messages.txt - name: Comment on the PR about the result - Success uses: jungwinter/comment@v1 # let us comment on a specific PR - id: create + if: success() && steps.message_reader.outputs.content == 'None' env: MESSAGE: | Hi! @@ -50,20 +53,21 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} body: ${{ env.MESSAGE }} - - name: Comment on the PR about the result - Failure + - name: Comment on the PR about the result - SVG Error uses: jungwinter/comment@v1 # let us comment on a specific PR + if: success() && steps.message_reader.outputs.content != 'None' env: MESSAGE: | Hi! - I'm Devicons' SVG-Checker Bot and it seems we've ran into a problem. I'm supposed to check your svgs but I couldn't do my task due to an issue. + I'm Devicons' SVG-Checker Bot and it seems we have some issues with your SVGs. Here is what went wrong: ``` {0} ``` - For more reference, check out our [CONTRIBUTING guide](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards) + For more reference on why these are errors, check out our [CONTRIBUTING guide](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards) Please address these issues. When you update this PR, I will check your SVGs again. @@ -71,6 +75,25 @@ jobs: SVG-Checker Bot :smile: PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out. + with: + type: create + issue_number: ${{ env.PR_NUM }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ format(env.MESSAGE, steps.message_reader.outputs.content) }} + + - name: Comment on the PR about the result - Failure + uses: jungwinter/comment@v1 # let us comment on a specific PR + if: failure() || cancelled() + env: + MESSAGE: | + Hi! + + I'm Devicons' SVG-Checker Bot and it seems we've ran into a problem. I'm supposed to check your svgs but I couldn't do my task due to an issue. + + Please let my maintainers know of the issues. They will take a look at my work and try to resolve the problem. Until then, please hang tight and sorry for the inconvenience. + + Cheers, + SVG-Checker Bot :smile: with: type: create issue_number: ${{ env.PR_NUM }} diff --git a/.github/workflows/post_peek_screenshot.yml b/.github/workflows/post_peek_screenshot.yml index b6d85b7eb..d39bce471 100644 --- a/.github/workflows/post_peek_screenshot.yml +++ b/.github/workflows/post_peek_screenshot.yml @@ -1,7 +1,7 @@ name: Post the screenshots into a comment from Peek Icons workflow on: workflow_run: - workflows: ["Peek Icons"] + workflows: ['Peek Icons'] types: - completed jobs: @@ -9,9 +9,9 @@ jobs: name: Post the screenshot runs-on: ubuntu-18.04 steps: - - name: Fail the workflow if trigger failed so we can still comment on PR - if: ${{ github.event.workflow_run.conclusion != 'success' }} - run: echo "::error ::Peek Icons workflow failed. Failing script" + - name: Check if the trigger run worked. If not, fail the current run. + if: github.event.workflow_run.conclusion != 'success' + uses: cutenode/action-always-fail@v1.0.1 - name: Download workflow artifact uses: dawidd6/action-download-artifact@v2.11.0 @@ -28,14 +28,14 @@ jobs: - name: Upload screenshot of the newly made icons gotten from the artifacts id: icons_overview_img_step - uses: devicons/public-upload-to-imgur@v2.2.0 + uses: devicons/public-upload-to-imgur@v2.2.1 with: path: ./screenshots/new_icons.png client_id: ${{secrets.IMGUR_CLIENT_ID}} - name: Upload zoomed in screenshot of the newly made icons gotten from the artifacts id: icons_detailed_img_step - uses: devicons/public-upload-to-imgur@v2.2.0 + uses: devicons/public-upload-to-imgur@v2.2.1 if: success() with: path: ./screenshots/screenshot_*.png @@ -43,9 +43,10 @@ jobs: - name: Comment on the PR about the result - Success uses: jungwinter/comment@v1 # let us comment on a specific PR + if: success() env: - OVERVIEW_IMG_URL: ${{ fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0] }} - DETAILED_IMGS_URL: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '\n') }} + OVERVIEW_IMG_MARKDOWN: ${{ fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0] }} + DETAILED_IMGS_MARKDOWN: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '\n') }} MESSAGE: | Hi there, @@ -72,7 +73,7 @@ jobs: body: ${{format(env.MESSAGE, env.OVERVIEW_IMG_MARKDOWN, env.DETAILED_IMGS_MARKDOWN)}} - name: Comment on the PR about the result - Failure - if: failure() + if: failure() || cancelled() uses: jungwinter/comment@v1 # let us comment on a specific PR env: MESSAGE: | From 4ea84460cc5737fd4f3880555dbc854a394d647d Mon Sep 17 00:00:00 2001 From: Thomas Bui Date: Sun, 10 Jan 2021 20:10:37 -0800 Subject: [PATCH 8/8] Changed to file read action --- .github/workflows/post_check_svgs_comment.yml | 29 +++++++++---------- .github/workflows/post_peek_screenshot.yml | 15 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/post_check_svgs_comment.yml b/.github/workflows/post_check_svgs_comment.yml index b7d712205..a94f7593e 100644 --- a/.github/workflows/post_check_svgs_comment.yml +++ b/.github/workflows/post_check_svgs_comment.yml @@ -10,7 +10,6 @@ jobs: runs-on: ubuntu-18.04 steps: - name: Check if the trigger run worked. If it failed, fail the current run. - # this is done cause this script should only post the err message if trigger run failed if: success() && github.event.workflow_run.conclusion != 'success' uses: cutenode/action-always-fail@v1.0.1 @@ -21,23 +20,23 @@ jobs: workflow: peek_icons.yml run_id: ${{ github.event.workflow_run.id }} - - name: Get the PR number and save it in $PR_NUM + - name: Read the pr_num file if: success() - run: | - echo 'PR_NUM<> $GITHUB_ENV - cat ./pr_num/pr_num.txt >> $GITHUB_ENV - echo 'EOF' >> $GITHUB_ENV + id: pr_num_reader + uses: juliangruber/read-file-action@v1.0.0 + with: + path: ./pr_num/pr_num.txt - - name: Read the message file + - name: Read the err message file if: success() - id: message_reader + id: err_message_reader uses: juliangruber/read-file-action@v1.0.0 with: path: ./svg_err_messages/svg_err_messages.txt - name: Comment on the PR about the result - Success uses: jungwinter/comment@v1 # let us comment on a specific PR - if: success() && steps.message_reader.outputs.content == 'None' + if: success() && steps.err_message_reader.outputs.content == 'None' env: MESSAGE: | Hi! @@ -49,13 +48,13 @@ jobs: SVG-Checker Bot :grin: with: type: create - issue_number: ${{ env.PR_NUM }} + issue_number: ${{ steps.pr_num_reader.outputs.content }} token: ${{ secrets.GITHUB_TOKEN }} body: ${{ env.MESSAGE }} - name: Comment on the PR about the result - SVG Error uses: jungwinter/comment@v1 # let us comment on a specific PR - if: success() && steps.message_reader.outputs.content != 'None' + if: success() && steps.err_message_reader.outputs.content != 'None' env: MESSAGE: | Hi! @@ -77,9 +76,9 @@ jobs: PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out. with: type: create - issue_number: ${{ env.PR_NUM }} + issue_number: ${{ steps.pr_num_reader.outputs.content }} token: ${{ secrets.GITHUB_TOKEN }} - body: ${{ format(env.MESSAGE, steps.message_reader.outputs.content) }} + body: ${{ format(env.MESSAGE, steps.err_message_reader.outputs.content) }} - name: Comment on the PR about the result - Failure uses: jungwinter/comment@v1 # let us comment on a specific PR @@ -96,6 +95,6 @@ jobs: SVG-Checker Bot :smile: with: type: create - issue_number: ${{ env.PR_NUM }} + issue_number: ${{ steps.pr_num_reader.outputs.content }} token: ${{ secrets.GITHUB_TOKEN }} - body: ${{ format(env.MESSAGE, env.SVG_ERR_MSGS)}} + body: ${{ env.MESSAGE }} diff --git a/.github/workflows/post_peek_screenshot.yml b/.github/workflows/post_peek_screenshot.yml index d39bce471..44bda66ab 100644 --- a/.github/workflows/post_peek_screenshot.yml +++ b/.github/workflows/post_peek_screenshot.yml @@ -20,11 +20,12 @@ jobs: workflow: peek_icons.yml run_id: ${{ github.event.workflow_run.id }} - - name: Get the PR number and save it in $PR_NUM - run: | - echo 'PR_NUM<> $GITHUB_ENV - cat ./pr_num/pr_num.txt >> $GITHUB_ENV - echo 'EOF' >> $GITHUB_ENV + - name: Read the pr_num file + if: success() + id: pr_num_reader + uses: juliangruber/read-file-action@v1.0.0 + with: + path: ./pr_num/pr_num.txt - name: Upload screenshot of the newly made icons gotten from the artifacts id: icons_overview_img_step @@ -68,7 +69,7 @@ jobs: Peek Bot :blush: with: type: create - issue_number: ${{ env.PR_NUM }} + issue_number: ${{ steps.pr_num_reader.outputs.content }} token: ${{ secrets.GITHUB_TOKEN }} body: ${{format(env.MESSAGE, env.OVERVIEW_IMG_MARKDOWN, env.DETAILED_IMGS_MARKDOWN)}} @@ -93,6 +94,6 @@ jobs: Peek Bot :relaxed: with: type: create - issue_number: ${{ env.PR_NUM }} + issue_number: ${{ steps.pr_num_reader.outputs.content }} token: ${{ secrets.GITHUB_TOKEN }} body: ${{ env.MESSAGE }}