mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 14:06:14 -05:00
ci: add Windows package builds and verified update publication
This commit is contained in:
9 files changed
+662
-3
No files matched your search
@@ -175,7 +175,7 @@ release_snapshot() {
|
||||
|
||||
# The appcast publisher removes expired macOS snapshots after the new feed
|
||||
# is live. Removing them here would temporarily break the current feed.
|
||||
if [[ "$asset" == GPConnect_*_arm64.* ]]; then
|
||||
if [[ "$asset" == GPConnect_*_arm64.* || "$asset" == GPConnect_*_windows-x64-setup.exe* ]]; then
|
||||
continue
|
||||
fi
|
||||
if ! delete_release_asset "$asset"; then
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Retain other platform/channel feeds before replacing a static Worker deployment."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
from urllib.error import HTTPError
|
||||
from urllib.parse import urlparse
|
||||
from urllib.request import urlopen
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
FEEDS = ("appcast.xml", "latest.json", "windows/latest.json", "windows/stable/appcast.xml", "windows/snapshot/appcast.xml")
|
||||
|
||||
|
||||
def preserve(base_url: str, directory: Path, exclude: list[str]) -> None:
|
||||
if urlparse(base_url).scheme != "https":
|
||||
raise ValueError("feed host must use HTTPS")
|
||||
for relative in FEEDS:
|
||||
if relative in exclude:
|
||||
continue
|
||||
try:
|
||||
with urlopen(base_url.rstrip("/") + "/" + relative, timeout=30) as response:
|
||||
data = response.read(1024 * 1024 + 1)
|
||||
except HTTPError as error:
|
||||
if error.code == 404:
|
||||
continue
|
||||
raise
|
||||
if len(data) > 1024 * 1024:
|
||||
raise ValueError(f"published feed is too large: {relative}")
|
||||
if relative.endswith(".json"):
|
||||
json.loads(data)
|
||||
else:
|
||||
ET.fromstring(data)
|
||||
target = directory / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--base-url", required=True)
|
||||
parser.add_argument("--directory", type=Path, required=True)
|
||||
parser.add_argument("--exclude", action="append", default=[], choices=FEEDS)
|
||||
args = parser.parse_args()
|
||||
preserve(args.base_url, args.directory, args.exclude)
|
||||
@@ -0,0 +1,164 @@
|
||||
import argparse
|
||||
import base64
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from urllib.error import HTTPError
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
def load(name, filename):
|
||||
spec = importlib.util.spec_from_file_location(name, Path(__file__).parents[1] / filename)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
feed = load("windows_update_feed", "windows-update-feed.py")
|
||||
preserver = load("preserve_update_feeds", "preserve-update-feeds.py")
|
||||
|
||||
|
||||
class WindowsFeedTests(unittest.TestCase):
|
||||
def args(self, root, channel="stable", version="3.4.0", build=None):
|
||||
name = feed.installer_name(version, channel, build)
|
||||
installer = root / name
|
||||
installer.write_bytes(b"test installer")
|
||||
signature = root / "installer.sig"
|
||||
signature.write_text(base64.b64encode(bytes(64)).decode())
|
||||
highlights = root / "highlights.txt"
|
||||
highlights.write_text("Update & improve <Windows>.\n")
|
||||
tag = f"v{version}" if channel == "stable" else "snapshot"
|
||||
return argparse.Namespace(installer=installer, signature_file=signature,
|
||||
installer_url=f"https://github.com/yuezk/GlobalProtect-openconnect/releases/download/{tag}/{name}",
|
||||
repository="yuezk/GlobalProtect-openconnect", channel=channel,
|
||||
version=version, build=build, released_at="2026-11-14",
|
||||
highlights_file=highlights, input=None, output=root / "windows", allow_localhost=False)
|
||||
|
||||
def test_catalog_and_appcast_keep_the_same_version_and_payload(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
args = self.args(Path(directory))
|
||||
feed.generate(args)
|
||||
catalog = json.loads((args.output / "latest.json").read_text())
|
||||
self.assertEqual(catalog["stable"]["platforms"], ["windows"])
|
||||
item = ET.parse(args.output / "stable/appcast.xml").find("channel/item")
|
||||
self.assertEqual(item.findtext("description"), "Update & improve <Windows>.")
|
||||
enclosure = item.find("enclosure")
|
||||
self.assertEqual(enclosure.get(f"{{{feed.SPARKLE}}}version"), catalog["stable"]["version"])
|
||||
self.assertEqual(int(enclosure.get("length")), args.installer.stat().st_size)
|
||||
self.assertEqual(enclosure.get(f"{{{feed.SPARKLE}}}os"), "windows-x64")
|
||||
|
||||
def test_snapshot_promotion_retains_stable_and_rejects_downgrade(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
args = self.args(Path(directory))
|
||||
feed.generate(args)
|
||||
args.input = args.output / "latest.json"
|
||||
args.channel, args.build = "snapshot", "2026.1114.2"
|
||||
args.installer = args.installer.rename(args.installer.parent / feed.installer_name(args.version, args.channel, args.build))
|
||||
args.installer_url = f"https://github.com/{args.repository}/releases/download/snapshot/{args.installer.name}"
|
||||
feed.generate(args)
|
||||
catalog = json.loads(args.input.read_text())
|
||||
self.assertEqual(catalog["stable"]["version"], "3.4.0")
|
||||
self.assertEqual(catalog["snapshot"]["build"], "2026.1114.2")
|
||||
enclosure = ET.parse(args.output / "snapshot/appcast.xml").find("channel/item/enclosure")
|
||||
self.assertEqual(enclosure.get(f"{{{feed.SPARKLE}}}version"), "3.4.0-snapshot.2026.1114.2")
|
||||
args.build = "2026.1114.1"
|
||||
args.installer = args.installer.rename(args.installer.parent / feed.installer_name(args.version, args.channel, args.build))
|
||||
args.installer_url = f"https://github.com/{args.repository}/releases/download/snapshot/{args.installer.name}"
|
||||
with self.assertRaisesRegex(ValueError, "older"):
|
||||
feed.generate(args)
|
||||
|
||||
def test_snapshot_filename_cannot_advertise_another_build(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
args = self.args(Path(directory), "snapshot", build="2026.1114.1")
|
||||
args.build = "2026.1114.2"
|
||||
with self.assertRaisesRegex(ValueError, "filename does not match"):
|
||||
feed.generate(args)
|
||||
|
||||
def test_newer_stable_updates_both_native_feeds_and_retains_snapshot_history(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
snapshot = self.args(root, "snapshot", build="2026.1114.2")
|
||||
feed.generate(snapshot)
|
||||
stable = self.args(root, version="3.5.0")
|
||||
stable.input = stable.output / "latest.json"
|
||||
feed.generate(stable)
|
||||
catalog = json.loads(stable.input.read_text())
|
||||
self.assertEqual(catalog["snapshot"]["baseVersion"], "3.4.0")
|
||||
self.assertEqual(catalog["snapshot"]["build"], "2026.1114.2")
|
||||
for channel in ("stable", "snapshot"):
|
||||
enclosure = ET.parse(stable.output / channel / "appcast.xml").find("channel/item/enclosure")
|
||||
self.assertEqual(enclosure.get(f"{{{feed.SPARKLE}}}version"), "3.5.0")
|
||||
self.assertEqual(enclosure.get("url"), stable.installer_url)
|
||||
|
||||
def test_stable_without_snapshot_initializes_both_native_feeds(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
args = self.args(Path(directory))
|
||||
feed.generate(args)
|
||||
self.assertEqual((args.output / "stable/appcast.xml").read_bytes(),
|
||||
(args.output / "snapshot/appcast.xml").read_bytes())
|
||||
self.assertIsNone(json.loads((args.output / "latest.json").read_text())["snapshot"])
|
||||
|
||||
def test_stable_does_not_replace_same_or_newer_base_snapshot_feed(self):
|
||||
for snapshot_version in ("3.4.0", "3.5.0"):
|
||||
with self.subTest(snapshot_version=snapshot_version), tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
snapshot = self.args(root, "snapshot", version=snapshot_version, build="2026.1114.2")
|
||||
feed.generate(snapshot)
|
||||
before = (snapshot.output / "snapshot/appcast.xml").read_bytes()
|
||||
stable = self.args(root)
|
||||
stable.input = stable.output / "latest.json"
|
||||
feed.generate(stable)
|
||||
self.assertEqual((stable.output / "snapshot/appcast.xml").read_bytes(), before)
|
||||
|
||||
def test_snapshot_older_than_stable_is_rejected_without_changing_published_files(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
stable = self.args(root, version="3.5.0")
|
||||
feed.generate(stable)
|
||||
published = {relative: (stable.output / relative).read_bytes()
|
||||
for relative in ("latest.json", "stable/appcast.xml", "snapshot/appcast.xml")}
|
||||
snapshot = self.args(root, "snapshot", version="3.4.0", build="2026.1114.3")
|
||||
snapshot.input = stable.output / "latest.json"
|
||||
with self.assertRaisesRegex(ValueError, "snapshot base version is older"):
|
||||
feed.generate(snapshot)
|
||||
for relative, content in published.items():
|
||||
self.assertEqual((stable.output / relative).read_bytes(), content)
|
||||
|
||||
def test_private_loopback_download_requires_explicit_opt_in(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
args = self.args(Path(directory))
|
||||
args.installer_url = "http://127.0.0.1:18770/setup.exe"
|
||||
with self.assertRaisesRegex(ValueError, "matching GitHub"):
|
||||
feed.generate(args)
|
||||
args.allow_localhost = True
|
||||
feed.generate(args)
|
||||
|
||||
def test_missing_or_malformed_signature_is_rejected(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
args = self.args(Path(directory))
|
||||
args.signature_file.write_text("not a signature")
|
||||
with self.assertRaises(ValueError):
|
||||
feed.generate(args)
|
||||
|
||||
def test_preservation_keeps_other_feeds_and_does_not_hide_server_errors(self):
|
||||
class Response:
|
||||
def __enter__(self): return self
|
||||
def __exit__(self, *unused): pass
|
||||
def read(self, length): return b'{"schemaVersion": 1}'
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
with patch.object(preserver, "urlopen", return_value=Response()) as request:
|
||||
preserver.preserve("https://updates.gpgui.com", root,
|
||||
["appcast.xml", "latest.json", "windows/stable/appcast.xml", "windows/snapshot/appcast.xml"])
|
||||
self.assertTrue((root / "windows/latest.json").exists())
|
||||
self.assertEqual(request.call_count, 1)
|
||||
with patch.object(preserver, "urlopen", side_effect=HTTPError("url", 500, "failure", {}, None)):
|
||||
with self.assertRaises(HTTPError):
|
||||
preserver.preserve("https://updates.gpgui.com", root, [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -10,7 +10,7 @@ import unicodedata
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
ALLOWED_PLATFORMS = {"linux", "freebsd", "openbsd"}
|
||||
ALLOWED_PLATFORMS = {"linux", "freebsd", "openbsd", "windows"}
|
||||
SEMVER = re.compile(r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$")
|
||||
BUILD = re.compile(r"^(0|[1-9][0-9]*)(?:\.(0|[1-9][0-9]*)){0,2}$")
|
||||
EXPECTED_TOP_LEVEL_KEYS = {"schemaVersion", "stable", "snapshot"}
|
||||
@@ -192,7 +192,7 @@ def main() -> None:
|
||||
generate_parser.add_argument("--channel", choices=("stable", "snapshot"), required=True)
|
||||
generate_parser.add_argument("--version", required=True)
|
||||
generate_parser.add_argument("--platform", action="append", choices=sorted(ALLOWED_PLATFORMS),
|
||||
help="Published Unix target; repeat for multiple targets (default: all)")
|
||||
help="Published target; repeat for multiple targets (default: Unix targets)")
|
||||
generate_parser.add_argument("--build")
|
||||
generate_parser.add_argument("--released-at", required=True)
|
||||
generate_parser.add_argument("--highlights-file", required=True, type=Path)
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the Windows catalog and WinSparkle appcast from one verified installer."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
SPARKLE = "http://www.andymatuschak.org/xml-namespaces/sparkle"
|
||||
ET.register_namespace("sparkle", SPARKLE)
|
||||
spec = importlib.util.spec_from_file_location("update_manifest", Path(__file__).with_name("validate-update-manifest.py"))
|
||||
manifest = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(manifest)
|
||||
|
||||
|
||||
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 generate(args: argparse.Namespace) -> None:
|
||||
manifest.version_tuple(args.version)
|
||||
if args.channel == "snapshot":
|
||||
if args.build is None:
|
||||
raise ValueError("snapshot releases require --build")
|
||||
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 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"]
|
||||
if stable is not None and manifest.version_tuple(args.version) < manifest.version_tuple(stable["version"]):
|
||||
raise ValueError("snapshot base version is older than the published stable release")
|
||||
output = args.output
|
||||
output.mkdir(parents=True, exist_ok=True)
|
||||
catalog = output / "latest.json"
|
||||
manifest.generate(argparse.Namespace(
|
||||
repository=args.repository, channel=args.channel, version=args.version,
|
||||
platform=["windows"], build=args.build, released_at=args.released_at,
|
||||
highlights_file=args.highlights_file, input=args.input, output=catalog,
|
||||
))
|
||||
data = json.loads(catalog.read_text(encoding="utf-8"))
|
||||
if any(release and release["platforms"] != ["windows"] for release in [data["stable"], data["snapshot"]]):
|
||||
raise ValueError("Windows catalog may contain only the Windows target")
|
||||
release = data[args.channel]
|
||||
display_version = release_version(args.version, args.channel, args.build)
|
||||
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,
|
||||
})
|
||||
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.
|
||||
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")
|
||||
|
||||
|
||||
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("--repository", default="yuezk/GlobalProtect-openconnect")
|
||||
parser.add_argument("--channel", choices=("stable", "snapshot"), required=True)
|
||||
parser.add_argument("--version", required=True)
|
||||
parser.add_argument("--build")
|
||||
parser.add_argument("--released-at", required=True)
|
||||
parser.add_argument("--highlights-file", type=Path, required=True)
|
||||
parser.add_argument("--input", type=Path)
|
||||
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()
|
||||
try:
|
||||
generate(args)
|
||||
except (OSError, ValueError) as error:
|
||||
parser.error(str(error))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user