Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/test-czdev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test czdev

on:
push:
paths: ['scripts/czdev/**', 'tests/**', '.github/workflows/test-czdev.yml']
pull_request:
paths: ['scripts/czdev/**', 'tests/**', '.github/workflows/test-czdev.yml']

permissions:
contents: read

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python3 -m unittest discover -s tests -v
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ email-address matching.

### `czdev publish` — end-to-end flow

Version updates automatically replace older store versions. The publish PR
removes manifests for strictly older Debian versions of the same app, including
when switching between `arm64` and `all`; listing-only updates keep manifests.
The shared packages deployment also enforces this for older CLI versions and
concurrent submissions. Official old download links are removed after the new
version is deployed and present in both store registries. Your fork's upload
buffer remains under your control; no manual `czdev unpublish` is needed for
superseded store versions.

```
┌──────────────────────────────────────────────────────────────────────────────┐
│ czdev publish — End-to-End Flow │
Expand Down
28 changes: 25 additions & 3 deletions scripts/czdev/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def run(deb: Optional[str] = None):
# branch — no .deb, no LFS.
push_pool_branch(gh, push_owner, push_repo, branch, meta["package"], app_dir, store_meta, meta_out,
extra={manifest_name: json.dumps(manifest, indent=2) + "\n"},
message=f"publish: {meta['package']} {meta['version']} ({meta['architecture']})")
message=f"publish: {meta['package']} {meta['version']} ({meta['architecture']})",
replacement=manifest)

pr_body = (
f"## Package: `{meta['package']}`\n\n"
Expand All @@ -153,9 +154,11 @@ def run(deb: Optional[str] = None):
f"| Binary | [{asset_name}]({download_url}) |\n\n"
f"Submitted via `czdev publish`. The `.deb` is hosted on the contributor's "
f"buffer release; CI verifies the sha256 and, on merge, promotes it into the "
f"official `apt-pool` release."
f"official `apt-pool` release. Older versions are replaced automatically; "
f"their store download links are removed after the new version is deployed."
)
open_pr(gh, pr_head_owner, branch, f"publish: {meta['package']} {meta['version']}", pr_body)
print(" Once the new version is deployed, older store versions are removed automatically.")


def run_meta_only():
Expand Down Expand Up @@ -212,7 +215,8 @@ def push_target(gh: GitHubClient, user) -> tuple:


def push_pool_branch(gh: GitHubClient, push_owner: str, push_repo: str, branch: str, pkg: str,
app_dir: str, store_meta: dict, meta_out: dict, extra: dict, message: str):
app_dir: str, store_meta: dict, meta_out: dict, extra: dict, message: str,
replacement: Optional[dict] = None):
"""Commit pool/main/<pkg>/ (meta.json, screenshots, icon and `extra` files)
on a new branch of the push target, based on the official repo's main.

Expand Down Expand Up @@ -271,6 +275,8 @@ def push_pool_branch(gh: GitHubClient, push_owner: str, push_repo: str, branch:
(dest_dir / "meta.json").write_text(json.dumps(meta_out, indent=2, ensure_ascii=False) + "\n")
for name, text in extra.items():
(dest_dir / name).write_text(text)
if replacement is not None:
retire_older_manifests(dest_dir, replacement)

print(" → Creating commit... ", end="", flush=True)
run_cmd_in(tmp_dir, ["git", "add", "-A", f"pool/main/{pkg}"])
Expand Down Expand Up @@ -298,6 +304,22 @@ def open_pr(gh: GitHubClient, pr_head_owner: Optional[str], branch: str, title:
print(" a first release waits for a maintainer.")


def retire_older_manifests(directory: Path, replacement: dict):
"""Replace only older versions of this package; metadata-only PRs skip this."""
target = directory / (replacement["filename"] + ".release.json")
if not target.is_file() or json.loads(target.read_text()) != replacement:
raise ValueError("replacement manifest is missing or changed")
obsolete = []
for path in directory.glob("*.deb.release.json"):
item = json.loads(path.read_text())
if item["package"] != replacement["package"]:
raise ValueError(f"manifest package mismatch: {path}")
if compare_versions(item["version"], replacement["version"]) < 0:
obsolete.append(path)
for path in obsolete:
path.unlink()


def resolve_deb(deb: Optional[str]) -> str:
if deb:
if not os.path.isfile(deb):
Expand Down
63 changes: 63 additions & 0 deletions tests/test_publish_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Version replacement in czdev publish PRs, without uploads or live changes."""
import json
from pathlib import Path
import sys
import tempfile
import unittest
from unittest.mock import patch

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
from czdev import publish


class ReplacementTests(unittest.TestCase):
def setUp(self):
temporary = tempfile.TemporaryDirectory()
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)

def manifest(self, version, arch='arm64'):
item = dict(package='sample', version=version,
filename=f'sample_{publish.asset_safe(version)}_{arch}.deb')
path = self.root / (item['filename'] + '.release.json')
path.write_text(json.dumps(item))
return path, item

def test_update_removes_older_versions_across_architecture_changes(self):
older = [self.manifest(v)[0] for v in ('1.9', '1.10~rc1', '1.10-2')]
latest, item = self.manifest('1.10-10', 'all')
listing = self.root / 'meta.json'
listing.write_text('{"title":"keep"}')
publish.retire_older_manifests(self.root, item)
self.assertTrue(latest.exists())
self.assertTrue(listing.exists())
self.assertFalse(any(p.exists() for p in older))

def test_epoch_equal_version_and_newer_manifests_are_preserved(self):
old, _ = self.manifest('9.0')
current, item = self.manifest('1:0.1')
equal, _ = self.manifest('1:0.1', 'all')
newer, _ = self.manifest('2:0.1')
publish.retire_older_manifests(self.root, item)
self.assertFalse(old.exists())
self.assertTrue(all(p.exists() for p in (current, equal, newer)))

def test_missing_replacement_preserves_all_old_versions(self):
old, item = self.manifest('1.0')
item['filename'] = 'missing_2.0_all.deb'
with self.assertRaisesRegex(ValueError, 'replacement'):
publish.retire_older_manifests(self.root, item)
self.assertTrue(old.exists())

def test_metadata_only_branch_never_runs_version_retirement(self):
with patch.object(publish, 'run_cmd_in'), patch.object(publish.time, 'sleep'), \
patch.object(publish, 'retire_older_manifests') as retire:
gh = unittest.mock.Mock()
gh.get_ref_sha.return_value = 'upstream'
publish.push_pool_branch(gh, 'owner', 'repo', 'metadata/sample', 'sample',
str(self.root), {}, {}, {}, 'metadata only')
retire.assert_not_called()


if __name__ == '__main__':
unittest.main()
Loading