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

bump_version.py « scripts - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ae8d1ccfb2b5db37f70fdc49ec0769c325631a2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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'tag: {current_version}',
                              f'tag: {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)