From 8e38e2a6f4540d843413a9c05402030e78ee00c5 Mon Sep 17 00:00:00 2001 From: Waozi Date: Mon, 21 Sep 2026 11:46:14 -0300 Subject: [PATCH] Keep release appcast tool with Inbe --- .github/workflows/release.yml | 8 +-- scripts/make_appcast.py | 104 ++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100755 scripts/make_appcast.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ca3bc3ce9..1ff580b34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -846,12 +846,6 @@ jobs: with: fetch-depth: 0 - - name: Checkout Kryon Appcast Tool - run: | - set -euo pipefail - git submodule update --init --depth 1 vendor/kryon - test -f vendor/kryon/scripts/make_appcast.py - - name: Download Release Artifacts uses: actions/download-artifact@v4 with: @@ -954,7 +948,7 @@ jobs: echo "no release artifacts found for the appcast" exit 1 fi - python3 vendor/kryon/scripts/make_appcast.py \ + python3 scripts/make_appcast.py \ --version "$VERSION" \ --base-url "$BASE" \ --notes-url "https://github.com/waozixyz/inbe/releases/tag/$TAG" \ diff --git a/scripts/make_appcast.py b/scripts/make_appcast.py new file mode 100755 index 000000000..9ef240e82 --- /dev/null +++ b/scripts/make_appcast.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +"""Generate the Inbe appcast for a release. + +The release workflow publishes appcast.json next to its artifacts: + + scripts/make_appcast.py \ + --version "$VERSION" \ + --base-url "https://github.com/OWNER/APP/releases/download/v$VERSION" \ + --notes-url "https://github.com/OWNER/APP/releases/tag/v$VERSION" \ + --changelog CHANGELOG.md \ + --out build/release/appcast.json \ + --channel appimage=build/release/linux/app-linux-x86_64.AppImage \ + --channel windows=build/release/windows/app-windows.zip + +Each --channel becomes {url, sha256, size} in the document; the URL is +base-url/ plus the file's basename. Notes are the version's CHANGELOG.md +section, collapsed to one line and capped at 400 chars. Channels with a +missing file are skipped, an error when the flag is --channel-required. +""" + +import argparse +import datetime +import hashlib +import json +import os +import re +import sys + + +def changelog_notes(path, version, limit=400): + try: + text = open(path, encoding="utf-8").read() + except OSError: + return "" + match = re.search( + r"^## \[" + re.escape(version) + r"\].*?\n(.*?)(?=^## \[|\Z)", + text, re.S | re.M) + if match is None: + return "" + return " ".join(match.group(1).split())[:limit] + + +def channel_entry(base_url, rel_path): + with open(rel_path, "rb") as f: + data = f.read() + return { + "url": base_url.rstrip("/") + "/" + os.path.basename(rel_path), + "sha256": hashlib.sha256(data).hexdigest(), + "size": len(data), + } + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("--version", required=True) + parser.add_argument("--base-url", required=True, + help="release download URL prefix") + parser.add_argument("--notes-url", default="", + help="release page URL (defaults to base-url's tag)") + parser.add_argument("--changelog", default="CHANGELOG.md") + parser.add_argument("--out", required=True) + parser.add_argument("--channel", action="append", default=[], + metavar="NAME=PATH", dest="channels", + help="release artifact for a channel (repeatable)") + parser.add_argument("--channel-required", action="store_true", + help="fail when a named channel has no artifact") + args = parser.parse_args() + + channels = {} + for item in args.channels: + name, _, path = item.partition("=") + if not name or not path: + parser.error("--channel wants NAME=PATH, got %r" % item) + if not os.path.isfile(path): + if args.channel_required: + sys.exit("missing artifact for channel %s: %s" % (name, path)) + print("skipping channel %s (no artifact)" % name) + continue + channels[name] = channel_entry(args.base_url, path) + if not channels: + sys.exit("no channel artifacts found") + + notes_url = args.notes_url + if not notes_url: + # derive ".../releases/download/vX" -> ".../releases/tag/vX" + head, sep, tail = args.base_url.rstrip("/").partition("/download/") + notes_url = head + "/tag/" + tail if sep else head + + appcast = { + "version": args.version, + "date": datetime.date.today().isoformat(), + "notes": changelog_notes(args.changelog, args.version), + "notes_url": notes_url, + "channels": channels, + } + with open(args.out, "w", encoding="utf-8") as f: + json.dump(appcast, f, indent=2) + f.write("\n") + print("wrote %s" % args.out) + print(json.dumps(appcast, indent=2)) + + +if __name__ == "__main__": + main()