mirror of
https://github.com/konpa/devicon.git
synced 2025-08-12 09:34:36 +02:00
Create a monthly script that checks all svgs
This commit is contained in:
17
.github/scripts/build_assets/arg_getters.py
vendored
17
.github/scripts/build_assets/arg_getters.py
vendored
@@ -40,15 +40,22 @@ def get_selenium_runner_args(peek_mode=False):
|
|||||||
return parser.parse_args()
|
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 = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run whenever a PR is opened")
|
||||||
parser.add_argument("icomoon_json_path",
|
parser.add_argument("files_changed_json_path",
|
||||||
help="The path to the icomoon.json aka the selection.json created by Icomoon",
|
help="The path to the files.json created by the gh-action-get-changed-files@2.1.4",
|
||||||
action=PathResolverAction)
|
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",
|
parser.add_argument("devicon_json_path",
|
||||||
help="The path to the devicon.json",
|
help="The path to the devicon.json",
|
||||||
action=PathResolverAction)
|
action=PathResolverAction)
|
||||||
|
43
.github/scripts/build_assets/filehandler.py
vendored
43
.github/scripts/build_assets/filehandler.py
vendored
@@ -6,7 +6,7 @@ import os
|
|||||||
import re
|
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
|
Find the newly added icons by finding the difference between
|
||||||
the devicon.json and the icomoon.json.
|
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.
|
:param icomoon_json_path: a path to the iconmoon.json.
|
||||||
:return: a list of the new icons as JSON objects.
|
:return: a list of the new icons as JSON objects.
|
||||||
"""
|
"""
|
||||||
with open(devicon_json_path) as json_file:
|
devicon_json = get_json_file_content(devicon_json_path)
|
||||||
devicon_json = json.load(json_file)
|
icomoon_json = get_json_file_content(icomoon_json_path)
|
||||||
|
|
||||||
with open(icomoon_json_path) as json_file:
|
|
||||||
icomoon_json = json.load(json_file)
|
|
||||||
|
|
||||||
new_icons = []
|
new_icons = []
|
||||||
for icon in devicon_json:
|
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
|
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.
|
Checks whether the icon's name is not in the icomoon_json.
|
||||||
:param icon: the icon object we are searching for.
|
: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,
|
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.
|
Get all the suitable svgs file path listed in the devicon.json.
|
||||||
:param new_icons, a list containing the info on the new icons.
|
: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.")
|
print(f"{screenshot_folder} already exist. Script will do nothing.")
|
||||||
finally:
|
finally:
|
||||||
return str(screenshot_folder)
|
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
|
||||||
|
@@ -1,42 +1,8 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
import sys
|
|
||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
import time
|
|
||||||
from pathlib import Path
|
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]):
|
def check_svgs(svg_file_paths: List[Path]):
|
||||||
"""
|
"""
|
||||||
Check the width, height, viewBox and style of each svgs passed in.
|
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))
|
err_msgs.append("\n".join(err_msg))
|
||||||
|
|
||||||
if len(err_msgs) > 0:
|
if len(err_msgs) > 0:
|
||||||
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
|
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
18
.github/scripts/check_all_icons.py
vendored
18
.github/scripts/check_all_icons.py
vendored
@@ -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)
|
|
27
.github/scripts/check_svgs_monthly.py
vendored
Normal file
27
.github/scripts/check_svgs_monthly.py
vendored
Normal file
@@ -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()
|
30
.github/scripts/check_svgs_on_pr.py
vendored
Normal file
30
.github/scripts/check_svgs_on_pr.py
vendored
Normal file
@@ -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()
|
35
.github/workflows/check_svgs_monthly.yml
vendored
Normal file
35
.github/workflows/check_svgs_monthly.yml
vendored
Normal file
@@ -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
|
@@ -1,20 +1,32 @@
|
|||||||
name: Check SVGs
|
name: Check SVGs On PR
|
||||||
on: pull_request
|
on:
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**.svg' # runs only when a svg is added in the PR
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check the SVGs' quality
|
name: Check the SVGs' quality
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
steps:
|
steps:
|
||||||
|
<<<<<<< HEAD:.github/workflows/check_svgs.yml
|
||||||
- uses: actions/checkout@v2
|
- 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
|
- name: Setup Python v3.8
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v2
|
||||||
with:
|
with:
|
||||||
python-version: 3.8
|
python-version: 3.8
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: python -m pip install --upgrade pip
|
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
|
- name: Run the check_svg script
|
||||||
|
shell: bash
|
||||||
run: >
|
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
|
- name: Comment on the PR about the result - Success
|
||||||
if: success()
|
if: success()
|
||||||
uses: github-actions-up-and-running/pr-comment@v1.0.1
|
uses: github-actions-up-and-running/pr-comment@v1.0.1
|
||||||
@@ -30,7 +42,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
message: ${{ env.MESSAGE }}
|
message: ${{ env.MESSAGE }}
|
||||||
|
|
||||||
- name: Comment on the PR about the result - Failed
|
- name: Comment on the PR about the result - Failed
|
||||||
if: failure()
|
if: failure()
|
||||||
uses: github-actions-up-and-running/pr-comment@v1.0.1
|
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.
|
PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out.
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
message: ${{ format(env.MESSAGE, env.ERR_MSGS)}}
|
message: ${{ format(env.MESSAGE, env.SVG_ERR_MSGS)}}
|
Reference in New Issue
Block a user