1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-14 02:24:04 +02:00

Add fix for bad zip file and logging for build (#1069)

This commit is contained in:
Thomas Bui
2022-03-20 10:04:09 -07:00
committed by GitHub
parent ac68b12d20
commit 39dfa5416e
9 changed files with 154 additions and 96 deletions

View File

@@ -5,6 +5,7 @@ import re
import subprocess
import json
from typing import List, Dict
from io import FileIO
# pycharm complains that build_assets is an unresolved ref
@@ -18,63 +19,68 @@ def main():
Build the icons using Icomoon. Also optimize the svgs.
"""
runner = None
logfile = open("log.txt", "w")
try:
args = arg_getters.get_selenium_runner_args()
new_icons = get_icons_for_building(args.icomoon_json_path, args.devicon_json_path, args.token)
new_icons = get_icons_for_building(args.icomoon_json_path, args.devicon_json_path, args.token, logfile)
if len(new_icons) == 0:
sys.exit("No files need to be uploaded. Ending script...")
print(f"There are {len(new_icons)} icons to be build. Here are they:", *new_icons, sep = "\n")
print(f"There are {len(new_icons)} icons to be build. Here are they:", *new_icons, sep = "\n", file=logfile)
print("Begin optimizing files...")
optimize_svgs(new_icons, args.icons_folder_path)
print("Begin optimizing files...", file=logfile)
optimize_svgs(new_icons, args.icons_folder_path, logfile=logfile)
print("Updating the icomoon json...")
update_icomoon_json(new_icons, args.icomoon_json_path)
print("Updating the icomoon json...", file=logfile)
update_icomoon_json(new_icons, args.icomoon_json_path, logfile)
print("Start the building icons process...")
print("Start the building icons process...", file=logfile)
icon_svgs = filehandler.get_svgs_paths(
new_icons, args.icons_folder_path, icon_versions_only=True)
zip_name = "devicon-v1.0.zip"
zip_path = Path(args.download_path, zip_name)
screenshot_folder = filehandler.create_screenshot_folder("./")
runner = BuildSeleniumRunner(args.download_path,
args.geckodriver_path, args.headless)
args.geckodriver_path, args.headless, log_output=logfile)
runner.build_icons(args.icomoon_json_path, zip_path,
icon_svgs, screenshot_folder)
filehandler.extract_files(str(zip_path), args.download_path)
filehandler.rename_extracted_files(args.download_path)
filehandler.extract_files(str(zip_path), args.download_path, logfile)
filehandler.rename_extracted_files(args.download_path, logfile)
print("Creating the release message by querying the GitHub API...")
get_release_message(args.token)
print("Creating the release message by querying the GitHub API...", file=logfile)
get_release_message(args.token, logfile)
print("Closing issues with the `in-develop` label.")
print("Closing issues with the `in-develop` label.", file=logfile)
issues = api_handler.get_issues_by_labels(args.token, ["in-develop"])
issue_nums = [issue_num["number"] for issue_num in issues]
api_handler.close_issues(args.token, issue_nums)
print("Task completed.")
print("Task completed.", file=logfile)
except TimeoutException as e:
util.exit_with_err(Exception("Selenium Time Out Error: \n" + str(e)))
util.exit_with_err(Exception("Selenium Time Out Error: \n" + str(e)), logfile)
except Exception as e:
util.exit_with_err(e)
util.exit_with_err(e, logfile)
finally:
print("Exiting", file=logfile)
if runner is not None:
runner.close()
logfile.close()
def get_icons_for_building(icomoon_json_path: str, devicon_json_path: str, token: str):
def get_icons_for_building(icomoon_json_path: str, devicon_json_path: str, token: str, logfile: FileIO):
"""
Get the icons for building.
:param icomoon_json_path - the path to the `icomoon.json`.
:param devicon_json_path - the path to the `devicon.json`.
:param token - the token to access the GitHub API.
:param logfile.
:return a list of dict containing info on the icons. These are
from the `devicon.json`.
"""
devicon_json = filehandler.get_json_file_content(devicon_json_path)
pull_reqs = api_handler.get_merged_pull_reqs_since_last_release(token)
pull_reqs = api_handler.get_merged_pull_reqs_since_last_release(token, logfile)
new_icons = []
for pull_req in pull_reqs:
@@ -95,22 +101,24 @@ def get_icons_for_building(icomoon_json_path: str, devicon_json_path: str, token
return new_icons
def optimize_svgs(new_icons: List[dict], icons_folder_path: str):
def optimize_svgs(new_icons: List[str], icons_folder_path: str, logfile: FileIO):
"""
Optimize the newly added svgs. This is done in batches
since the command line has a limit on characters allowed.
:param new_icons - the new icons that need to be optimized.
:param icons_folder_path - the path to the /icons folder.
:param logfile - the file obj to store logging info in.
"""
svgs = filehandler.get_svgs_paths(new_icons, icons_folder_path, icon_versions_only=False)
start = 0
step = 10
for i in range(start, len(svgs), step):
batch = svgs[i:i + step]
print(f"Optimizing these files\n{batch}", file=logfile)
subprocess.run(["npm", "run", "optimize-svg", "--", f"--svgFiles={json.dumps(batch)}"], shell=True)
def update_icomoon_json(new_icons: List[str], icomoon_json_path: str):
def update_icomoon_json(new_icons: List[str], icomoon_json_path: str, logfile: FileIO):
"""
Update the `icomoon.json` if it contains any icons
that needed to be updated. This will remove the icons
@@ -127,7 +135,7 @@ def update_icomoon_json(new_icons: List[str], icomoon_json_path: str):
icomoon_json["icons"] = list(icons_to_keep)
new_len = len(icomoon_json["icons"])
print(f"Update completed. Removed {cur_len - new_len} icons:", *messages, sep='\n')
print(f"Update completed. Removed {cur_len - new_len} icons:", *messages, sep='\n', file=logfile)
filehandler.write_to_file(icomoon_json_path, json.dumps(icomoon_json))
@@ -149,18 +157,18 @@ def find_icomoon_icon_not_in_new_icons(icomoon_icon: Dict, new_icons: List, mess
return True
def get_release_message(token):
def get_release_message(token, logfile: FileIO):
"""
Get the release message for the latest build and write
the result in a file.
:param token: the GitHub API token to access the API.
"""
# fetch first page by default
data = api_handler.get_merged_pull_reqs_since_last_release(token)
data = api_handler.get_merged_pull_reqs_since_last_release(token, logfile)
newIcons = []
features = []
print("Parsing through the pull requests...")
print("Parsing through the pull requests...", file=logfile)
for pullData in data:
authors = api_handler.find_all_authors(pullData, token)
markdown = f"- [{pullData['title']}]({pullData['html_url']}) by {authors}."
@@ -170,7 +178,7 @@ def get_release_message(token):
else:
features.append(markdown)
print("Constructing message...")
print("Constructing message...", file=logfile)
thankYou = "A huge thanks to all our maintainers and contributors for making this release possible!"
iconTitle = f"**{len(newIcons)} New Icons**"
featureTitle = f"**{len(features)} New Features**"
@@ -178,10 +186,10 @@ def get_release_message(token):
iconTitle, "\n".join(newIcons),
featureTitle, "\n".join(features))
print("--------------Here is the build message--------------\n", finalString)
print("--------------Here is the build message--------------\n", finalString, file=logfile)
release_message_path = "./release_message.txt"
filehandler.write_to_file(release_message_path, finalString)
print("Script finished")
print("Script finished", file=logfile)
if __name__ == "__main__":