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/drafts/check_svgs_monthly.py b/.github/drafts/check_svgs_monthly.py new file mode 100644 index 000000000..440e2fcb5 --- /dev/null +++ b/.github/drafts/check_svgs_monthly.py @@ -0,0 +1,26 @@ +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 util + + +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) + util.check_svgs(svgs) + print("All SVGs found were good. Task completed.") + except Exception as e: + util.exit_with_err(e) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/.github/drafts/check_svgs_monthly.yml b/.github/drafts/check_svgs_monthly.yml new file mode 100644 index 000000000..5e0655aaf --- /dev/null +++ b/.github/drafts/check_svgs_monthly.yml @@ -0,0 +1,42 @@ +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 + + - 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 + + - 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 ./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 diff --git a/.github/scripts/build_assets/arg_getters.py b/.github/scripts/build_assets/arg_getters.py index 4e1d59c06..51c5d557f 100644 --- a/.github/scripts/build_assets/arg_getters.py +++ b/.github/scripts/build_assets/arg_getters.py @@ -40,15 +40,26 @@ 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_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() + +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..cd4848cb8 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,35 @@ 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_added_json_path: str, + files_modified_json_path: str): + """ + Get the svgs added and modified from the files_changed_json_path. + :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_added = get_json_file_content(files_added_json_path) + files_modified = get_json_file_content(files_modified_json_path) + + svgs = [] + for file in files_added: + path = Path(file) + if path.suffix.lower() == ".svg": + svgs.append(path) + + for file in files_modified: + path = Path(file) + if path.suffix.lower() == ".svg": + 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/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/check_svgs.py b/.github/scripts/build_assets/util.py similarity index 56% rename from .github/scripts/check_svgs.py rename to .github/scripts/build_assets/util.py index 460ee3535..f8e990b0b 100644 --- a/.github/scripts/check_svgs.py +++ b/.github/scripts/build_assets/util.py @@ -1,40 +1,20 @@ from typing import List -import sys import xml.etree.ElementTree as et -import time from pathlib import Path +import os +import json +import platform +import sys +import traceback -# 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(): +def exit_with_err(err: Exception): """ - Check the quality of the svgs. - If any error is found, set an environmental variable called ERR_MSGS - that will contains the error messages. + Exit the current step and display the err. + :param: err, the error/exception encountered. """ - 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)) + traceback.print_exc() + sys.exit(1) def check_svgs(svg_file_paths: List[Path]): @@ -45,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 = [] @@ -84,8 +66,36 @@ 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' -if __name__ == "__main__": - main() +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_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_on_pr.py b/.github/scripts/check_svgs_on_pr.py new file mode 100644 index 000000000..a49a2bbad --- /dev/null +++ b/.github/scripts/check_svgs_on_pr.py @@ -0,0 +1,36 @@ +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 util + + +def main(): + """ + Check the quality of the svgs. + 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: + # check the svgs + svgs = filehandler.get_added_modified_svgs(args.files_added_json_path, + args.files_modified_json_path) + print("SVGs to check: ", *svgs, sep='\n') + + 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.exit_with_err(e) + + +if __name__ == "__main__": + 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() 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.yml b/.github/workflows/check_svgs.yml deleted file mode 100644 index b3fe29256..000000000 --- a/.github/workflows/check_svgs.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Check SVGs -on: pull_request -jobs: - check: - name: Check the SVGs' quality - runs-on: ubuntu-18.04 - 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 - - name: Run the check_svg script - run: > - python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons - - name: Comment on the PR about the result - Success - if: success() - uses: github-actions-up-and-running/pr-comment@v1.0.1 - 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: - 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 - 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: - repo-token: ${{ secrets.GITHUB_TOKEN }} - message: ${{ format(env.MESSAGE, env.ERR_MSGS)}} diff --git a/.github/workflows/check_svgs_on_pr.yml b/.github/workflows/check_svgs_on_pr.yml new file mode 100644 index 000000000..70dd42446 --- /dev/null +++ b/.github/workflows/check_svgs_on_pr.yml @@ -0,0 +1,45 @@ +name: Check SVGs On PR +on: pull_request +jobs: + check: + name: Check the SVGs' quality + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@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_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: 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/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..a94f7593e --- /dev/null +++ b/.github/workflows/post_check_svgs_comment.yml @@ -0,0 +1,100 @@ +name: Post the result of a SVG Check into its PR. +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: Check if the trigger run worked. If it failed, fail the current run. + 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 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: peek_icons.yml + run_id: ${{ github.event.workflow_run.id }} + + - 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: Read the err message file + if: success() + 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.err_message_reader.outputs.content == 'None' + 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: ${{ 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.err_message_reader.outputs.content != 'None' + env: + MESSAGE: | + Hi! + + 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 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. + + 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: ${{ steps.pr_num_reader.outputs.content }} + token: ${{ secrets.GITHUB_TOKEN }} + 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 + 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: ${{ steps.pr_num_reader.outputs.content }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ env.MESSAGE }} diff --git a/.github/workflows/post_peek_screenshot.yml b/.github/workflows/post_peek_screenshot.yml new file mode 100644 index 000000000..44bda66ab --- /dev/null +++ b/.github/workflows/post_peek_screenshot.yml @@ -0,0 +1,99 @@ +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: 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 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + workflow: peek_icons.yml + run_id: ${{ github.event.workflow_run.id }} + + - 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 + 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.1 + 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 + if: success() + env: + 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, + + 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: ${{ steps.pr_num_reader.outputs.content }} + 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() || cancelled() + 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: ${{ steps.pr_num_reader.outputs.content }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ env.MESSAGE }}