Skip to content

Open source CapCut alternative.

TypeScript

Keep latest Donkey releases

David Leada8ec755248
diff --git a/.github/workflows/promote-donkey-release.yml b/.github/workflows/promote-donkey-release.yml
index a34868ad..02da0c58 100644
--- a/.github/workflows/promote-donkey-release.yml
+++ b/.github/workflows/promote-donkey-release.yml
@@ -166,6 +166,7 @@ jobs:
--build "${{ steps.release.outputs.build }}"
--sparkle-ed-signature "${{ steps.sparkle.outputs.signature }}"
--asset-name "Donkey.dmg"
+ --keep-releases 10
--commit
)
diff --git a/docs/guides/releasing-donkey.md b/docs/guides/releasing-donkey.md
index fc1c7a84..99d94286 100644
--- a/docs/guides/releasing-donkey.md
+++ b/docs/guides/releasing-donkey.md
@@ -20,6 +20,9 @@ the result to the moving `nightly` prerelease.
- The workflow also uploads `Donkey.dmg.sha256`.
- The website download URL points to the promoted numeric release asset, not a
moving `latest` or `-latest` URL.
+- The production release workflow keeps the latest 10 numeric GitHub Releases
+ and deletes older numeric release records after promotion. It does not delete
+ Git tags, aliases, or the nightly prerelease.
- The public Sparkle appcast is committed at `site/public/appcast.xml` and
served as `https://donkeyuse.com/appcast.xml`.
- Sparkle signs and validates update archives; do not add a Donkey-specific
@@ -77,7 +80,8 @@ creates or updates the numeric GitHub Release, uploads the DMG and checksum,
updates `site/public/appcast.xml`, updates the website download constant,
commits those site/appcast changes, marks the numeric release as GitHub's latest
release, and moves the alias tags. When no numeric release tag exists yet, the
-workflow starts at `0.1.0`.
+workflow starts at `0.1.0`. After promotion, it deletes older production
+GitHub Release records so only the latest 10 numeric releases remain.
## Alias Tags
@@ -117,6 +121,8 @@ After the workflow finishes:
- The website source has `DONKEY_LATEST_VERSION` set to the numeric version.
- `site/public/appcast.xml` contains one item for that version and an enclosure
URL under `/releases/download/vMAJOR.MINOR.PATCH/Donkey.dmg`.
+- The GitHub Releases page keeps no more than 10 numeric production releases,
+ plus the separate nightly prerelease when present.
- `https://donkeyuse.com/appcast.xml` updates after the site deploy completes.
If Sparkle cannot validate an update, first check that the app was packaged with
diff --git a/scripts/promote-github-release.py b/scripts/promote-github-release.py
index 634a7aa8..043546d8 100644
--- a/scripts/promote-github-release.py
+++ b/scripts/promote-github-release.py
@@ -18,7 +18,7 @@ SEMVER_RE = re.compile(r"^v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<pa
LATEST_VERSION_RE = re.compile(r'export const DONKEY_LATEST_VERSION = "[^"]+";')
-@dataclass(frozen=True)
+@dataclass(frozen=True, order=True)
class Version:
major: int
minor: int
@@ -55,6 +55,13 @@ class Release:
published_at: str
+@dataclass(frozen=True)
+class RetentionRelease:
+ version: Version
+ tag_name: str
+ release_id: int
+
+
def run(command: Sequence[str], *, dry_run: bool = False, mutate: bool = False) -> str:
if dry_run and mutate:
print(f"dry-run: {' '.join(command)}")
@@ -112,6 +119,13 @@ def parse_version(raw_version: str) -> Version:
)
+def numeric_release_version(tag_name: str) -> Version | None:
+ try:
+ return parse_version(tag_name)
+ except ValueError:
+ return None
+
+
def load_release(repo: str, tag: str, asset_name: str) -> Release:
payload = run(["gh", "api", f"repos/{repo}/releases/tags/{tag}"])
data = json.loads(payload)
@@ -131,6 +145,40 @@ def load_release(repo: str, tag: str, asset_name: str) -> Release:
raise ValueError(f"release {tag} does not have an asset named {asset_name}")
+def load_retention_releases(repo: str) -> list[RetentionRelease]:
+ payload = run(["gh", "api", "--paginate", "--slurp", f"repos/{repo}/releases"])
+ pages = json.loads(payload)
+ if not isinstance(pages, list):
+ raise ValueError("GitHub releases response was not a list")
+
+ raw_releases: list[dict] = []
+ for page in pages:
+ if isinstance(page, list):
+ raw_releases.extend(item for item in page if isinstance(item, dict))
+ elif isinstance(page, dict):
+ raw_releases.append(page)
+
+ releases: list[RetentionRelease] = []
+ for release in raw_releases:
+ if release.get("prerelease") is True:
+ continue
+
+ tag_name = str(release.get("tag_name") or "")
+ version = numeric_release_version(tag_name)
+ if version is None:
+ continue
+
+ releases.append(
+ RetentionRelease(
+ version=version,
+ tag_name=tag_name,
+ release_id=int(release["id"]),
+ )
+ )
+
+ return sorted(releases, key=lambda release: release.version, reverse=True)
+
+
def release_pub_date(published_at: str) -> str:
if published_at:
parsed = datetime.fromisoformat(published_at.replace("Z", "+00:00"))
@@ -234,6 +282,36 @@ def mark_release_latest(repo: str, release: Release, dry_run: bool) -> None:
)
+def prune_old_releases(repo: str, keep_releases: int, dry_run: bool) -> None:
+ if keep_releases < 1:
+ raise ValueError("keep releases must be at least 1")
+
+ releases = load_retention_releases(repo)
+ stale_releases = releases[keep_releases:]
+ if not stale_releases:
+ print(f"Release retention: found {len(releases)} production releases; nothing to delete.")
+ return
+
+ print(
+ "Release retention: "
+ f"keeping latest {keep_releases} production releases and deleting {len(stale_releases)} older releases."
+ )
+ for release in stale_releases:
+ run(
+ [
+ "gh",
+ "api",
+ "-X",
+ "DELETE",
+ f"repos/{repo}/releases/{release.release_id}",
+ ],
+ dry_run=dry_run,
+ mutate=True,
+ )
+ action = "Would delete" if dry_run else "Deleted"
+ print(f"{action} GitHub Release {release.tag_name}")
+
+
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Promote a numeric Donkey GitHub Release for site downloads and Sparkle.")
parser.add_argument("--repo", required=True, help="GitHub repository in owner/name form.")
@@ -246,6 +324,7 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--promote-major", action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("--promote-minor", action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("--promote-latest", action=argparse.BooleanOptionalAction, default=True)
+ parser.add_argument("--keep-releases", type=int, default=10, help="Keep this many latest numeric production releases.")
parser.add_argument("--commit", action="store_true", help="Commit and push website/appcast changes before moving aliases.")
parser.add_argument("--dry-run", action="store_true")
return parser.parse_args()
@@ -253,6 +332,9 @@ def parse_args() -> argparse.Namespace:
def main() -> int:
args = parse_args()
+ if args.keep_releases < 1:
+ raise ValueError("keep releases must be at least 1")
+
version = parse_version(args.version)
if version.tag.endswith("-latest"):
raise ValueError("promoted website versions must be numeric and must not use a -latest tag")
@@ -269,6 +351,7 @@ def main() -> int:
promote_tags(version, args.promote_major, args.promote_minor, args.promote_latest, args.dry_run)
if args.promote_latest:
mark_release_latest(args.repo, release, args.dry_run)
+ prune_old_releases(args.repo, args.keep_releases, args.dry_run)
print(f"Promoted {version.tag}")
print(f"Download URL: {release.asset.download_url}")