Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2022-07-27 10:55:49 +0300
committerlovetox <philipp@hoerist.com>2022-07-27 10:56:26 +0300
commite3f6f6ddc90e5cd1c3c60a95365705ab9ff84190 (patch)
tree969c96b875e46cd079342df25a98234d6834c3cf /scripts
parentb364e0e2403e5c95f55f686cadf8e5ad8665c5a6 (diff)
chore: Add bump_version.py
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bump_version.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/scripts/bump_version.py b/scripts/bump_version.py
new file mode 100755
index 0000000..54192ce
--- /dev/null
+++ b/scripts/bump_version.py
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+
+import re
+import argparse
+from pathlib import Path
+import subprocess
+
+REPO_DIR = Path(__file__).resolve().parent.parent
+
+
+INIT = REPO_DIR / 'nbxmpp' / '__init__.py'
+CFG = REPO_DIR / 'setup.cfg'
+CHANGELOG = REPO_DIR / 'ChangeLog'
+
+VERSION_RX = r'\d+\.\d+\.\d+'
+
+
+def get_current_version() -> str:
+ content = INIT.read_text(encoding='utf8')
+ match = re.search(VERSION_RX, content)
+ if match is None:
+ exit('Unable to find current version')
+ return match[0]
+
+
+def bump_version(current_version: str, new_version: str) -> None:
+ content = INIT.read_text(encoding='utf8')
+ content = content.replace(current_version, new_version, 1)
+ INIT.write_text(content, encoding='utf8')
+
+ content = CFG.read_text(encoding='utf8')
+ content = content.replace(current_version, new_version, 1)
+ CFG.write_text(content, encoding='utf8')
+
+
+def make_changelog(new_version: str) -> None:
+
+ cmd = [
+ 'git-chglog',
+ '--next-tag',
+ new_version
+ ]
+
+ result = subprocess.run(cmd,
+ cwd=REPO_DIR,
+ text=True,
+ check=True,
+ capture_output=True)
+
+ changes = result.stdout
+ changes = changes.removeprefix('\n')
+
+ current_changelog = CHANGELOG.read_text()
+
+ with CHANGELOG.open('w') as f:
+ f.write(changes + current_changelog)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Bump Version')
+ parser.add_argument('version', help='The new version, e.g. 1.5.0')
+ args = parser.parse_args()
+
+ current_version = get_current_version()
+
+ bump_version(current_version, args.version)
+ make_changelog(args.version)