add release script
This commit is contained in:
parent
ddb49108f2
commit
fe4eadab1c
3 changed files with 120 additions and 62 deletions
6
build.py
6
build.py
|
@ -22,7 +22,7 @@ from source.py.utils import (
|
|||
)
|
||||
from source.py.feature import freeze_feature, get_freeze_config_str
|
||||
|
||||
version = "7.000 beta31"
|
||||
FONT_VERSION = "7.000 beta31"
|
||||
# =========================================================================================
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ def parse_args():
|
|||
"-v",
|
||||
"--version",
|
||||
action="version",
|
||||
version=f"Maple Mono Builder v{version}",
|
||||
version=f"Maple Mono Builder v{FONT_VERSION}",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
|
@ -545,7 +545,7 @@ def get_unique_identifier(
|
|||
if "CN" in postscript_name and narrow:
|
||||
freeze_config_str += "Narrow;"
|
||||
|
||||
return f"Version {version};SUBF;{postscript_name};2024;FL830;{freeze_config_str}"
|
||||
return f"Version {FONT_VERSION};SUBF;{postscript_name};2024;FL830;{freeze_config_str}"
|
||||
|
||||
|
||||
def change_char_width(font: TTFont, match_width: int, target_width: int):
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from source.py.utils import run
|
||||
|
||||
# Mapping of style names to weights
|
||||
weight_map = {
|
||||
"Thin": "100",
|
||||
"ExtraLight": "200",
|
||||
"Light": "300",
|
||||
"Regular": "400",
|
||||
"Italic": "400",
|
||||
"SemiBold": "500",
|
||||
"Medium": "600",
|
||||
"Bold": "700",
|
||||
"ExtraBold": "800",
|
||||
}
|
||||
|
||||
|
||||
def format_filename(filename: str):
|
||||
match = re.match(r"MapleMono-(.*)\.(.*)$", filename)
|
||||
|
||||
if not match:
|
||||
return None
|
||||
|
||||
style = match.group(1)
|
||||
|
||||
weight = weight_map[style.removesuffix("Italic") if style != "Italic" else "Italic"]
|
||||
suf = "normal" if "italic" in filename.lower() else "italic"
|
||||
|
||||
new_filename = f"maple-mono-latin-{weight}-{suf}.{match.group(2)}"
|
||||
return new_filename
|
||||
|
||||
|
||||
def rename_files(dir: str):
|
||||
for filename in os.listdir(dir):
|
||||
if not filename.endswith(".woff") and not filename.endswith(".woff2"):
|
||||
continue
|
||||
new_name = format_filename(filename)
|
||||
if new_name:
|
||||
os.rename(os.path.join(dir, filename), os.path.join(dir, new_name))
|
||||
print(f"Renamed: {filename} -> {new_name}")
|
||||
|
||||
|
||||
def main():
|
||||
target_dir = "fontsource"
|
||||
if os.path.exists(target_dir):
|
||||
shutil.rmtree(target_dir)
|
||||
run("python build.py --ttf-only")
|
||||
run(f"ftcli converter ft2wf -f woff2 ./fonts/TTF -out {target_dir}")
|
||||
run(f"ftcli converter ft2wf -f woff ./fonts/TTF -out {target_dir}")
|
||||
run("ftcli converter ft2wf -f woff2 ./fonts/Variable -out woff2/var")
|
||||
|
||||
rename_files(target_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
117
release.py
Normal file
117
release.py
Normal file
|
@ -0,0 +1,117 @@
|
|||
import argparse
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from source.py.utils import run
|
||||
|
||||
# Mapping of style names to weights
|
||||
weight_map = {
|
||||
"Thin": "100",
|
||||
"ExtraLight": "200",
|
||||
"Light": "300",
|
||||
"Regular": "400",
|
||||
"Italic": "400",
|
||||
"SemiBold": "500",
|
||||
"Medium": "600",
|
||||
"Bold": "700",
|
||||
"ExtraBold": "800",
|
||||
}
|
||||
|
||||
|
||||
def format_filename(filename: str):
|
||||
match = re.match(r"MapleMono-(.*)\.(.*)$", filename)
|
||||
|
||||
if not match:
|
||||
return None
|
||||
|
||||
style = match.group(1)
|
||||
|
||||
weight = weight_map[style.removesuffix("Italic") if style != "Italic" else "Italic"]
|
||||
suf = "normal" if "italic" in filename.lower() else "italic"
|
||||
|
||||
new_filename = f"maple-mono-latin-{weight}-{suf}.{match.group(2)}"
|
||||
return new_filename
|
||||
|
||||
|
||||
def rename_files(dir: str):
|
||||
for filename in os.listdir(dir):
|
||||
if not filename.endswith(".woff") and not filename.endswith(".woff2"):
|
||||
continue
|
||||
new_name = format_filename(filename)
|
||||
if new_name:
|
||||
os.rename(os.path.join(dir, filename), os.path.join(dir, new_name))
|
||||
print(f"Renamed: {filename} -> {new_name}")
|
||||
|
||||
|
||||
def parse_tag(args):
|
||||
"""
|
||||
Parse the tag from the command line arguments.
|
||||
Format: v7.000[-beta31]
|
||||
"""
|
||||
tag = args.tag
|
||||
if not tag.startswith("v"):
|
||||
tag = f"v{tag}"
|
||||
if not re.match(r"^v\d+\.\d{3}$", tag):
|
||||
raise ValueError(f"Tag must end with 3 numbers following a '.', input is {tag}")
|
||||
if args.beta:
|
||||
tag += "-" if args.beta.startswith("beta") else "-beta" + args.beta
|
||||
return tag
|
||||
|
||||
def update_build_script_version(tag):
|
||||
with open("build.py", "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
f.close()
|
||||
content = re.sub(r'FONT_VERSION = ".*"', f'FONT_VERSION = "{tag}"', content)
|
||||
with open("build.py", "w", encoding="utf-8") as f:
|
||||
f.write(content)
|
||||
f.close()
|
||||
|
||||
|
||||
def git_commit(tag):
|
||||
run("git add woff2/var build.py")
|
||||
run(f"git commit -m 'Release {tag}'")
|
||||
run(f"git tag {tag}")
|
||||
print("Committed and tagged")
|
||||
|
||||
run("git push origin")
|
||||
run(f"git push origin {tag}")
|
||||
print("Pushed to origin")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"tag",
|
||||
type=str,
|
||||
help="The tag to build the release for, format: v7.000",
|
||||
)
|
||||
parser.add_argument(
|
||||
"beta",
|
||||
nargs="?",
|
||||
type=str,
|
||||
help="Beta tag name, format: 3 or beta3",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
tag = parse_tag(args)
|
||||
# prompt and wait for user input
|
||||
choose = input(f"Tag {tag}? (Y or n) ")
|
||||
if choose != "" and choose.lower() != "y":
|
||||
print("Aborted")
|
||||
return
|
||||
update_build_script_version(tag)
|
||||
|
||||
target_dir = "fontsource"
|
||||
if os.path.exists(target_dir):
|
||||
shutil.rmtree(target_dir)
|
||||
run("python build.py --ttf-only")
|
||||
run(f"ftcli converter ft2wf -f woff2 ./fonts/TTF -out {target_dir}")
|
||||
run(f"ftcli converter ft2wf -f woff ./fonts/TTF -out {target_dir}")
|
||||
run("ftcli converter ft2wf -f woff2 ./fonts/Variable -out woff2/var")
|
||||
rename_files(target_dir)
|
||||
|
||||
git_commit(tag)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue