57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
import os
|
|
import re
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
VERSION_HEADER = re.compile(r"\[\d+.\d+.\d+\]")
|
|
SCRIPT_DIR = Path(__file__).absolute().parent.parent
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("version")
|
|
args = parser.parse_args()
|
|
|
|
changelog = get_changelog(args.version)
|
|
outfilename = save_changelog(args.version, changelog)
|
|
|
|
print(outfilename)
|
|
|
|
|
|
def get_changelog(version: str) -> list[str]:
|
|
changelog = SCRIPT_DIR / "CHANGELOG.md"
|
|
|
|
with changelog.open("r") as infile:
|
|
lines = infile.readlines()
|
|
|
|
start = -1
|
|
end = -1
|
|
|
|
for i, line in enumerate(lines):
|
|
if start == -1:
|
|
match = re.search(version, line)
|
|
if match is None:
|
|
continue
|
|
start = i
|
|
else:
|
|
match = VERSION_HEADER.search(line)
|
|
if match is not None:
|
|
end = i
|
|
break
|
|
|
|
if start == -1:
|
|
exit(1)
|
|
|
|
return lines[start:end] if end > -1 else lines[start:]
|
|
|
|
|
|
def save_changelog(version: str, lines: list[str]) -> str:
|
|
version_changelog = SCRIPT_DIR / f"wapp-changelog-{version}.md"
|
|
with version_changelog.open("w") as outfile:
|
|
outfile.writelines(lines)
|
|
return str(version_changelog)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|