ci: build native Windows ARM64 packages and publish paired updates (#707)

This commit is contained in:
Kevin Yue authored and GitHub committed 2026-11-15 02:34:19 +08:00
1 parent 5031d4dcfb
commit dedd06366e
9 files changed
+281 -100

No files matched your search

+61 -43
View File
@@ -1,9 +1,8 @@
#!/usr/bin/env python3
"""Build the Windows catalog and WinSparkle appcast from one verified installer."""
from __future__ import annotations
"""Build one Windows catalog and appcast from verified native installers."""
import argparse
import base64
from dataclasses import dataclass
import hashlib
import importlib.util
import json
@@ -18,14 +17,47 @@ manifest = importlib.util.module_from_spec(spec)
spec.loader.exec_module(manifest)
@dataclass
class Payload:
architecture: str
installer: Path
installer_url: str
signature_file: Path
def release_version(version: str, channel: str, build: str | None) -> str:
if channel == "snapshot":
return f"{version}-snapshot.{build}"
return version
def installer_name(version: str, channel: str, build: str | None) -> str:
return f"GPConnect_{release_version(version, channel, build)}_windows-x64-setup.exe"
def installer_name(version: str, channel: str, build: str | None, architecture: str = "x64") -> str:
return f"GPConnect_{release_version(version, channel, build)}_windows-{architecture}-setup.exe"
def validate_payload(payload: Payload, args: argparse.Namespace) -> tuple[str, int]:
if payload.architecture not in {"x64", "arm64"}:
raise ValueError("unsupported Windows architecture")
expected_name = installer_name(args.version, args.channel, args.build, payload.architecture)
if not args.allow_localhost and payload.installer.name != expected_name:
raise ValueError("installer filename does not match the version, channel, build and architecture")
parsed = urlparse(payload.installer_url)
tag = f"v{args.version}" if args.channel == "stable" else "snapshot"
expected = f"https://github.com/{args.repository}/releases/download/{tag}/"
local = args.allow_localhost and parsed.scheme == "http" and parsed.hostname in {"localhost", "127.0.0.1", "::1"}
if not local and not payload.installer_url.startswith(expected):
raise ValueError("installer URL must identify the matching GitHub release asset")
if parsed.query or parsed.fragment or not parsed.path.endswith(".exe"):
raise ValueError("installer URL must name an EXE without query or fragment")
if not local and parsed.path.rsplit("/", 1)[-1] != expected_name:
raise ValueError("installer download filename does not match the version, channel, build and architecture")
signature = payload.signature_file.read_text(encoding="ascii").strip()
if len(base64.b64decode(signature, validate=True)) != 64:
raise ValueError("EdDSA signature must contain 64 bytes")
length = payload.installer.stat().st_size
if length == 0:
raise ValueError("installer is empty")
return signature, length
def generate(args: argparse.Namespace) -> None:
@@ -36,25 +68,9 @@ def generate(args: argparse.Namespace) -> None:
manifest.build_tuple(args.build)
elif args.build is not None:
raise ValueError("stable releases must not specify --build")
expected_name = installer_name(args.version, args.channel, args.build)
if not args.allow_localhost and args.installer.name != expected_name:
raise ValueError("installer filename does not match the version, channel and build")
parsed = urlparse(args.installer_url)
tag = f"v{args.version}" if args.channel == "stable" else "snapshot"
expected = f"https://github.com/{args.repository}/releases/download/{tag}/"
local = args.allow_localhost and parsed.scheme == "http" and parsed.hostname in {"localhost", "127.0.0.1", "::1"}
if not local and not args.installer_url.startswith(expected):
raise ValueError("installer URL must identify the matching GitHub release asset")
if parsed.query or parsed.fragment or not parsed.path.endswith(".exe"):
raise ValueError("installer URL must name an EXE without query or fragment")
if not local and parsed.path.rsplit("/", 1)[-1] != expected_name:
raise ValueError("installer download filename does not match the version, channel and build")
signature = args.signature_file.read_text(encoding="ascii").strip()
if len(base64.b64decode(signature, validate=True)) != 64:
raise ValueError("EdDSA signature must contain 64 bytes")
length = args.installer.stat().st_size
if length == 0:
raise ValueError("installer is empty")
if not args.payload or len({payload.architecture for payload in args.payload}) != len(args.payload):
raise ValueError("provide one installer per Windows architecture")
prepared = [(payload, *validate_payload(payload, args)) for payload in args.payload]
if args.channel == "snapshot" and args.input is not None:
previous = manifest.validate_manifest(json.loads(args.input.read_text(encoding="utf-8")), args.repository)
stable = previous["stable"]
@@ -76,40 +92,40 @@ def generate(args: argparse.Namespace) -> None:
rss = ET.Element("rss", {"version": "2.0"})
channel = ET.SubElement(rss, "channel")
ET.SubElement(channel, "title").text = "GP Connect for Windows"
item = ET.SubElement(channel, "item")
ET.SubElement(item, "title").text = f"GP Connect {display_version}"
ET.SubElement(item, "description").text = "\n".join(release["highlights"])
ET.SubElement(item, f"{{{SPARKLE}}}minimumSystemVersion").text = "10.0.19041"
ET.SubElement(item, "enclosure", {
"url": args.installer_url, "length": str(length), "type": "application/octet-stream",
f"{{{SPARKLE}}}version": display_version,
f"{{{SPARKLE}}}shortVersionString": display_version,
f"{{{SPARKLE}}}os": "windows-x64", f"{{{SPARKLE}}}edSignature": signature,
})
for payload, signature, length in prepared:
item = ET.SubElement(channel, "item")
ET.SubElement(item, "title").text = f"GP Connect {display_version}"
ET.SubElement(item, "description").text = "\n".join(release["highlights"])
minimum = "10.0.22000" if payload.architecture == "arm64" else "10.0.19041"
ET.SubElement(item, f"{{{SPARKLE}}}minimumSystemVersion").text = minimum
ET.SubElement(item, "enclosure", {
"url": payload.installer_url, "length": str(length), "type": "application/octet-stream",
f"{{{SPARKLE}}}version": display_version,
f"{{{SPARKLE}}}shortVersionString": display_version,
f"{{{SPARKLE}}}os": f"windows-{payload.architecture}", f"{{{SPARKLE}}}edSignature": signature,
})
ET.indent(rss)
channels = [args.channel]
snapshot = data["snapshot"]
if args.channel == "stable" and (
snapshot is None or manifest.version_tuple(args.version) > manifest.version_tuple(snapshot["baseVersion"])
):
# Core offers a newer stable release to snapshot installations too.
# Keep the snapshot catalog history, but route its native install feed
# to the same newer stable candidate until a new snapshot is promoted.
# A newer stable release also updates snapshot installations.
channels.append("snapshot")
for target_channel in channels:
channel_directory = output / target_channel
channel_directory.mkdir(exist_ok=True)
ET.ElementTree(rss).write(channel_directory / "appcast.xml", encoding="utf-8", xml_declaration=True)
with args.installer.open("rb") as installer:
digest = hashlib.file_digest(installer, "sha256").hexdigest()
(output / (args.installer.name + ".sha256")).write_text(f"{digest} {args.installer.name}\n", encoding="ascii")
for payload, _, _ in prepared:
with payload.installer.open("rb") as installer:
digest = hashlib.file_digest(installer, "sha256").hexdigest()
(output / (payload.installer.name + ".sha256")).write_text(f"{digest} {payload.installer.name}\n", encoding="ascii")
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--installer", type=Path, required=True)
parser.add_argument("--installer-url", required=True)
parser.add_argument("--signature-file", type=Path, required=True)
parser.add_argument("--payload", nargs=4, action="append", required=True,
metavar=("ARCH", "INSTALLER", "URL", "SIGNATURE_FILE"))
parser.add_argument("--repository", default="yuezk/GlobalProtect-openconnect")
parser.add_argument("--channel", choices=("stable", "snapshot"), required=True)
parser.add_argument("--version", required=True)
@@ -120,6 +136,8 @@ def main() -> None:
parser.add_argument("--output", type=Path, required=True)
parser.add_argument("--allow-localhost", action="store_true", help="Permit an isolated loopback test download")
args = parser.parse_args()
args.payload = [Payload(architecture, Path(installer), url, Path(signature))
for architecture, installer, url, signature in args.payload]
try:
generate(args)
except (OSError, ValueError) as error: