intial commit
Test action / integration (push) Successful in 11s

This commit is contained in:
NikoKS committed 2026-08-26 22:59:40 +07:00
commit 88bc7844e3
7 files changed
+446

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""Read bump-my-version's current_version from a local file or Git ref."""
from __future__ import annotations
import argparse
import subprocess
import tomllib
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("config_file")
parser.add_argument("--ref")
return parser.parse_args()
def main() -> None:
args = parse_args()
try:
if args.ref:
content = subprocess.check_output(
["git", "show", f"{args.ref}:{args.config_file}"],
)
else:
with open(args.config_file, "rb") as config_file:
content = config_file.read()
except (OSError, subprocess.CalledProcessError) as error:
raise SystemExit(f"Could not load {args.config_file}: {error}") from error
try:
version = tomllib.loads(content.decode())["tool"]["bumpversion"]["current_version"]
except (KeyError, TypeError, UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
raise SystemExit(
f"Could not read tool.bumpversion.current_version from {args.config_file}: {error}"
) from error
if not isinstance(version, str):
raise SystemExit("tool.bumpversion.current_version must be a string")
print(version)
if __name__ == "__main__":
main()