mirror of
https://github.com/konpa/devicon.git
synced 2025-02-24 09:12:36 +01:00
* Refactored peek script into a class * Post-peek workflow now upload the new screenshots * Refactored BuildSeleniumRunner into a class * Updated build_icons.yml to reflect new changes * Fixed issue with building icons that were already in the app * Build script will take screenshot of new icons * Update post peek yaml message * Added alerts * Peek script now check for strokes in icons * Updated post_peek's strokes in svgs message * Updated post_peek script's message * Updated post_peek's message * Refactored get_release_message into icomoon_build * Change devicon.css name to devicon-base.css * Updated post_peek message * Added update icon as a valid PR title for bot-peek * Add \n char to SVG after it gets optimized * Fixed error with 'update icon' regex * Build script now batch issues when upload SVG * Addressed build-bot's screenshot order * Apply suggestions from code review Co-authored-by: David Leal <halfpacho@gmail.com> Co-authored-by: David Leal <halfpacho@gmail.com>
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
import os
|
|
import re
|
|
from typing import List
|
|
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(1)
|
|
|
|
|
|
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())
|
|
|
|
|
|
def find_object_added_in_pr(icons: List[dict], pr_title: str):
|
|
"""
|
|
Find the icon name from the PR title.
|
|
:param icons, a list of the font objects found in the devicon.json.
|
|
:pr_title, the title of the PR that this workflow was called on.
|
|
:return a dictionary with the "name"
|
|
entry's value matching the name in the pr_title.
|
|
:raise If no object can be found, raise an Exception.
|
|
"""
|
|
try:
|
|
pattern = re.compile(r"(?<=^new icon: )\w+ (?=\(.+\))|(?<=^update icon: )\w+ (?=\(.+\))", re.I)
|
|
icon_name_index = 0
|
|
icon_name = pattern.findall(pr_title)[icon_name_index].lower().strip() # should only have one match
|
|
icon = [icon for icon in icons if icon["name"] == icon_name][0]
|
|
return icon
|
|
except IndexError as e: # there are no match in the findall()
|
|
print(e)
|
|
message = "util.find_object_added_in_pr: Couldn't find an icon matching the name in the PR title.\n" \
|
|
f"PR title is: '{pr_title}'"
|
|
raise Exception(message)
|