mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-23 06:46:02 +00:00
fix(ci): no 404 window when a test build is replaced; merged PRs keep their build until Preview has it (#2635)
* 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
This commit is contained in:
1 parent
059711cfe1
commit
6f7d7f827f
9 files changed
+336
-72
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import unittest
|
||||
|
||||
from tools.release.update_catalog import ApiError, in_preview, iso_millis, keeps_test_build
|
||||
from tools.release.retire_test_builds import retired
|
||||
|
||||
MERGED = "2026-11-14T20:00:00Z"
|
||||
NOW = iso_millis(MERGED) + 3600_000
|
||||
|
||||
|
||||
class FakeSource:
|
||||
def __init__(self, status=None):
|
||||
self.status = status
|
||||
self.asked = []
|
||||
|
||||
def get(self, path):
|
||||
self.asked.append(path)
|
||||
if self.status is None:
|
||||
raise ApiError(404, "no")
|
||||
return {"status": self.status}
|
||||
|
||||
|
||||
def pull(state="closed", merged_at=MERGED, draft=False, base="main"):
|
||||
return {"state": state, "merged_at": merged_at, "merge_commit_sha": "a" * 40, "draft": draft, "base": {"ref": base}}
|
||||
|
||||
|
||||
class RetireTestBuildsTest(unittest.TestCase):
|
||||
def test_an_open_pr_keeps_its_build(self):
|
||||
self.assertFalse(retired(pull(state="open", merged_at=None), FakeSource("ahead"), "o/r", "b" * 40))
|
||||
|
||||
def test_a_closed_unmerged_pr_loses_it_at_once(self):
|
||||
self.assertTrue(retired(pull(merged_at=None), FakeSource(), "o/r", None))
|
||||
|
||||
def test_a_merged_pr_keeps_it_until_a_preview_carries_the_merge(self):
|
||||
self.assertFalse(in_preview(FakeSource("behind"), "o/r", pull(), "b" * 40, NOW))
|
||||
self.assertFalse(in_preview(FakeSource(), "o/r", pull(), "b" * 40, NOW))
|
||||
self.assertFalse(in_preview(FakeSource("ahead"), "o/r", pull(), None, NOW))
|
||||
self.assertTrue(in_preview(FakeSource("ahead"), "o/r", pull(), "b" * 40, NOW))
|
||||
self.assertTrue(in_preview(FakeSource("identical"), "o/r", pull(), "a" * 40, NOW))
|
||||
|
||||
def test_a_merge_no_preview_ever_carries_is_let_go_after_the_grace(self):
|
||||
self.assertTrue(in_preview(FakeSource(), "o/r", pull(), None, NOW + 4 * 86_400_000))
|
||||
|
||||
def test_the_catalog_lists_open_and_merged_main_prs(self):
|
||||
self.assertTrue(keeps_test_build(pull(state="open", merged_at=None)))
|
||||
self.assertTrue(keeps_test_build(pull()))
|
||||
self.assertFalse(keeps_test_build(pull(merged_at=None)))
|
||||
self.assertFalse(keeps_test_build(pull(draft=True)))
|
||||
self.assertFalse(keeps_test_build(pull(base="release")))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,8 +1,12 @@
|
||||
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,
|
||||
@@ -59,6 +63,64 @@ pubg com.tencent.ig -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(
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user