Skip to content

Commit

Permalink
ci: allow multi submission
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Nov 5, 2024
1 parent 61a9571 commit af99d81
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
9 changes: 5 additions & 4 deletions .github/scripts/build_assets/arg_getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def get_selenium_runner_args(has_token=True, peek_mode=False):
"""
Get the commandline arguments for the icomoon_peek.py and
Get the commandline arguments for the icomoon_peek.py and
icomoon_build.py.
"""
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
Expand Down Expand Up @@ -49,9 +49,6 @@ def get_check_icon_pr_args():
"""
parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run whenever a PR is opened")

parser.add_argument("pr_title",
help="The title of the PR that we are peeking at")

parser.add_argument("icons_folder_path",
help="The path to the icons folder",
action=PathResolverAction)
Expand All @@ -60,6 +57,10 @@ def get_check_icon_pr_args():
help="The path to the devicon.json",
action=PathResolverAction)

parser.add_argument("changed_files",
help="List of SVG files changed in the PR",
nargs="+")

return parser.parse_args()


Expand Down
31 changes: 13 additions & 18 deletions .github/scripts/build_assets/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,24 @@ def set_env_var(key: str, value: str, delimiter: str='~'):
raise Exception("This function doesn't support this platform: " + platform.system())


def find_object_added_in_pr(icons: List[dict], pr_title: str):
def find_objects_added_in_pr(icons: List[dict], changed_files: List[str]) -> List[dict]:
"""
Find the icon name from the PR title.
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.
:changed_files, SVG files changed in this PR.
:return a list of dictionaries with the "name"
entry values matching the name of changed icons.
"""
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)
filtered_icons = []
for file in changed_files:
icon_name = Path(file).parent.name
icon = [icon for icon in icons if icon["name"] == icon_name]
if len(icon) > 0:
filtered_icons.extend(icon)
return filtered_icons


def is_svg_in_font_attribute(svg_file_path: Path, devicon_object: dict):
def is_svg_in_font_attribute(svg_file_path: Path, devicon_object: dict):
"""
Check if svg is in devicon.json's font attribute.
:param svg_file_path, the path to a single svg icon
Expand Down
63 changes: 32 additions & 31 deletions .github/scripts/check_icon_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,41 @@ def main():
all_icons = filehandler.get_json_file_content(args.devicon_json_path)

devicon_err_msg = []
err_msg = []
#First check if devicon.json is sorted
if sorted(all_icons, key=lambda d: d['name']) != all_icons:
devicon_err_msg.append(f"devicon.json is not sorted correctly.\nPlease make sure that your icon is added in the `devicon.json` file at the correct alphabetic position\nas seen here: https://github.com/devicons/devicon/wiki/Updating-%60devicon.json%60")

# get only the icon object that has the name matching the pr title
filtered_icon = util.find_object_added_in_pr(all_icons, args.pr_title)
print("Checking devicon.json object: " + str(filtered_icon))
devicon_err_msg.append(check_devicon_object(filtered_icon))

# check the file names
filename_err_msg = ""
svgs = None
try:
svgs = filehandler.get_svgs_paths([filtered_icon], args.icons_folder_path, as_str=False)
print("SVGs to check: ", *svgs, sep='\n')
except ValueError as e:
filename_err_msg = "Error found regarding filenames:\n- " + e.args[0]

# check the svgs
if svgs is None or len(svgs) == 0:
print("No SVGs to check, ending script.")
svg_err_msg = "Error checking SVGs: no SVGs to check. Might be caused by above issues."
else:
svg_err_msg = check_svgs(svgs, filtered_icon)

err_msg = []
if devicon_err_msg != []:
err_msg.extend(devicon_err_msg)

if filename_err_msg != "":
err_msg.append(filename_err_msg)

if svg_err_msg != "":
err_msg.append(svg_err_msg)
filtered_icons = util.find_objects_added_in_pr(all_icons, args.changed_files)
for filtered_icon in filtered_icons:
print("Checking devicon.json object: " + str(filtered_icon))
devicon_err_msg.append(check_devicon_object(filtered_icon))

# check the file names
filename_err_msg = ""
svgs = None
try:
svgs = filehandler.get_svgs_paths([filtered_icon], args.icons_folder_path, as_str=False)
print("SVGs to check: ", *svgs, sep='\n')
except ValueError as e:
filename_err_msg = "Error found regarding filenames:\n- " + e.args[0]

# check the svgs
if svgs is None or len(svgs) == 0:
print("No SVGs to check, ending script.")
svg_err_msg = "Error checking SVGs: no SVGs to check. Might be caused by above issues."
else:
svg_err_msg = check_svgs(svgs, filtered_icon)

if devicon_err_msg != []:
err_msg.extend(devicon_err_msg)

if filename_err_msg != "":
err_msg.append(filename_err_msg)

if svg_err_msg != "":
err_msg.append(svg_err_msg)

filehandler.write_to_file("./err_messages.txt", "\n\n".join(err_msg))
print("Task completed.")
Expand Down Expand Up @@ -109,7 +110,7 @@ def check_devicon_object(icon: dict):
err_msgs.append(f"- Invalid version name in versions['svg']: '{version}'. Must match regexp: (original|plain|line)(-wordmark)?")
except KeyError:
err_msgs.append("- missing key: 'svg' in 'versions'.")

try:
if type(icon["versions"]["font"]) != list or len(icon["versions"]["svg"]) == 0:
err_msgs.append("- must contain at least 1 font version in a list.")
Expand Down Expand Up @@ -160,7 +161,7 @@ def check_devicon_object(icon: dict):
if len(err_msgs) > 0:
message = "Error found in \"devicon.json\" for \"{}\" entry: \n{}".format(icon["name"], "\n".join(err_msgs))
return message
return ""
return ""


def check_svgs(svg_file_paths: List[Path], devicon_object: dict):
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/check_icon_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ jobs:
runs-on: ubuntu-latest
if: startsWith(github.event.pull_request.title, 'new icon') || startsWith(github.event.pull_request.title, 'update icon') # only checks icon PR
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: '1'

- name: Check if PR is develop
if: ${{ github.base_ref != 'develop' }}
if: false
# if: ${{ github.base_ref != 'develop' }}
run: |
echo -e "The PR's base branch is \`${{ github.base_ref }}\`, but should be \`develop\`\nPlease change the PR so that it's based on, and merged into \`develop\`" > ./err_messages.txt
echo "wrong_branch=true" >> $GITHUB_ENV
- uses: actions/setup-python@v4
if: ${{ !env.wrong_branch }}
with:
with:
python-version: 3.8

- name: Install dependencies
Expand All @@ -27,9 +30,9 @@ jobs:
- name: Run the check_svg script
if: ${{ !env.wrong_branch }}
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: python ./.github/scripts/check_icon_pr.py "$PR_TITLE" ./icons ./devicon.json
run: |
CHANGED_ICONS=$(git diff --name-only ${{ github.base_ref }} ${{ github.sha }} | grep -E 'icons/.*\.svg')
python ./.github/scripts/check_icon_pr.py ./icons ./devicon.json ${CHANGED_ICONS}
- name: Upload the err messages
uses: actions/upload-artifact@v3
Expand Down

0 comments on commit af99d81

Please sign in to comment.