source: trunk/misc/build_helpers/update-version.py

Last change on this file was 6bb46a83, checked in by meejah <meejah@…>, at 2022-10-03T00:52:57Z

flake8

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#
2# this updates the (tagged) version of the software
3#
4# Any "options" are hard-coded in here (e.g. the GnuPG key to use)
5#
6
7author = "meejah <meejah@meejah.ca>"
8
9
10import sys
11import time
12from datetime import datetime
13from packaging.version import Version
14
15from dulwich.repo import Repo
16from dulwich.porcelain import (
17    tag_list,
18    tag_create,
19    status,
20)
21
22from twisted.internet.task import (
23    react,
24)
25from twisted.internet.defer import (
26    ensureDeferred,
27)
28
29
30def existing_tags(git):
31    versions = sorted(
32        Version(v.decode("utf8").lstrip("tahoe-lafs-"))
33        for v in tag_list(git)
34        if v.startswith(b"tahoe-lafs-")
35    )
36    return versions
37
38
39def create_new_version(git):
40    versions = existing_tags(git)
41    biggest = versions[-1]
42
43    return Version(
44        "{}.{}.{}".format(
45            biggest.major,
46            biggest.minor + 1,
47            0,
48        )
49    )
50
51
52async def main(reactor):
53    git = Repo(".")
54
55    st = status(git)
56    if any(st.staged.values()) or st.unstaged:
57        print("unclean checkout; aborting")
58        raise SystemExit(1)
59
60    v = create_new_version(git)
61    if "--no-tag" in sys.argv:
62        print(v)
63        return
64
65    print("Existing tags: {}".format("\n".join(str(x) for x in existing_tags(git))))
66    print("New tag will be {}".format(v))
67
68    # the "tag time" is seconds from the epoch .. we quantize these to
69    # the start of the day in question, in UTC.
70    now = datetime.now()
71    s = now.utctimetuple()
72    ts = int(
73        time.mktime(
74            time.struct_time((s.tm_year, s.tm_mon, s.tm_mday, 0, 0, 0, 0, s.tm_yday, 0))
75        )
76    )
77    tag_create(
78        repo=git,
79        tag="tahoe-lafs-{}".format(str(v)).encode("utf8"),
80        author=author.encode("utf8"),
81        message="Release {}".format(v).encode("utf8"),
82        annotated=True,
83        objectish=b"HEAD",
84        sign=author.encode("utf8"),
85        tag_time=ts,
86        tag_timezone=0,
87    )
88
89    print("Tag created locally, it is not pushed")
90    print("To push it run something like:")
91    print("   git push origin {}".format(v))
92
93
94if __name__ == "__main__":
95    react(lambda r: ensureDeferred(main(r)))
Note: See TracBrowser for help on using the repository browser.