mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +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
@@ -992,3 +992,35 @@ jobs:
|
||||
if: ${{ always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && needs.announce.result != 'skipped' }}
|
||||
uses: ./.github/workflows/update-catalog.yml
|
||||
secrets: inherit
|
||||
|
||||
retire-tests:
|
||||
needs: catalog
|
||||
if: ${{ always() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && needs.catalog.result == 'success' }}
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.sha }}
|
||||
persist-credentials: false
|
||||
- uses: actions/create-github-app-token@v2
|
||||
id: ci-token
|
||||
with:
|
||||
app-id: ${{ vars.DROIDDECK_CI_APP_ID }}
|
||||
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
|
||||
owner: Droid-Deck
|
||||
repositories: DroidDeck-CI
|
||||
- name: Delete the test builds this Preview build replaces
|
||||
env:
|
||||
SOURCE_GITHUB_TOKEN: ${{ github.token }}
|
||||
CI_GITHUB_TOKEN: ${{ steps.ci-token.outputs.token }}
|
||||
run: python3 tools/release/retire_test_builds.py
|
||||
|
||||
catalog-after-retire:
|
||||
needs: retire-tests
|
||||
if: ${{ always() && needs.retire-tests.result == 'success' }}
|
||||
uses: ./.github/workflows/update-catalog.yml
|
||||
secrets: inherit
|
||||
@@ -40,36 +40,19 @@ jobs:
|
||||
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
|
||||
owner: Droid-Deck
|
||||
repositories: DroidDeck-CI
|
||||
- name: Delete the test build
|
||||
if: ${{ steps.state.outputs.closed == 'true' }}
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
retry() {
|
||||
for attempt in 1 2 3 4; do
|
||||
"$@" && return 0
|
||||
[ "$attempt" = 4 ] || sleep $((attempt * 20))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
existing=$(retry gh api --paginate "repos/Droid-Deck/DroidDeck-CI/releases?per_page=100" --jq '.[].tag_name')
|
||||
found=0
|
||||
for tag in "pr-$PR_NUMBER" "pr-$PR_NUMBER.0"; do
|
||||
if grep -qxF "$tag" <<<"$existing"; then
|
||||
retry gh release delete "$tag" -R Droid-Deck/DroidDeck-CI --yes --cleanup-tag
|
||||
echo "Deleted $tag"
|
||||
found=1
|
||||
fi
|
||||
done
|
||||
[ "$found" = 1 ] || echo "No test build for PR #$PR_NUMBER"
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
if: ${{ steps.state.outputs.closed == 'true' }}
|
||||
with:
|
||||
ref: main
|
||||
persist-credentials: false
|
||||
- name: Delete the test build unless main still needs it
|
||||
if: ${{ steps.state.outputs.closed == 'true' }}
|
||||
env:
|
||||
SOURCE_GITHUB_TOKEN: ${{ github.token }}
|
||||
CI_GITHUB_TOKEN: ${{ steps.ci-token.outputs.token }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
# A merged PR's build stays until a Preview build carries the merge; build.yml and the sweep remove it then.
|
||||
run: python3 tools/release/retire_test_builds.py --pr "$PR_NUMBER"
|
||||
- name: Retire the Discord PR announcement
|
||||
if: ${{ steps.state.outputs.closed == 'true' }}
|
||||
env:
|
||||
|
||||
@@ -226,6 +226,8 @@ jobs:
|
||||
publish:
|
||||
needs: [authorize, sign]
|
||||
runs-on: ubuntu-24.04
|
||||
outputs:
|
||||
keep: ${{ steps.publish.outputs.keep }}
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
@@ -322,12 +324,8 @@ jobs:
|
||||
cp pr-packs/* signed/ 2>/dev/null || true
|
||||
gh release upload "$tag" signed/* -R "$repo" --clobber
|
||||
gh release edit "$tag" -R "$repo" --title "PR #$PR_NUMBER" --notes "$notes" --prerelease
|
||||
keep=$(cd signed && ls | jq -R . | jq -sc .)
|
||||
gh api "repos/$repo/releases/tags/$tag" |
|
||||
jq -r --argjson keep "$keep" '.assets[] | select(.name as $n | $keep | index($n) | not) | .id' |
|
||||
while IFS= read -r id; do
|
||||
gh api --method DELETE "repos/$repo/releases/assets/$id" >/dev/null
|
||||
done
|
||||
# The previous push's files stay until the catalog names these (the prune job), so a download started from the old catalog still finds its APK.
|
||||
echo "keep=$(cd signed && ls | jq -R . | jq -sc .)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
published=$(gh release view "$tag" -R "$repo" --json tagName,assets)
|
||||
jq -e --arg tag "$tag" '.tagName == $tag and (.assets | length) > 0' <<<"$published" >/dev/null
|
||||
@@ -417,3 +415,41 @@ jobs:
|
||||
if: ${{ always() && needs.publish.result != 'skipped' }}
|
||||
uses: ./.github/workflows/update-catalog.yml
|
||||
secrets: inherit
|
||||
|
||||
prune:
|
||||
needs: [authorize, publish, catalog]
|
||||
if: ${{ always() && needs.publish.result == 'success' && needs.catalog.result == 'success' }}
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/create-github-app-token@v2
|
||||
id: ci-token
|
||||
with:
|
||||
app-id: ${{ vars.DROIDDECK_CI_APP_ID }}
|
||||
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
|
||||
owner: Droid-Deck
|
||||
repositories: DroidDeck-CI
|
||||
- name: Remove the previous push's files
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
|
||||
PR_NUMBER: ${{ needs.authorize.outputs.pr_number }}
|
||||
KEEP: ${{ needs.publish.outputs.keep }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
repo=Droid-Deck/DroidDeck-CI
|
||||
tag="pr-$PR_NUMBER"
|
||||
# An app that read the catalog just before it changed may still be starting that download.
|
||||
sleep 300
|
||||
# Delete nothing the published catalog still names.
|
||||
named=$(gh api -H "Accept: application/vnd.github.raw+json" "repos/$repo/contents/catalog.json?ref=main" |
|
||||
jq -c --argjson pr "$PR_NUMBER" '[.tests[] | select(.pr == $pr) | .apks[].name]')
|
||||
stale=$(jq -nr --argjson named "$named" --argjson keep "$KEEP" '$named - $keep | join(" ")')
|
||||
if [ -n "$stale" ]; then
|
||||
echo "::warning::The catalog still names $stale; keeping every file of $tag"
|
||||
exit 0
|
||||
fi
|
||||
gh api "repos/$repo/releases/tags/$tag" |
|
||||
jq -r --argjson keep "$KEEP" '.assets[] | select(.name as $n | $keep | index($n) | not) | .id' |
|
||||
while IFS= read -r id; do
|
||||
gh api --method DELETE "repos/$repo/releases/assets/$id" >/dev/null
|
||||
done
|
||||
@@ -26,35 +26,15 @@ jobs:
|
||||
private-key: ${{ secrets.DROIDDECK_CI_APP_KEY }}
|
||||
owner: Droid-Deck
|
||||
repositories: DroidDeck-CI
|
||||
- name: Delete test builds whose PR is no longer open
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: main
|
||||
persist-credentials: false
|
||||
- name: Delete test builds of closed PRs, and of merged PRs a Preview build carries
|
||||
env:
|
||||
CI_TOKEN: ${{ steps.ci-token.outputs.token }}
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
retry() {
|
||||
for attempt in 1 2 3 4; do
|
||||
"$@" && return 0
|
||||
[ "$attempt" = 4 ] || sleep $((attempt * 20))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
tags=$(GH_TOKEN="$CI_TOKEN" retry gh api --paginate "repos/Droid-Deck/DroidDeck-CI/releases?per_page=100" --jq '.[].tag_name' |
|
||||
grep -E '^pr-[0-9]+(\.0)?$' || true)
|
||||
failed=0
|
||||
for tag in $tags; do
|
||||
number=${tag#pr-}
|
||||
number=${number%.0}
|
||||
state=$(retry gh api "repos/$GITHUB_REPOSITORY/pulls/$number" --jq .state) || { failed=1; continue; }
|
||||
if [ "$state" != open ]; then
|
||||
if GH_TOKEN="$CI_TOKEN" retry gh release delete "$tag" -R Droid-Deck/DroidDeck-CI --yes --cleanup-tag; then
|
||||
echo "Deleted $tag (PR #$number is $state)"
|
||||
else
|
||||
failed=1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
exit "$failed"
|
||||
SOURCE_GITHUB_TOKEN: ${{ github.token }}
|
||||
CI_GITHUB_TOKEN: ${{ steps.ci-token.outputs.token }}
|
||||
run: python3 tools/release/retire_test_builds.py
|
||||
|
||||
catalog:
|
||||
needs: sweep
|
||||
|
||||
@@ -96,7 +96,17 @@ internal class UpdatesMenu(private val activity: Activity, private val ui: Handl
|
||||
percent = 0
|
||||
Thread({
|
||||
val result = runCatching {
|
||||
val file = SelfInstaller.download(activity, apk) { pct -> ui.post { percent = pct } }
|
||||
val file = try {
|
||||
SelfInstaller.download(activity, apk) { pct -> ui.post { percent = pct } }
|
||||
} catch (e: java.io.IOException) {
|
||||
// Each push replaces a test build's APK, so a list read before the push names a file that is gone.
|
||||
if (r.pr <= 0) throw e
|
||||
val fresh = runCatching { AppUpdates.refresh(activity) }.getOrNull() ?: throw e
|
||||
ui.post { catalog = fresh }
|
||||
val newer = fresh.tests.firstOrNull { it.tag == r.tag }?.apk?.takeIf { it.url != apk.url } ?: throw e
|
||||
ui.post { percent = 0 }
|
||||
SelfInstaller.download(activity, newer) { pct -> ui.post { percent = pct } }
|
||||
}
|
||||
ui.post { stage = activity.getString(R.string.upd_stage_installing); percent = -1 }
|
||||
SelfInstaller.install(activity, file) { id -> session = id }
|
||||
}
|
||||
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Deletes test builds nobody can still need: a closed PR's at once, a merged PR's once a Preview build carries the merge."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from update_catalog import ApiError, GitHub, current_file, in_preview, previous_catalog, q # noqa: E402
|
||||
|
||||
TEST_TAG = re.compile(r"^pr-([1-9][0-9]*)(\.0)?$")
|
||||
|
||||
|
||||
def retired(pull: dict, source: GitHub, repo: str, preview_commit: str | None) -> bool:
|
||||
if pull.get("state") == "open":
|
||||
return False
|
||||
if not pull.get("merged_at"):
|
||||
return True
|
||||
return in_preview(source, repo, pull, preview_commit)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--source-repo", default=os.environ.get("GITHUB_REPOSITORY", "Droid-Deck/DroidDeck"))
|
||||
parser.add_argument("--ci-repo", default="Droid-Deck/DroidDeck-CI")
|
||||
parser.add_argument("--pr", type=int, help="only this PR's test build")
|
||||
args = parser.parse_args()
|
||||
source = GitHub(os.environ.get("SOURCE_GITHUB_TOKEN", ""))
|
||||
ci = GitHub(os.environ["CI_GITHUB_TOKEN"])
|
||||
catalog = previous_catalog(current_file(ci, args.ci_repo, "catalog.json")) or {}
|
||||
preview_commit = (catalog.get("preview") or {}).get("commit")
|
||||
failed = False
|
||||
for release in ci.get_all(f"/repos/{args.ci_repo}/releases"):
|
||||
tag = release.get("tag_name") or ""
|
||||
match = TEST_TAG.fullmatch(tag)
|
||||
if not match or (args.pr and int(match.group(1)) != args.pr):
|
||||
continue
|
||||
number = int(match.group(1))
|
||||
try:
|
||||
pull = source.get(f"/repos/{args.source_repo}/pulls/{number}")
|
||||
if not retired(pull, source, args.source_repo, preview_commit):
|
||||
print(f"Keeping {tag}: PR #{number} is {'open' if pull.get('state') == 'open' else 'merged, not yet in a Preview build'}")
|
||||
continue
|
||||
ci.request("DELETE", f"/repos/{args.ci_repo}/releases/{release['id']}")
|
||||
try:
|
||||
ci.request("DELETE", f"/repos/{args.ci_repo}/git/refs/tags/{q(tag)}")
|
||||
except ApiError as e:
|
||||
if e.status not in (404, 422):
|
||||
raise
|
||||
print(f"Deleted {tag}")
|
||||
except ApiError as e:
|
||||
print(f"{tag}: {e}", file=sys.stderr)
|
||||
failed = True
|
||||
return 1 if failed else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -184,8 +184,12 @@ def source_meta(source: GitHub, repo: str, ref: str):
|
||||
return code, version, variants, signer
|
||||
|
||||
|
||||
def asset_for_suffix(assets: list[dict], suffix: str, all_suffixes: list[str]):
|
||||
def asset_for_suffix(assets: list[dict], suffix: str, all_suffixes: list[str], commit: str = ""):
|
||||
others = [s for s in all_suffixes if s and s != suffix]
|
||||
# A test build's release briefly holds the previous push's APKs too; the one named for this commit wins.
|
||||
current = f"-{commit[:7].lower()}{suffix}.apk" if len(commit) >= 7 else None
|
||||
if current:
|
||||
assets = sorted(assets, key=lambda a: not (a.get("name") or "").lower().endswith(current))
|
||||
for asset in assets:
|
||||
name = asset.get("name", "")
|
||||
if not name.endswith(f"{suffix}.apk"):
|
||||
@@ -220,7 +224,7 @@ def release_entry(
|
||||
suffixes = [suffix for _, suffix in variants]
|
||||
apks = {}
|
||||
for package, suffix in variants:
|
||||
asset = asset_for_suffix(release.get("assets") or [], suffix, suffixes)
|
||||
asset = asset_for_suffix(release.get("assets") or [], suffix, suffixes, commit)
|
||||
if not asset:
|
||||
continue
|
||||
asset.update(
|
||||
@@ -246,24 +250,30 @@ def release_entry(
|
||||
}
|
||||
|
||||
|
||||
def complete_apks(preview: dict, variants: list[tuple[str, str]]) -> bool:
|
||||
apks = preview.get("apks") or {}
|
||||
return set(apks) == {package for package, _ in variants} and all(
|
||||
SHA256.fullmatch((apk.get("sha256") or "").lower()) and SHA256.fullmatch((apk.get("signerSha256") or "").lower())
|
||||
for apk in apks.values()
|
||||
)
|
||||
|
||||
|
||||
def newest_complete(ordered: list[dict], variants: list[tuple[str, str]]) -> dict | None:
|
||||
"""The Preview to offer and to judge merges by: the newest one whose APKs have all been uploaded."""
|
||||
return next((p for p in ordered if complete_apks(p, variants)), None)
|
||||
|
||||
|
||||
def preview_history_entry(release: dict, preview: dict, variants: list[tuple[str, str]]):
|
||||
tag = release.get("tag_name") or ""
|
||||
tag_match = MAIN_TAG.fullmatch(tag)
|
||||
commit = (preview.get("commit") or "").lower()
|
||||
expected_packages = {package for package, _ in variants}
|
||||
apks = preview.get("apks") or {}
|
||||
if (
|
||||
release.get("draft")
|
||||
or not release.get("prerelease")
|
||||
or not tag_match
|
||||
or not re.fullmatch(r"[0-9a-f]{40}", commit)
|
||||
or not commit.startswith(tag_match.group(1))
|
||||
or set(apks) != expected_packages
|
||||
or any(
|
||||
not SHA256.fullmatch((apk.get("sha256") or "").lower())
|
||||
or not SHA256.fullmatch((apk.get("signerSha256") or "").lower())
|
||||
for apk in apks.values()
|
||||
)
|
||||
or not complete_apks(preview, variants)
|
||||
):
|
||||
return None
|
||||
return {
|
||||
@@ -341,6 +351,38 @@ class Cache:
|
||||
return self.commits[sha]
|
||||
|
||||
|
||||
MERGED_GRACE_DAYS = 3
|
||||
|
||||
|
||||
def in_preview(source: GitHub, repo: str, pull: dict, preview_commit: str | None, now_millis: int | None = None) -> bool:
|
||||
"""Whether the newest Preview build was built from a main that already holds the PR's merge.
|
||||
|
||||
A merge that main's build skips (documentation only) never reaches a Preview build, so after
|
||||
MERGED_GRACE_DAYS it counts as carried anyway.
|
||||
"""
|
||||
merge = pull.get("merge_commit_sha") or ""
|
||||
merged_at = iso_millis(pull.get("merged_at"))
|
||||
if not merged_at or not merge:
|
||||
return False
|
||||
now = now_millis if now_millis is not None else int(time.time() * 1000)
|
||||
if now - merged_at > MERGED_GRACE_DAYS * 86_400_000:
|
||||
return True
|
||||
if not preview_commit:
|
||||
return False
|
||||
try:
|
||||
status = source.get(f"/repos/{repo}/compare/{q(merge)}...{q(preview_commit)}").get("status")
|
||||
except ApiError:
|
||||
return False
|
||||
return status in ("ahead", "identical")
|
||||
|
||||
|
||||
def keeps_test_build(pull: dict) -> bool:
|
||||
"""An open PR keeps its test build; a merged one keeps it until a Preview build carries the merge."""
|
||||
if pull.get("draft") or (pull.get("base") or {}).get("ref") != "main":
|
||||
return False
|
||||
return pull.get("state") == "open" or bool(pull.get("merged_at"))
|
||||
|
||||
|
||||
def unique_previews(previews: list[dict]) -> list[dict]:
|
||||
ordered = sorted(previews, key=lambda r: (r.get("committedAt") or r["publishedAt"], r["publishedAt"]), reverse=True)
|
||||
result = []
|
||||
@@ -381,6 +423,7 @@ def build_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str, pr
|
||||
previews = []
|
||||
preview_history = []
|
||||
tests = []
|
||||
merged_pulls: dict[int, dict | None] = {}
|
||||
for release in releases:
|
||||
if release.get("draft"):
|
||||
continue
|
||||
@@ -421,7 +464,7 @@ def build_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str, pr
|
||||
pull = source.get(f"/repos/{source_repo}/pulls/{pr}")
|
||||
except ApiError:
|
||||
continue
|
||||
if pull.get("state") != "open" or pull.get("draft") or pull.get("base", {}).get("ref") != "main":
|
||||
if not keeps_test_build(pull):
|
||||
continue
|
||||
commit = release_body_value(body, "Commit")
|
||||
if not commit or not re.fullmatch(r"[0-9a-f]{7,40}", commit):
|
||||
@@ -443,6 +486,7 @@ def build_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str, pr
|
||||
except (ApiError, KeyError):
|
||||
pass
|
||||
title, summary = ci_description(release)
|
||||
merged_pulls[pr] = pull if pull.get("state") != "open" else None
|
||||
tests.append(
|
||||
release_entry(
|
||||
release,
|
||||
@@ -468,6 +512,9 @@ def build_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str, pr
|
||||
)
|
||||
|
||||
ordered = unique_previews(previews)
|
||||
usable = newest_complete(ordered, main_variants)
|
||||
newest = usable["commit"] if usable else None
|
||||
tests = [t for t in tests if not (merged_pulls.get(t["pr"]) and in_preview(source, source_repo, merged_pulls[t["pr"]], newest))]
|
||||
tests.sort(key=lambda r: r["publishedAt"], reverse=True)
|
||||
return {
|
||||
"schema": 1,
|
||||
@@ -476,7 +523,7 @@ def build_catalog(source: GitHub, ci: GitHub, source_repo: str, ci_repo: str, pr
|
||||
"generatedAt": int(time.time() * 1000),
|
||||
"mainVersionCode": main_code,
|
||||
"stable": stable,
|
||||
"preview": ordered[0] if ordered else None,
|
||||
"preview": usable,
|
||||
"recentPreviews": recent_previews(preview_history),
|
||||
"previews": ordered,
|
||||
"tests": tests,
|
||||
|
||||
@@ -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