Files

41 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Raise the game version in VERSION: vYYYYMM-NNNNN.
Run with every change to the game (the number counts the changes of the current month and
starts again at 00001 when the month turns). The version is shown on the title screen and in
the pause menu, and it is the version a savegame support question refers to.
"""
import datetime
import pathlib
import re
import sys
FILE = pathlib.Path(__file__).resolve().parent.parent / "VERSION"
PATTERN = re.compile(r"^v(\d{6})-(\d{1,5})$")
def main() -> int:
month = datetime.date.today().strftime("%Y%m")
current = FILE.read_text(encoding="utf-8").strip() if FILE.exists() else ""
match = PATTERN.match(current)
if match and match.group(1) == month:
number = int(match.group(2)) + 1
elif match: # a new month: count again from the first change
number = 1
elif current:
print(f"VERSION does not look like vYYYYMM-NNNNN: {current!r}", file=sys.stderr)
return 1
else:
number = 1
version = f"v{month}-{number:05d}"
FILE.write_text(version + "\n", encoding="utf-8")
if match:
print(f"{current} -> {version}")
else:
print(version)
return 0
if __name__ == "__main__":
sys.exit(main())