diff options
author | lovetox <philipp@hoerist.com> | 2022-05-21 13:21:57 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2022-05-21 13:21:57 +0300 |
commit | a0fddbde5dbc44c6d6a974023357d46e8ffaedf9 (patch) | |
tree | f317f6f152a7963c578920b2eb33f8cd4312c15d /scripts | |
parent | dbfef6f461ceee48d55010e867b61db2cfb0e36a (diff) |
chore: Scripts: Add bump_version script
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/bump_version.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/bump_version.py b/scripts/bump_version.py new file mode 100755 index 000000000..998ff0089 --- /dev/null +++ b/scripts/bump_version.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +import re +import argparse +from datetime import datetime +from pathlib import Path + +REPO_DIR = Path(__file__).resolve().parent.parent + + +INIT = REPO_DIR / 'gajim' / '__init__.py' +FLATPAK = REPO_DIR / 'flatpak' / 'org.gajim.Gajim.yaml' +APPDATA = REPO_DIR / 'data' / 'org.gajim.Gajim.appdata.xml.in' + +VERSION_RX = r"\d+\.\d+\.\d+" + + +def get_current_version() -> str: + with INIT.open('r') as f: + content = f.read() + + match = re.search(VERSION_RX, content) + if match is None: + exit('Unable to find current version') + return match[0] + + +def bump_init(current_version: str, new_version: str) -> None: + with INIT.open('r', encoding='utf8') as f: + content = f.read() + + content = content.replace(current_version, new_version, 1) + + with INIT.open('w', encoding='utf8') as f: + f.write(content) + + +def bump_flatpak(current_version: str, new_version: str) -> None: + with FLATPAK.open('r', encoding='utf8') as f: + content = f.read() + + content = content.replace(f'gajim-{current_version}', + f'gajim-{new_version}', 1) + + with FLATPAK.open('w', encoding='utf8') as f: + f.write(content) + + +def bump_appdata(new_version: str) -> None: + with APPDATA.open('r', encoding='utf8') as f: + lines = f.readlines() + + date = datetime.today().strftime('%Y-%m-%d') + release_string = f' <release version="{new_version}" date="{date}" />' + + with APPDATA.open('w', encoding='utf8') as f: + for line in lines: + f.write(line) + if '<releases>' in line: + f.write(release_string) + f.write('\n') + + +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_init(current_version, args.version) + bump_flatpak(current_version, args.version) + bump_appdata(args.version) |