Skip to content

armgit / soju

Public Imported from GitHub
0

Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.

Releases move the Homebrew tap with them: scripts/publish-release.sh creates the release, updates the tap and checks the result; CI fails when a pinned engine or support file is gone or the tap is behind (a Homebrew install of 1.14.16 hit 404s on files deleted since) (#157)

Mikek63d038a1552e
diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml
index d097f6007f2..e2ceb3e8742 100644
--- a/.github/workflows/check.yml
+++ b/.github/workflows/check.yml
@@ -16,6 +16,10 @@ jobs:
for script in scripts/*.sh scripts/soju; do bash -n "$script"; done
python3 -m unittest discover -s tests -q
node --test tests/test_steam_login.cjs
+ - name: Released files still resolve, Homebrew installs the newest release
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
+ run: python3 scripts/release-health.py
- name: Purchase link routing
run: |
swiftc app/PurchaseLinks.swift tests/test_purchase_links.swift -o /tmp/soju-purchase-tests
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index f7eb8a582fc..01b1ef34771 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -56,6 +56,16 @@ Pull requests:
Not sure where to start? Issues labelled
[good first issue](https://github.com/BCD1210/soju/labels/good%20first%20issue) are small and self-contained.
+## Releasing (maintainers)
+
+After the pull request is merged: `scripts/build-app.sh` with the Developer ID, `scripts/notarize-app.sh`, then
+`scripts/publish-release.sh <notes-file>`. That one command creates the GitHub release, moves the Homebrew tap
+to it and runs `scripts/release-health.py`. Do not create the release by hand: the tap stays behind.
+
+Engine and support releases (`engine-v*`, `launcher-support-v*`, `steam-support-v*` and the like) are pinned by
+the app versions that shipped with them. Never delete one while a version that names it can still be installed.
+CI runs `scripts/release-health.py`, which fails when a pinned file is gone or the tap is behind the newest release.
+
## Security
Please do not open a public issue for a security problem. See [SECURITY.md](SECURITY.md).
diff --git a/scripts/publish-release.sh b/scripts/publish-release.sh
new file mode 100755
index 00000000000..5d366ced0d9
--- /dev/null
+++ b/scripts/publish-release.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# Publish the notarized build as GitHub release v<VERSION> and move everything
+# that points at "the current version" with it:
+# scripts/publish-release.sh <notes-file>
+# Before: merge to main, scripts/build-app.sh (Developer ID), scripts/notarize-app.sh.
+# Does: gh release create -> Homebrew tap -> scripts/release-health.py.
+set -euo pipefail
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+cd "$ROOT"
+NOTES="${1:?notes file (one bullet per change)}"
+[ -s "$NOTES" ] || { echo "Empty notes file: $NOTES"; exit 64; }
+VERSION=$(cat VERSION)
+REPO="${SOJU_REPO:-BCD1210/soju}"
+ZIP="dist/Soju-$VERSION-macos-arm64.zip"
+[ -f "$ZIP" ] && [ -f "$ZIP.sha256" ] || { echo "Build and notarize first: $ZIP is missing"; exit 1; }
+(cd dist && shasum -a 256 -c "$(basename "$ZIP").sha256" >/dev/null) || { echo "$ZIP does not match its .sha256"; exit 1; }
+xcrun stapler validate dist/Soju.app >/dev/null 2>&1 || { echo "dist/Soju.app is not notarized (scripts/notarize-app.sh)"; exit 1; }
+[ "$(git rev-parse --abbrev-ref HEAD)" = main ] || { echo "Release from main"; exit 1; }
+[ -z "$(git status --porcelain --untracked-files=no)" ] || { echo "Uncommitted changes"; exit 1; }
+git fetch -q origin main
+[ "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)" ] || { echo "main is not what is on GitHub"; exit 1; }
+if gh release view "v$VERSION" -R "$REPO" >/dev/null 2>&1; then
+ echo "Release v$VERSION exists already; continuing with the tap and the checks"
+else
+ gh release create "v$VERSION" "$ZIP" "$ZIP.sha256" -R "$REPO" --target "$(git rev-parse HEAD)" \
+ --title "Soju $VERSION" --notes-file "$NOTES"
+fi
+bash scripts/update-homebrew-tap.sh "$VERSION"
+python3 scripts/release-health.py --wait 120
diff --git a/scripts/release-health.py b/scripts/release-health.py
new file mode 100644
index 00000000000..3838891dc01
--- /dev/null
+++ b/scripts/release-health.py
@@ -0,0 +1,163 @@
+#!/usr/bin/env python3
+"""Checks that what users install still resolves.
+
+ release-health.py [--wait SECONDS] [--grace-hours 3]
+
+1. Every release asset this checkout pins (the engine in install.sh and
+ scripts/update.sh, resources/*.json) answers on GitHub.
+2. The Homebrew tap installs the newest stable release. Behind by a release
+ older than the grace period is a failure (scripts/publish-release.sh moves it).
+3. Every asset pinned by the version the tap installs still answers: `soju install`
+ from Homebrew runs that version's installer, not the newest one.
+
+A pinned engine or support release must stay on GitHub for as long as a version
+that names it can still be installed. Run in CI (.github/workflows/check.yml).
+--wait retries the tap check for that long (GitHub's raw cache lags a push).
+"""
+import argparse
+from datetime import datetime, timedelta, timezone
+import json
+import os
+from pathlib import Path
+import re
+import sys
+import time
+import urllib.error
+import urllib.request
+
+REPO = os.environ.get("SOJU_REPO", "BCD1210/soju")
+TAP = os.environ.get("SOJU_TAP", "BCD1210/homebrew-soju")
+ROOT = Path(__file__).resolve().parents[1]
+APP_TAG = re.compile(r"^v\d+\.\d+\.\d+$")
+RESOURCES = ["launcher-support", "steam-support", "steam-wine", "steam-dxvk", "gptk", "xbox-runtime", "d2r-vr", "didim-store"]
+
+
+def fetch(url, method="GET", token=True):
+ request = urllib.request.Request(url, method=method, headers={"User-Agent": "soju-release-health"})
+ key = os.environ.get("GITHUB_TOKEN")
+ if token and key and url.startswith("https://api.github.com/"):
+ request.add_header("Authorization", "Bearer " + key)
+ return urllib.request.urlopen(request, timeout=30)
+
+
+def engine_urls(script_text):
+ """The engine archive an installer script pins, from its ENGINE_TAG line."""
+ found = re.search(r'^ENGINE_TAG="([^"]+)"', script_text, re.M)
+ return ["https://github.com/%s/releases/download/%s/wine-engine-x86_64.tar.xz" % (REPO, found.group(1))] if found else []
+
+
+def json_urls(text):
+ """Every "url" value in a resources file."""
+ urls = []
+
+ def walk(node):
+ if isinstance(node, dict):
+ for key, value in node.items():
+ if key == "url" and isinstance(value, str):
+ urls.append(value)
+ else:
+ walk(value)
+ elif isinstance(node, list):
+ for value in node:
+ walk(value)
+
+ walk(json.loads(text))
+ return urls
+
+
+def own_release(url):
+ return url.startswith("https://github.com/%s/releases/download/" % REPO)
+
+
+def formula_version(text):
+ found = re.search(r"archive/refs/tags/v(\d+\.\d+\.\d+)\.tar\.gz", text)
+ return found.group(1) if found else ""
+
+
+def newest_stable(releases):
+ stable = [r for r in releases if APP_TAG.match(r.get("tag_name", "")) and not r.get("draft") and not r.get("prerelease")]
+ stable.sort(key=lambda r: [int(n) for n in r["tag_name"][1:].split(".")])
+ return stable[-1] if stable else None
+
+
+def tap_is_late(tap_version, release, now, grace_hours):
+ """Behind the newest release, and that release has been out longer than the grace period."""
+ if not release or tap_version == release["tag_name"][1:]:
+ return False
+ published = datetime.fromisoformat(release["published_at"].replace("Z", "+00:00"))
+ return now - published > timedelta(hours=grace_hours)
+
+
+def missing(urls):
+ gone = []
+ for url in sorted(set(urls)):
+ try:
+ fetch(url, "HEAD").close()
+ except urllib.error.HTTPError as error:
+ gone.append("%s -> HTTP %s" % (url, error.code))
+ except OSError as error:
+ gone.append("%s -> %s" % (url, error))
+ return gone
+
+
+def pinned_here():
+ urls = []
+ for name in ("install.sh", "scripts/update.sh"):
+ urls += engine_urls((ROOT / name).read_text())
+ for path in sorted((ROOT / "resources").glob("*.json")):
+ urls += [u for u in json_urls(path.read_text()) if own_release(u)]
+ return urls
+
+
+def pinned_at(version):
+ raw = "https://raw.githubusercontent.com/%s/v%s/" % (REPO, version)
+ urls = []
+ for name in ("install.sh", "scripts/update.sh"):
+ with fetch(raw + name) as response:
+ urls += engine_urls(response.read().decode())
+ for name in RESOURCES:
+ try:
+ with fetch(raw + "resources/%s.json" % name) as response:
+ urls += [u for u in json_urls(response.read().decode()) if own_release(u)]
+ except urllib.error.HTTPError:
+ pass # that version had no such file
+ return urls
+
+
+def tap_version():
+ with fetch("https://api.github.com/repos/%s/contents/Formula/soju.rb" % TAP) as response:
+ import base64
+ return formula_version(base64.b64decode(json.load(response)["content"]).decode())
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--wait", type=int, default=0)
+ parser.add_argument("--grace-hours", type=float, default=3)
+ args = parser.parse_args()
+ problems = ["Pinned here, gone from GitHub: " + line for line in missing(pinned_here())]
+ with fetch("https://api.github.com/repos/%s/releases?per_page=40" % REPO) as response:
+ newest = newest_stable(json.load(response))
+ deadline = time.time() + args.wait
+ while True:
+ tap = tap_version()
+ if not newest or tap == newest["tag_name"][1:] or time.time() >= deadline:
+ break
+ time.sleep(10)
+ if not tap:
+ problems.append("Could not read the version in %s Formula/soju.rb" % TAP)
+ else:
+ grace = 0 if args.wait else args.grace_hours
+ if tap_is_late(tap, newest, datetime.now(timezone.utc), grace):
+ problems.append("Homebrew installs %s but the newest release is %s: run scripts/update-homebrew-tap.sh %s"
+ % (tap, newest["tag_name"][1:], newest["tag_name"][1:]))
+ problems += ["Homebrew's %s pins a file that is gone: %s" % (tap, line) for line in missing(pinned_at(tap))]
+ for line in problems:
+ print("FAIL " + line)
+ if not problems:
+ print("ok pinned assets answer; Homebrew installs %s (newest release %s)" % (tap, newest["tag_name"][1:] if newest else "none"))
+ return 1 if problems else 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/scripts/update-homebrew-tap.sh b/scripts/update-homebrew-tap.sh
new file mode 100755
index 00000000000..444db46929f
--- /dev/null
+++ b/scripts/update-homebrew-tap.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Point the Homebrew tap (BCD1210/homebrew-soju) at a released version:
+# scripts/update-homebrew-tap.sh [version] (default: VERSION)
+# The formula installs the source of tag v<version>, so the tag must exist on
+# GitHub first. Run by scripts/publish-release.sh; safe to run again.
+set -euo pipefail
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+VERSION="${1:-$(cat "$ROOT/VERSION")}"
+REPO="${SOJU_REPO:-BCD1210/soju}"
+TAP="${SOJU_TAP_REMOTE:[email protected]:BCD1210/homebrew-soju.git}"
+[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Not a version: $VERSION"; exit 64; }
+WORK=$(mktemp -d "${TMPDIR:-/tmp}/soju-tap.XXXXXX")
+trap 'rm -rf "$WORK"' EXIT
+URL="https://github.com/$REPO/archive/refs/tags/v$VERSION.tar.gz"
+curl -fsSL "$URL" -o "$WORK/src.tar.gz" || { echo "Tag v$VERSION is not on GitHub yet: $URL"; exit 1; }
+SHA=$(shasum -a 256 "$WORK/src.tar.gz" | awk '{print $1}')
+# everything the formula installs must be in the tarball
+for f in install.sh scripts docs patches tools third_party app resources VERSION LICENSE NOTICE; do
+ tar tzf "$WORK/src.tar.gz" "soju-$VERSION/$f" >/dev/null 2>&1 || { echo "v$VERSION has no $f, which the formula installs"; exit 1; }
+done
+git clone -q --depth 1 "$TAP" "$WORK/tap"
+F="$WORK/tap/Formula/soju.rb"
+sed -i '' -E \
+ -e "s#(url \"https://github.com/$REPO/archive/refs/tags/v)[0-9.]+(\.tar\.gz\")#\1$VERSION\2#" \
+ -e "s#(sha256 \")[0-9a-f]{64}(\")#\1$SHA\2#" \
+ -e "s#(version \")[0-9.]+(\")#\1$VERSION\2#" "$F"
+grep -q "tags/v$VERSION.tar.gz" "$F" && grep -q "$SHA" "$F" && grep -q "version \"$VERSION\"" "$F" \
+ || { echo "Could not rewrite $F"; exit 1; }
+ruby -c "$F" >/dev/null
+if git -C "$WORK/tap" diff --quiet; then
+ echo "Homebrew tap already at $VERSION"
+else
+ git -C "$WORK/tap" commit -q -am "soju $VERSION"
+ git -C "$WORK/tap" push -q origin HEAD
+ echo "Homebrew tap -> $VERSION"
+fi
diff --git a/tests/test_release_health.py b/tests/test_release_health.py
new file mode 100644
index 00000000000..132bdc05c27
--- /dev/null
+++ b/tests/test_release_health.py
@@ -0,0 +1,59 @@
+import importlib.util
+from datetime import datetime, timezone
+from pathlib import Path
+import unittest
+
+ROOT = Path(__file__).resolve().parents[1]
+spec = importlib.util.spec_from_file_location("release_health", ROOT / "scripts" / "release-health.py")
+health = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(health)
+
+NOW = datetime(2026, 11, 19, 12, 0, tzinfo=timezone.utc)
+
+
+def release(tag, published, **extra):
+ return dict({"tag_name": tag, "published_at": published, "draft": False, "prerelease": False}, **extra)
+
+
+class ReleaseHealth(unittest.TestCase):
+ def test_engine_url_comes_from_the_pinned_tag(self):
+ self.assertEqual(health.engine_urls('REPO="x"\nENGINE_TAG="engine-v1.10"\n'),
+ ["https://github.com/BCD1210/soju/releases/download/engine-v1.10/wine-engine-x86_64.tar.xz"])
+ self.assertEqual(health.engine_urls("echo no engine here"), [])
+
+ def test_json_urls_are_found_at_any_depth(self):
+ text = '{"url": "https://a/1", "parts": [{"url": "https://a/2", "source_url": "https://a/3"}]}'
+ self.assertEqual(health.json_urls(text), ["https://a/1", "https://a/2"])
+
+ def test_only_our_own_release_assets_are_ours_to_keep(self):
+ self.assertTrue(health.own_release("https://github.com/BCD1210/soju/releases/download/steam-support-v9/x.tar.gz"))
+ self.assertFalse(health.own_release("https://github.com/Gcenx/macOS_Wine_builds/releases/download/11.0_1/w.tar.xz"))
+
+ def test_formula_version(self):
+ self.assertEqual(health.formula_version('url "https://github.com/BCD1210/soju/archive/refs/tags/v1.14.31.tar.gz"'), "1.14.31")
+ self.assertEqual(health.formula_version("nothing"), "")
+
+ def test_newest_stable_orders_by_number_and_skips_other_tags(self):
+ found = health.newest_stable([release("v1.14.9", "2026-11-01T00:00:00Z"), release("v1.14.31", "2026-11-18T00:00:00Z"),
+ release("engine-v1.10", "2026-11-18T01:00:00Z"),
+ release("v1.15.0", "2026-11-19T00:00:00Z", prerelease=True)])
+ self.assertEqual(found["tag_name"], "v1.14.31")
+ self.assertIsNone(health.newest_stable([]))
+
+ def test_tap_behind_an_old_release_is_late(self):
+ newest = release("v1.14.31", "2026-11-18T00:00:00Z")
+ self.assertTrue(health.tap_is_late("1.14.16", newest, NOW, 3))
+ self.assertFalse(health.tap_is_late("1.14.31", newest, NOW, 3))
+
+ def test_tap_gets_a_grace_period_right_after_a_release(self):
+ self.assertFalse(health.tap_is_late("1.14.30", release("v1.14.31", "2026-11-19T11:00:00Z"), NOW, 3))
+
+ def test_this_checkout_pins_the_engine_and_the_support_packages(self):
+ urls = health.pinned_here()
+ self.assertTrue(any("/wine-engine-x86_64.tar.xz" in u for u in urls))
+ self.assertTrue(any("soju-steam-support-" in u for u in urls))
+ self.assertTrue(all(health.own_release(u) for u in urls))
+
+
+if __name__ == "__main__":
+ unittest.main()