skrawcz commented on code in PR #741:
URL: https://github.com/apache/burr/pull/741#discussion_r3108324971


##########
scripts/verify_apache_artifacts.py:
##########
@@ -20,65 +20,215 @@
 Apache Artifacts Verification Script
 
 Comprehensive verification tool for Apache release artifacts.
-Checks signatures, checksums, licenses, and archive integrity.
+Checks signatures, checksums, archive integrity, license metadata,
+reproducible rebuilds, and Apache RAT results.
 
 Usage:
-    # List contents of an artifact
-    python scripts/verify_apache_artifacts.py list-contents 
dist/apache-burr-0.41.0-incubating-src.tar.gz
-
-    # Verify signatures and checksums
+    python scripts/verify_apache_artifacts.py --help
+        Show the available verification commands and flags.
     python scripts/verify_apache_artifacts.py signatures
-
-    # Verify licenses with Apache RAT
-    python scripts/verify_apache_artifacts.py licenses --rat-jar 
path/to/apache-rat.jar
-
-    # Verify everything
-    python scripts/verify_apache_artifacts.py all --rat-jar 
path/to/apache-rat.jar
-
-    # Specify custom artifacts directory
-    python scripts/verify_apache_artifacts.py signatures --artifacts-dir 
/path/to/dist
+        Verify detached GPG signatures, SHA512 checksums, and basic archive 
readability.
+    python scripts/verify_apache_artifacts.py artifacts
+        Verify required LICENSE/NOTICE/DISCLAIMER files in release artifacts.
+    python scripts/verify_apache_artifacts.py licenses --rat-jar 
/path/to/apache-rat.jar
+        Run Apache RAT and validate license-report results for extracted 
tarball contents.
+    python scripts/verify_apache_artifacts.py reproducible
+        Rebuild from the release source artifact and compare rebuilt outputs 
to release artifacts.
+    python scripts/verify_apache_artifacts.py all --rat-jar 
/path/to/apache-rat.jar --vote-email
+        Run the full verification flow and optionally render a vote email 
draft from the results.
 """
 
+from __future__ import annotations
+
 import argparse
 import glob
 import hashlib
+import importlib.util
 import os
+import re
 import shutil
 import subprocess
 import sys
 import tarfile
 import tempfile
+import textwrap
 import xml.etree.ElementTree as ET
 import zipfile
+from dataclasses import dataclass, field
+from pathlib import Path, PurePosixPath
 
 # Configuration
 PROJECT_SHORT_NAME = "burr"
+REQUIRED_TEXT_FILES = ("LICENSE", "NOTICE", "DISCLAIMER")
+WHEEL_LICENSE_FILES = ("LICENSE-wheel",)
+PASS = "PASS"
+FAIL = "FAIL"
+SKIP = "SKIP"
+
+
+@dataclass
+class CheckResult:
+    name: str
+    status: str
+    details: str = ""
+
+
+@dataclass
+class VerificationSummary:
+    results: list[CheckResult] = field(default_factory=list)
+
+    def record(self, name: str, status: str, details: str = "") -> None:
+        self.results.append(CheckResult(name=name, status=status, 
details=details))
+
+    def pass_(self, name: str, details: str = "") -> None:
+        self.record(name, PASS, details)
+
+    def fail(self, name: str, details: str = "") -> None:
+        self.record(name, FAIL, details)
+
+    def skip(self, name: str, details: str = "") -> None:
+        self.record(name, SKIP, details)
+
+    @property
+    def ok(self) -> bool:
+        return all(result.status != FAIL for result in self.results)
+
+    def render(self) -> str:
+        lines = ["Results:"]
+        if not self.results:
+            lines.append("  (no checks executed)")
+            return "\n".join(lines)
+
+        width = max(len(result.name) for result in self.results)
+        for result in self.results:
+            symbol = {"PASS": "āœ…", "FAIL": "āŒ", "SKIP": "⊘"}[result.status]
+            line = f"  {result.name:<{width}}  {symbol} {result.status}"
+            if result.details:
+                line += f"  {result.details}"
+            lines.append(line)
+        return "\n".join(lines)
 
 
 def _fail(message: str) -> None:
-    """Print error message and exit."""
     print(f"\nāŒ {message}")
     sys.exit(1)
 
 
 def _print_section(title: str) -> None:
-    """Print formatted section header."""
     print("\n" + "=" * 80)
     print(f"  {title}")
     print("=" * 80 + "\n")
 
 
-# ============================================================================
-# Signature and Checksum Verification
-# ============================================================================
+def _sha512_for_file(path: str) -> str:
+    sha512_hash = hashlib.sha512()
+    with open(path, "rb") as handle:
+        while chunk := handle.read(65536):
+            sha512_hash.update(chunk)
+    return sha512_hash.hexdigest()
+
+
+def _read_expected_text_files() -> dict[str, bytes]:
+    project_root = Path(__file__).resolve().parent.parent
+    expected: dict[str, bytes] = {}
+    for filename in (*REQUIRED_TEXT_FILES, *WHEEL_LICENSE_FILES):
+        expected[filename] = (project_root / filename).read_bytes()
+    return expected
+
+
+def _artifact_files(artifacts_dir: str) -> list[str]:
+    all_files = [
+        name
+        for name in os.listdir(artifacts_dir)
+        if os.path.isfile(os.path.join(artifacts_dir, name))
+    ]
+    return sorted(
+        name
+        for name in all_files
+        if not name.endswith((".asc", ".sha512"))
+        and not name.startswith("rat-report-")
+    )
+
+
+def _top_level_prefix(paths: list[str]) -> str | None:
+    parts = [PurePosixPath(path).parts for path in paths if path]
+    if not parts:
+        return None
+    prefix = parts[0][0]
+    if all(item and item[0] == prefix for item in parts):
+        return prefix
+    return None
+
+
+def _normalize_archive_member_names(names: list[str]) -> dict[str, str]:
+    prefix = _top_level_prefix(names)
+    normalized = {}
+    for name in names:
+        pure_name = PurePosixPath(name)
+        relative_parts = pure_name.parts[1:] if prefix and pure_name.parts[:1] 
== (prefix,) else pure_name.parts
+        normalized_name = str(PurePosixPath(*relative_parts)) if 
relative_parts else ""
+        normalized[normalized_name] = name
+    return normalized
+
+
+def _tar_file_bytes(artifact_path: str) -> dict[str, bytes]:
+    with tarfile.open(artifact_path, "r:gz") as tar:
+        file_members = [member for member in tar.getmembers() if 
member.isfile()]
+        mapping = _normalize_archive_member_names([member.name for member in 
file_members])
+        contents: dict[str, bytes] = {}
+        for member in file_members:
+            normalized_name = next(
+                normalized
+                for normalized, original in mapping.items()
+                if original == member.name
+            )
+            extracted = tar.extractfile(member)
+            if extracted is None:
+                continue
+            contents[normalized_name] = extracted.read()
+        return contents
+
+
+def _wheel_file_bytes(artifact_path: str) -> dict[str, bytes]:
+    with zipfile.ZipFile(artifact_path, "r") as wheel:
+        return {name: wheel.read(name) for name in wheel.namelist() if not 
name.endswith("/")}
+
 
+def _find_files_by_basename(file_bytes: dict[str, bytes], basename: str) -> 
list[str]:
+    matches = []
+    for path in file_bytes:
+        if PurePosixPath(path).name == basename:
+            matches.append(path)
+    return sorted(matches)
 
-def _verify_artifact_signature(artifact_path: str, signature_path: str) -> 
bool:
-    """Verify GPG signature of artifact."""
+
+def _verify_artifact_exists(artifact_path: str, summary: VerificationSummary, 
min_size: int = 1000) -> bool:
+    name = f"Artifact exists: {os.path.basename(artifact_path)}"

Review Comment:
   Nit: `REQUIRED_TEXT_FILES[1:]` silently skips `LICENSE` for wheels. A named 
constant (e.g., `WHEEL_REQUIRED_FILES = ("NOTICE", "DISCLAIMER") + 
WHEEL_LICENSE_FILES`) would make the intent clearer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to