summarylogtreecommitdiffstats
path: root/make-release.py
blob: 7fb158a87e8cfd3266706f9391fda8200ee0193e (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import argparse
import os
import sys
import subprocess

if sys.version_info.major < 3:
    sys.exit("Python3 required")

THIS_DIR = os.path.abspath(os.path.dirname(__file__))

def check_not_in_venv():
    if os.environ.get("VIRTUAL_ENV"):
        sys.exit("You should not run this in a virtualenv!")

def clean():
    cmd = ["git", "clean", "--force", "-d", "-x"]
    subprocess.check_call(cmd, cwd=THIS_DIR)


def set_version(version):
    version_changed = False
    pkgbuild = os.path.join(THIS_DIR, "PKGBUILD")
    with open(pkgbuild, "r") as fp:
        lines = fp.readlines()
    new_lines = list()
    for line in lines:
        if line.startswith("pkgver"):
            previous_version = line.split("=")[1]
            if previous_version != version:
                version_changed = True
            new_line = "pkgver='%s'\n" % version
            new_lines.append(new_line)
        else:
            new_lines.append(line)

    with open(pkgbuild, "w") as fp:
        fp.writelines(new_lines)
    return version_changed

def reset_pkgrel():
    pkgbuild = os.path.join(THIS_DIR, "PKGBUILD")
    with open(pkgbuild, "r") as fp:
        lines = fp.readlines()
    new_lines = list()
    for line in lines:
        if line.startswith("pkgrel"):
            new_line = "pkgrel='1'\n"
            new_lines.append(new_line)
        else:
            new_lines.append(line)
    with open(pkgbuild, "w") as fp:
        fp.writelines(new_lines)

def set_checksums():
    cmd = ["/usr/bin/updpkgsums"]
    subprocess.check_call(cmd, cwd=THIS_DIR)

def run_makepkg():
    cmd = ["/usr/bin/extra-x86_64-build"]
    subprocess.check_call(cmd, cwd=THIS_DIR)


def update_srcinfo():
    cmd = ["mksrcinfo"]
    subprocess.check_call(cmd, cwd=THIS_DIR)

def commit_all(version):
    cmd = ["git", "add", "PKGBUILD", ".SRCINFO"]
    subprocess.check_call(cmd)
    cmd = ["git", "commit", "--message", "Update to %s" % version]
    subprocess.check_call(cmd)

def push():
    cmd = ["git", "--no-pager", "show", "HEAD"]
    subprocess.check_call(cmd)
    answer = input("OK to push (y/n)? ")
    if answer == "y":
        cmd = ["git", "push"]
        subprocess.check_call(cmd)

def make_release(version):
    clean()
    version_changed = set_version(version)
    if version_changed:
        reset_pkgrel()
    set_checksums()
    run_makepkg()
    update_srcinfo()
    commit_all(version)
    push()

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("version")
    args = parser.parse_args()
    check_not_in_venv()
    version = args.version
    make_release(version)

if __name__ == "__main__":
    main()