diff --git a/scripts/validate_release.py b/scripts/validate_release.py new file mode 100644 index 0000000..6238506 --- /dev/null +++ b/scripts/validate_release.py @@ -0,0 +1,66 @@ +import argparse +import re +import subprocess +from typing import TypedDict + + +class Args(TypedDict): + tag: str + + +def main(): + args = get_args() + + version = args["tag"].lstrip("v") + + validate_changelog(version) + validate_tooth_json(version) + + +def get_args() -> Args: + parser = argparse.ArgumentParser() + parser.add_argument("--tag", required=True) + + args = parser.parse_args() + + return { + "tag": args.tag, + } + + +def validate_changelog(version: str): + try: + subprocess.run( + f"npx changelog --format markdownlint", + shell=True, + check=True, + ) + except subprocess.CalledProcessError as e: + print("Have you installed it by `npm i -g keep-a-changelog`?") + raise e + + with open("CHANGELOG.md", "r", encoding="utf-8") as f: + content = f.read() + + if not re.search(r"## \[{}\]".format(version), content): + raise Exception("CHANGELOG.md lacks version {}".format(version)) + + +def validate_tooth_json(version: str): + with open("tooth.json", "r", encoding="utf-8") as f: + content = f.read() + + if not re.search(r"\"version\": \"{}\"".format(version), content): + raise Exception("tooth.json has wrong version") + + if not re.search( + r"\"https://github.com/LiteLDev/MoreDimensions/releases/download/v{}/more-dimensions-windows-x64.zip\"".format( + version + ), + content, + ): + raise Exception("tooth.json has wrong version in asset URL") + + +if __name__ == "__main__": + main()