summaryrefslogtreecommitdiff
path: root/scripts/release/repo_release.py
blob: 7e4c3824f2c9ea73aa9b118f4dc35ae405596eb9 (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
"""
scripts/release/repo_release.py

Run after every `pyinstaller labui.spec` build, on the same platform that
build was produced on (no cross-compiling — this packages whatever
dist/LabUI/ currently contains, which is only correct for the OS the build
just ran on). Packages the freshly built dist/LabUI bundle as a new signed
tufup target, in that platform's own repo tree.

Prerequisites:
  - repo_init.py has been run once already for this platform
    (./<platform>/repository and ./<platform>/keystore exist)
  - core/version.py has been bumped to the new version
  - dist/LabUI/ exists (pyinstaller labui.spec has just been run, on this
    same machine/OS)

After this completes, see README.md in this directory for how to publish
the updated ./<platform>/repository/metadata and
./<platform>/repository/targets files to the "updates-<platform>" GitHub
Release.
"""

import os
import sys
from pathlib import Path

_THIS_DIR   = Path(__file__).resolve().parent
_REPO_ROOT  = _THIS_DIR.parent.parent
_DIST_DIR   = _REPO_ROOT / "dist" / "LabUI"


def _platform_key() -> str:
    """win / mac / linux — must match core.updater._platform_key() and the
    "updates-<key>" release tag on the publishing side."""
    if sys.platform.startswith("win"):
        return "win"
    if sys.platform == "darwin":
        return "mac"
    return "linux"


PLATFORM = _platform_key()

# Import core.version before changing cwd — needs the repo root on sys.path,
# which won't be true anymore once we chdir into scripts/release/<platform>.
sys.path.insert(0, str(_REPO_ROOT))
from core.version import __version__ as APP_VERSION

from tufup.repo import Repository

# tufup's config file / relative repo_dir / keys_dir all resolve against cwd
# (same reasoning as repo_init.py) — pin it here too, for the same reason.
_PLATFORM_DIR = _THIS_DIR / PLATFORM
os.chdir(_PLATFORM_DIR)


def main():
    if not _DIST_DIR.is_dir():
        raise SystemExit(
            f"{_DIST_DIR} not found — run `pyinstaller labui.spec` from the "
            f"repo root first, on this same machine/OS."
        )
    if not (_PLATFORM_DIR / "repository").is_dir():
        raise SystemExit(
            f"{_PLATFORM_DIR / 'repository'} not found — run "
            f"`python repo_init.py` once for this platform first."
        )

    repo = Repository.from_config()

    changelog = input(f"One-line changelog for v{APP_VERSION} ({PLATFORM}, optional): ").strip()
    custom_metadata = {"changelog": changelog} if changelog else None

    repo.add_bundle(
        new_bundle_dir=_DIST_DIR,
        new_version=APP_VERSION,
        skip_patch=True,  # no binary delta patching for now — full archive only
        custom_metadata=custom_metadata,
    )
    repo.publish_changes(private_key_dirs=[Path("keystore")])

    print(f"Signed and published v{APP_VERSION} ({PLATFORM}) to {_PLATFORM_DIR / 'repository'}")
    print(f"Next: upload {_PLATFORM_DIR / 'repository' / 'metadata'}/* and "
          f"{_PLATFORM_DIR / 'repository' / 'targets'}/* to the "
          f"'updates-{PLATFORM}' GitHub Release — see README.md in this directory.")


if __name__ == "__main__":
    main()