summarylogtreecommitdiffstats
path: root/pkgver.py
blob: 2945c3e7822801a0da0c010aab8ae88ba0ed10bc (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
#!/usr/bin/env python3
import yaml
import urllib.request
import xml.etree.ElementTree as ET  # wants to call Home
import subprocess
import re


def get_xivlauncher_commit():
    with urllib.request.urlopen(
        "https://raw.githubusercontent.com/flathub/dev.goats.xivlauncher/master/dev.goats.xivlauncher.yml"
    ) as f:
        flatpak_manifest = yaml.safe_load(f)
    for module in flatpak_manifest["modules"]:
        if module["name"] == "xivlauncher":
            for source in module["sources"]:
                if (
                    isinstance(source, dict)
                    and "url" in source.keys()
                    and source["url"]
                    == "https://github.com/goatcorp/FFXIVQuickLauncher.git"
                ):
                    return source["commit"]
    raise Exception("Could not get current XIVLauncher commit hash")


def get_version(commit):
    with urllib.request.urlopen(
        f"https://raw.githubusercontent.com/goatcorp/FFXIVQuickLauncher/{commit}/src/XIVLauncher.Core/XIVLauncher.Core.csproj"
    ) as f:
        csproj = ET.fromstring(f.read())
    for propertygroup in csproj.findall("PropertyGroup"):
        version = propertygroup.find("Version")
        if isinstance(
            version, ET.Element
        ):  # we cant check the existence, since bool(obj) calls obj.__len__ which for this element is 0
            return version.text
    raise Exception("Could not determine latest XIVLauncher version")


if __name__ == "__main__":
    commit = get_xivlauncher_commit()
    version = get_version(commit)
    subprocess.run(
        ["git", "tag", "-a", "-m", version, version, commit],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
    )
    git_describe = subprocess.run(
        ["git", "describe", "--long", "--match", version], capture_output=True
    )
    print(
        re.sub(r"([^-]*-g)", r"r\1", git_describe.stdout.decode())
        .strip()
        .replace("-", ".")
    )