|
| 1 | +import argparse |
| 2 | +import re |
| 3 | +import subprocess |
| 4 | +from typing import TypedDict |
| 5 | + |
| 6 | + |
| 7 | +class Args(TypedDict): |
| 8 | + tag: str |
| 9 | + |
| 10 | + |
| 11 | +def main(): |
| 12 | + args = get_args() |
| 13 | + |
| 14 | + version = args["tag"].lstrip("v") |
| 15 | + |
| 16 | + validate_changelog(version) |
| 17 | + validate_tooth_json(version) |
| 18 | + validate_tooth_template_json(version) |
| 19 | + |
| 20 | + |
| 21 | +def get_args() -> Args: |
| 22 | + parser = argparse.ArgumentParser() |
| 23 | + parser.add_argument("--tag", required=True) |
| 24 | + |
| 25 | + args = parser.parse_args() |
| 26 | + |
| 27 | + return { |
| 28 | + "tag": args.tag, |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | +def validate_changelog(version: str): |
| 33 | + try: |
| 34 | + subprocess.run( |
| 35 | + f"npx changelog --format markdownlint", |
| 36 | + shell=True, |
| 37 | + check=True, |
| 38 | + ) |
| 39 | + except subprocess.CalledProcessError as e: |
| 40 | + print("Have you installed it by `npm i -g keep-a-changelog`?") |
| 41 | + raise e |
| 42 | + |
| 43 | + with open("CHANGELOG.md", "r", encoding="utf-8") as f: |
| 44 | + content = f.read() |
| 45 | + |
| 46 | + if not re.search(r"## \[{}\]".format(version), content): |
| 47 | + raise Exception("CHANGELOG.md lacks version {}".format(version)) |
| 48 | + |
| 49 | + |
| 50 | +def validate_tooth_json(version: str): |
| 51 | + with open("tooth.json", "r", encoding="utf-8") as f: |
| 52 | + content = f.read() |
| 53 | + |
| 54 | + if not re.search(r"\"version\": \"{}\"".format(version), content): |
| 55 | + raise Exception("tooth.json has wrong version") |
| 56 | + |
| 57 | + if not re.search( |
| 58 | + r"\"gitea.litebds.com/LiteLDev/legacy-script-engine-lua\": \"{}\"".format( |
| 59 | + version |
| 60 | + ), |
| 61 | + content, |
| 62 | + ): |
| 63 | + raise Exception("tooth.json has wrong version in gitea.litebds.com/LiteLDev/legacy-script-engine-lua") |
| 64 | + |
| 65 | + if not re.search( |
| 66 | + r"\"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs\": \"{}\"".format( |
| 67 | + version |
| 68 | + ), |
| 69 | + content, |
| 70 | + ): |
| 71 | + raise Exception("tooth.json has wrong version in gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs") |
| 72 | + |
| 73 | +def validate_tooth_template_json(version: str): |
| 74 | + with open("tooth.template.json", "r", encoding="utf-8") as f: |
| 75 | + content = f.read() |
| 76 | + |
| 77 | + if not re.search(r"\"version\": \"{}\"".format(version), content): |
| 78 | + raise Exception("tooth.template.json has wrong version") |
| 79 | + |
| 80 | +if __name__ == "__main__": |
| 81 | + main() |
0 commit comments