Peach: Local-first video metadata scraper and media manager.
fix(release): macOS 产物带上对应源码并按文件逐个核对
longmeidao3748c5031827
diff --git a/.gitlab-ci.yml b/.gitlab-ci.ymlindex aa5572695..42dce2ca5 100644--- a/.gitlab-ci.yml+++ b/.gitlab-ci.yml@@ -279,5 +279,6 @@ publish-release:- python3 scripts/ci_r2_artifacts.py pull windows-release- python3 scripts/ci_r2_artifacts.py pull macos-release- cp dist/macos.noindex/arm64/*.dmg dist/macos.noindex/x86_64/*.dmg release/+ - cp dist/macos.noindex/arm64/*-corresponding-source.zip dist/macos.noindex/x86_64/*-corresponding-source.zip release/- python3 scripts/publish_gitlab_release.py- python3 scripts/ci_r2_artifacts.py cleanupdiff --git a/scripts/ci_r2_artifacts.py b/scripts/ci_r2_artifacts.pyindex 5071a4aef..babb112d5 100644--- a/scripts/ci_r2_artifacts.py+++ b/scripts/ci_r2_artifacts.py@@ -106,17 +106,25 @@ def inventory(root: Path, group: str) -> list[dict]:if not items or len({item["path"].casefold() for item in items}) != len(items):raise ValueError("产物清单为空或包含跨平台同名文件")if group == "macos-release":+ build = identity()for arch in ("arm64", "x86_64"):- if sum(item["path"].startswith(f"dist/macos.noindex/{arch}/") for item in items) != 3:- raise ValueError("每种 macOS 架构须包含 DMG、构建身份与 SHA-256 清单")folder = root / "dist/macos.noindex" / arch- info = json.loads((folder / "build-info.json").read_text(encoding="utf-8"))- build = identity()image = folder / f"Peach-{build['tag'][1:]}-macos-{arch}.dmg"+ # 镜像随包带 FFmpeg 与 untrunc,许可证要求同时提供对应源码;清单逐个列出这三份。+ listed = {image.name} | {f"{tool}-macos-{arch}-corresponding-source.zip" for tool in ("ffmpeg", "untrunc")}+ present = {PurePosixPath(item["path"]).name for item in items+ if item["path"].startswith(f"dist/macos.noindex/{arch}/")}+ if present != listed | {"build-info.json", "SHA256SUMS.txt"}:+ raise ValueError("每种 macOS 架构须包含 DMG、两份对应源码、构建身份与 SHA-256 清单")+ info = json.loads((folder / "build-info.json").read_text(encoding="utf-8"))+ sums = {}+ for line in (folder / "SHA256SUMS.txt").read_text(encoding="utf-8").splitlines():+ digest, _, name = line.partition(" ")+ sums[name] = digestif (info.get("commit") != build["commit"] or info.get("version") != build["tag"][1:]or info.get("architecture") != arch or info.get("dirty") is not False- or not image.is_file()- or (folder / "SHA256SUMS.txt").read_text(encoding="utf-8").strip() != f"{checksum(image)} {image.name}"):+ or set(sums) != listed+ or any(sums[name] != checksum(folder / name) for name in listed)):raise ValueError("macOS 构建身份或镜像 SHA-256 不符")return itemsdiff --git a/tests/test_scripts.py b/tests/test_scripts.pyindex 10b8fe947..f7d985836 100644--- a/tests/test_scripts.py+++ b/tests/test_scripts.py@@ -4891,13 +4891,21 @@ class R2ArtifactTransferTests(unittest.TestCase):(folder / "Peach.app/app").write_bytes(b"expanded application")(folder / "build-info.json").write_text(json.dumps({"version": "1.2.3", "commit": "a" * 40,"architecture": arch, "dirty": False}))- (folder / "SHA256SUMS.txt").write_text(f"{module.checksum(image)} {image.name}\n")+ sources = [folder / f"{tool}-macos-{arch}-corresponding-source.zip" for tool in ("ffmpeg", "untrunc")]+ for source in sources:+ source.write_bytes(b"corresponding source " + source.name.encode())+ # 与 `ci_macos.sh` 写出的清单同形:镜像一行,对应源码各一行。+ (folder / "SHA256SUMS.txt").write_text(+ "".join(f"{module.checksum(path)} {path.name}\n" for path in (image, *sources)))items = module.inventory(root, "macos-release")- self.assertEqual(len(items), 6)+ self.assertEqual(len(items), 10)self.assertFalse(any(".app/" in item["path"] for item in items))- image.write_bytes(b"tampered application")+ sources[0].write_bytes(b"tampered source")with self.assertRaisesRegex(ValueError, "SHA-256"):module.inventory(root, "macos-release")+ sources[0].unlink()+ with self.assertRaisesRegex(ValueError, "对应源码"):+ module.inventory(root, "macos-release")def test_rclone_path_requires_installed_project_tool(self):module = load_script("ci_r2_artifacts")