File: tag_version

package info (click to toggle)
toot 0.51.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,108 kB
  • sloc: python: 9,284; makefile: 41
file content (63 lines) | stat: -rwxr-xr-x 1,524 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

"""
Creates an annotated git tag for a given version number.

The tag will include the version number and changes for given version.

Usage: tag_version [version]
"""

import subprocess
import sys
import textwrap
import yaml

from datetime import date
from os import path

path = path.join(path.dirname(path.dirname(path.abspath(__file__))), "changelog.yaml")
with open(path, "r") as f:
    changelog = yaml.safe_load(f)

if len(sys.argv) != 2:
    print("Wrong argument count", file=sys.stderr)
    sys.exit(1)

version = sys.argv[1]

changelog_item = changelog.get(version)
if not changelog_item:
    print(f"Version `{version}` not found in changelog.", file=sys.stderr)
    sys.exit(1)

release_date = changelog_item["date"]
description = changelog_item.get("description")
changes = changelog_item["changes"]

if not isinstance(release_date, date):
    print(f"Release date not set for version `{version}` in the changelog.", file=sys.stderr)
    sys.exit(1)

commit_message = f"toot {version}\n\n"

if description:
    commit_message += textwrap.dedent(description)
    commit_message += "\n\n"

for c in changes:
    lines = textwrap.wrap(c, 70)
    initial = True
    for line in lines:
        lead = " *" if initial else "  "
        initial = False
        commit_message += f"{lead} {line}\n"

proc = subprocess.run(["git", "tag", "-a", version, "-m", commit_message])
if proc.returncode != 0:
    sys.exit(1)

print()
print(commit_message)
print()
print(f"Version {version} tagged \\o/")