mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
* fix(ci): a test build's files outlive the catalog that names them, and a merged PR's build lasts until Preview carries it - A new push's PR release keeps the previous push's files until the catalog names the new ones, then five minutes more, so a download started from the old catalog still finds its APK. The app also reloads the catalog and retries once when a test build's download fails. - Closing a PR without merging still deletes its test build. A merged PR's build stays, and stays listed, until the newest Preview build was built from a main holding the merge, or three days pass (docs-only merges build no Preview). Main's build, the PR cleanup and the sweep share one script for this. * fix(ci): name the current push's APK in the catalog and prune nothing it still names * fix(ci): only a Preview with every APK carries a merge or is offered * fix(ci): publish no preview while none has every APK * test(ci): build_catalog publishes no preview while its APKs are uploading
239 lines
11 KiB
Python
239 lines
11 KiB
Python
import base64
|
|
import unittest
|
|
|
|
from tools.release.update_catalog import (
|
|
Cache,
|
|
asset_for_suffix,
|
|
build_catalog,
|
|
complete_apks,
|
|
newest_complete,
|
|
merged_pr,
|
|
ci_description,
|
|
parse_gradle,
|
|
parse_variants,
|
|
published_millis,
|
|
preview_history_entry,
|
|
recent_previews,
|
|
release_body_value,
|
|
stable_app_release,
|
|
unique_previews,
|
|
)
|
|
|
|
|
|
class UpdateCatalogTest(unittest.TestCase):
|
|
def test_gradle_metadata(self):
|
|
code, name = parse_gradle("""android {
|
|
defaultConfig {
|
|
versionCode 12
|
|
versionName "0.3.1"
|
|
}
|
|
}
|
|
""")
|
|
self.assertEqual(12, code)
|
|
self.assertEqual("0.3.1", name)
|
|
|
|
def test_variants(self):
|
|
rows = parse_variants("""
|
|
# name package suffix
|
|
standard com.droiddeck.launcher -
|
|
pubg com.tencent.ig -pubg
|
|
""")
|
|
self.assertEqual(
|
|
[("com.droiddeck.launcher", ""), ("com.tencent.ig", "-pubg")],
|
|
rows,
|
|
)
|
|
|
|
def test_standard_asset_does_not_take_a_variant(self):
|
|
assets = [
|
|
{
|
|
"name": "DroidDeck-main-deadbee-pubg.apk",
|
|
"size": 10,
|
|
"digest": "sha256:" + "a" * 64,
|
|
"browser_download_url": "https://example/pubg",
|
|
},
|
|
{
|
|
"name": "DroidDeck-main-deadbee.apk",
|
|
"size": 11,
|
|
"digest": "sha256:" + "b" * 64,
|
|
"browser_download_url": "https://example/standard",
|
|
},
|
|
]
|
|
standard = asset_for_suffix(assets, "", ["", "-pubg"])
|
|
pubg = asset_for_suffix(assets, "-pubg", ["", "-pubg"])
|
|
self.assertEqual("DroidDeck-main-deadbee.apk", standard["name"])
|
|
self.assertEqual("DroidDeck-main-deadbee-pubg.apk", pubg["name"])
|
|
|
|
def test_the_apk_named_for_the_build_commit_wins_over_a_previous_push(self):
|
|
def apk(name, digit):
|
|
return {"name": name, "size": 1, "digest": "sha256:" + digit * 64, "browser_download_url": "https://example/" + name}
|
|
assets = [apk("DroidDeck-PR.7-1111111.apk", "a"), apk("DroidDeck-PR.7-2222222.apk", "b"),
|
|
apk("DroidDeck-PR.7-1111111-pubg.apk", "c"), apk("DroidDeck-PR.7-2222222-pubg.apk", "d")]
|
|
suffixes = ["", "-pubg"]
|
|
self.assertEqual("DroidDeck-PR.7-2222222.apk", asset_for_suffix(assets, "", suffixes, "2222222abc")["name"])
|
|
self.assertEqual("DroidDeck-PR.7-2222222-pubg.apk", asset_for_suffix(assets, "-pubg", suffixes, "2222222abc")["name"])
|
|
self.assertEqual("DroidDeck-PR.7-1111111.apk", asset_for_suffix(assets, "", suffixes)["name"])
|
|
|
|
def test_a_preview_counts_only_with_every_package_and_digest(self):
|
|
variants = [("com.droiddeck.launcher", ""), ("com.tencent.ig", "-pubg")]
|
|
good = {"sha256": "a" * 64, "signerSha256": "b" * 64}
|
|
self.assertTrue(complete_apks({"apks": {"com.droiddeck.launcher": good, "com.tencent.ig": good}}, variants))
|
|
self.assertFalse(complete_apks({"apks": {"com.droiddeck.launcher": good}}, variants))
|
|
self.assertFalse(complete_apks({"apks": {}}, variants))
|
|
self.assertFalse(complete_apks({"apks": {"com.droiddeck.launcher": good, "com.tencent.ig": {"sha256": "x"}}}, variants))
|
|
|
|
def test_no_preview_is_offered_until_one_has_every_apk(self):
|
|
variants = [("com.droiddeck.launcher", "")]
|
|
good = {"com.droiddeck.launcher": {"sha256": "a" * 64, "signerSha256": "b" * 64}}
|
|
uploading = {"commit": "2" * 40, "apks": {}}
|
|
done = {"commit": "1" * 40, "apks": good}
|
|
self.assertIsNone(newest_complete([uploading], variants))
|
|
self.assertIsNone(newest_complete([], variants))
|
|
self.assertIs(done, newest_complete([uploading, done], variants))
|
|
|
|
def test_the_catalog_publishes_no_preview_while_its_apks_are_uploading(self):
|
|
commit = "c" * 40
|
|
files = {
|
|
"app/build.gradle": " versionCode 19\n versionName \"0.7.1\"\n",
|
|
"tools/release/variants.txt": "standard com.droiddeck.launcher -\n",
|
|
"keystore/release-signer.sha256": "b" * 64 + "\n",
|
|
}
|
|
|
|
class FakeGitHub:
|
|
def get_all(self, path, limit=1000):
|
|
if "DroidDeck-CI/releases" in path:
|
|
return [{
|
|
"tag_name": f"main-{commit[:7]}", "prerelease": True, "assets": [],
|
|
"published_at": "2026-11-14T10:00:00Z",
|
|
"body": f"**Merged to main** - [PR #5](u): fix: x\n\nCommit: {commit}\nVersionCode: 19\n",
|
|
}]
|
|
return []
|
|
|
|
def get(self, path):
|
|
for name, text in files.items():
|
|
if f"/contents/{name.replace('/', '%2F')}?" in path:
|
|
return {"encoding": "base64", "content": base64.b64encode(text.encode()).decode()}
|
|
if "/commits/" in path:
|
|
return {"author": {"login": "dev"}, "commit": {"committer": {"date": "2026-11-14T09:59:00Z"}}}
|
|
raise AssertionError(path)
|
|
|
|
gh = FakeGitHub()
|
|
catalog = build_catalog(gh, gh, "Droid-Deck/DroidDeck", "Droid-Deck/DroidDeck-CI")
|
|
self.assertIsNone(catalog["preview"])
|
|
self.assertEqual([commit], [p["commit"] for p in catalog["previews"]])
|
|
|
|
def test_ci_description(self):
|
|
title, summary = ci_description(
|
|
{
|
|
"tag_name": "main-deadbee",
|
|
"name": "main deadbee",
|
|
"body": (
|
|
"**Merged to main** - [PR #9](https://github.com/Droid-Deck/DroidDeck/pull/9): "
|
|
"fix: keep Steam alive (merged 2026-09-30)\n\n"
|
|
"Steam no longer **exits** on resume.\n\n"
|
|
"Signed build of https://example"
|
|
),
|
|
}
|
|
)
|
|
self.assertEqual("fix: keep Steam alive", title)
|
|
self.assertEqual("Steam no longer exits on resume.", summary)
|
|
|
|
def test_release_body_metadata(self):
|
|
tick = chr(96)
|
|
body = f"Commit: {tick}abcdef1234567{tick}\nBase: 1234567\nVersionCode: 42\n"
|
|
self.assertEqual("abcdef1234567", release_body_value(body, "Commit"))
|
|
self.assertEqual("1234567", release_body_value(body, "Base"))
|
|
self.assertEqual("42", release_body_value(body, "VersionCode"))
|
|
|
|
def test_republished_pr_uses_updated_time_but_other_channels_use_publish_time(self):
|
|
release = {
|
|
"published_at": "2026-09-30T10:00:00Z",
|
|
"updated_at": "2026-09-30T12:00:00Z",
|
|
}
|
|
self.assertLess(
|
|
published_millis(release),
|
|
published_millis(release, prefer_updated=True),
|
|
)
|
|
|
|
def test_preview_history_keeps_only_complete_signed_main_releases(self):
|
|
variants = [("com.droiddeck.launcher", ""), ("com.example.variant", "-variant")]
|
|
commit = "a" * 40
|
|
entry = {
|
|
"commit": commit,
|
|
"title": "Fix Steam resume",
|
|
"summary": "Steam stays open after resuming.",
|
|
"publishedAt": 123,
|
|
"apks": {
|
|
package: {"sha256": "a" * 64, "signerSha256": "b" * 64}
|
|
for package, _ in variants
|
|
},
|
|
}
|
|
release = {"tag_name": "main-aaaaaaa", "draft": False, "prerelease": True}
|
|
self.assertEqual(
|
|
{
|
|
"commit": commit,
|
|
"title": "Fix Steam resume",
|
|
"summary": "Steam stays open after resuming.",
|
|
"publishedAt": 123,
|
|
},
|
|
preview_history_entry(release, entry, variants),
|
|
)
|
|
|
|
for invalid_release in (
|
|
{**release, "draft": True},
|
|
{**release, "prerelease": False},
|
|
{**release, "tag_name": "pr-42"},
|
|
):
|
|
self.assertIsNone(preview_history_entry(invalid_release, entry, variants))
|
|
self.assertIsNone(preview_history_entry(release, {**entry, "commit": "a" * 12}, variants))
|
|
self.assertIsNone(preview_history_entry(release, {**entry, "apks": {"com.droiddeck.launcher": {}}}, variants))
|
|
unsigned = {**entry, "apks": {package: {"sha256": "a" * 64} for package, _ in variants}}
|
|
self.assertIsNone(preview_history_entry(release, unsigned, variants))
|
|
|
|
def test_preview_history_is_newest_first_deduplicated_and_limited(self):
|
|
entries = [
|
|
{"commit": f"{i:040x}", "title": str(i), "summary": "", "publishedAt": i}
|
|
for i in range(12)
|
|
]
|
|
entries.append({**entries[-1], "title": "duplicate", "publishedAt": 99})
|
|
recent = recent_previews(entries)
|
|
self.assertEqual(10, len(recent))
|
|
self.assertEqual("duplicate", recent[0]["title"])
|
|
self.assertEqual("000000000000000000000000000000000000000a", recent[1]["commit"])
|
|
self.assertEqual(1, len([item for item in recent if item["commit"].endswith("000b")]))
|
|
|
|
def test_stable_is_the_newest_app_release_not_github_latest(self):
|
|
def release(tag, at, *assets, **flags):
|
|
return {"tag_name": tag, "published_at": at, "assets": [{"name": a} for a in assets], **flags}
|
|
releases = [
|
|
release("gamescope-3.16.29-p5", "2026-10-01T18:53:08Z", "gamescope.tzst"),
|
|
release("0.3.0", "2026-09-30T00:00:00Z", "DroidDeck-0.3.0.apk", prerelease=True),
|
|
release("0.2.1", "2026-09-29T00:00:00Z", "DroidDeck-0.2.1.apk", draft=True),
|
|
release("0.2.0", "2026-09-28T03:20:01Z", "DroidDeck-0.2.0-pubg.apk", "DroidDeck-0.2.0.apk"),
|
|
release("0.1.6", "2026-09-01T00:00:00Z", "DroidDeck-0.1.6.apk"),
|
|
]
|
|
self.assertEqual("0.2.0", stable_app_release(releases)["tag_name"])
|
|
self.assertIsNone(stable_app_release(releases[:1]))
|
|
|
|
def test_merged_pr_comes_from_the_first_paragraph(self):
|
|
body = "**Merged to main** - [PR #2602](https://github.com/Droid-Deck/DroidDeck/pull/2602): fix: x\n\nSee [PR #9](u)."
|
|
self.assertEqual(2602, merged_pr({"body": body}))
|
|
self.assertEqual(0, merged_pr({"body": "**Pushed to main** without a PR - fix: x"}))
|
|
|
|
def test_previews_follow_commit_order_not_publish_order(self):
|
|
older = {"commit": "a" * 40, "committedAt": 100, "publishedAt": 900}
|
|
newer = {"commit": "b" * 40, "committedAt": 200, "publishedAt": 300}
|
|
again = {**newer, "publishedAt": 50}
|
|
self.assertEqual([newer, older], unique_previews([older, again, newer]))
|
|
|
|
def test_cache_reuses_commit_facts_from_the_last_catalog(self):
|
|
class NoNetwork:
|
|
def get(self, path):
|
|
raise AssertionError(path)
|
|
|
|
cache = Cache({"previews": [{"commit": "A" * 40, "author": "dev", "committedAt": 5}]})
|
|
self.assertEqual({"author": "dev", "committedAt": 5}, cache.commit(NoNetwork(), "o/r", "a" * 40))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|