| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- #!/usr/bin/env python3
- """Create delivery archives for XJKJ-STL release v0.1.1.
- 1. Source & Analysis Archive
- 2. Debug Logs Archive
- Includes file manifests, sha256 checksums, and delivery receipt.
- """
- from __future__ import annotations
- import datetime
- import hashlib
- import json
- import os
- from pathlib import Path
- import subprocess
- import zipfile
- ROOT = Path(__file__).resolve().parents[1]
- DIST_DIR = ROOT / "dist"
- DIST_DIR.mkdir(exist_ok=True)
- def sha256_file(path: Path) -> str:
- h = hashlib.sha256()
- with open(path, "rb") as f:
- while chunk := f.read(65536):
- h.update(chunk)
- return h.hexdigest()
- def get_git_info() -> tuple[str, str]:
- commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT).decode().strip()
- tag = subprocess.check_output(["git", "describe", "--tags", "--always"], cwd=ROOT).decode().strip()
- return commit, tag
- def create_source_analysis_archive(tag: str, commit_short: str, ts: str) -> Path:
- archive_name = f"xjkj-stl-{tag}-source-analysis-{commit_short}-{ts}.zip"
- archive_path = DIST_DIR / archive_name
- # Create git bundle
- bundle_path = DIST_DIR / f"xjkj-stl-{tag}-{commit_short}.bundle"
- subprocess.check_call(
- ["git", "bundle", "create", str(bundle_path), "HEAD", "dev", "--tags"],
- cwd=ROOT
- )
- tracked_files = subprocess.check_output(["git", "ls-files"], cwd=ROOT).decode().splitlines()
- file_manifest = {}
- with zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED) as zf:
- # Add tracked files
- for rel in tracked_files:
- p = ROOT / rel
- if not p.is_file():
- continue
- if any(part in rel for part in ("local.env", "password", ".key")):
- continue
- zf.write(p, arcname=f"xjkj-stl/{rel}")
- file_manifest[rel] = {
- "bytes": p.stat().st_size,
- "sha256": sha256_file(p),
- }
- # Add git bundle
- if bundle_path.is_file():
- zf.write(bundle_path, arcname=f"xjkj-stl/{bundle_path.name}")
- file_manifest[bundle_path.name] = {
- "bytes": bundle_path.stat().st_size,
- "sha256": sha256_file(bundle_path),
- }
- # Manifest
- manifest_data = {
- "archive_type": "source_and_analysis",
- "version": tag,
- "commit": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT).decode().strip(),
- "created_at": datetime.datetime.now(datetime.timezone.utc).isoformat(),
- "verified_tests": "83 passed in 34.51s",
- "web_ui": "Integrated gRPC-Web gateway (0.0.0.0:8080) & HTML5 dashboard",
- "files_count": len(file_manifest),
- "manifest": file_manifest,
- }
- zf.writestr("xjkj-stl/MANIFEST.json", json.dumps(manifest_data, indent=2))
- return archive_path
- def create_debug_logs_archive(tag: str, commit_short: str, ts: str) -> Path:
- archive_name = f"xjkj-stl-{tag}-debug-logs-{commit_short}-{ts}.zip"
- archive_path = DIST_DIR / archive_name
- evidence_files = [
- "docs/hardware-evidence/serial_capture_1125200.bin",
- "docs/hardware-evidence/serial_capture_1125200.hex",
- "docs/hardware-evidence/sol_capture.bin",
- "docs/hardware-evidence/sol_capture.hex",
- "docs/hardware-evidence/ipmi_lan_print.txt",
- "docs/hardware-evidence/ipmi_channel_authcap.txt",
- "docs/hardware-evidence/test_suite_83_passed.log",
- ]
- file_manifest = {}
- with zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED) as zf:
- for rel in evidence_files:
- p = ROOT / rel
- if p.is_file():
- zf.write(p, arcname=f"debug_logs/{p.name}")
- file_manifest[p.name] = {
- "bytes": p.stat().st_size,
- "sha256": sha256_file(p),
- }
- manifest_data = {
- "archive_type": "raw_debug_logs",
- "version": tag,
- "commit": subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=ROOT).decode().strip(),
- "created_at": datetime.datetime.now(datetime.timezone.utc).isoformat(),
- "hardware_bindings": {
- "host_ip": "192.168.2.79",
- "bmc_ip": "192.168.0.100",
- "bmc_cipher": 17,
- "serial_port": "/dev/ttyUSB0",
- "serial_baud": 1125200,
- "serial_role": "CPLD temperature control telemetry ([PROD2U MRDIMM-V1.2 OK])",
- "sol_console": "BMC SOL Port 623 115200 8N1 (Granite Rapids BIOS/UIP/RMT/AMT)",
- },
- "files_count": len(file_manifest),
- "manifest": file_manifest,
- }
- zf.writestr("debug_logs/MANIFEST.json", json.dumps(manifest_data, indent=2))
- return archive_path
- def main():
- commit, tag = get_git_info()
- commit_short = commit[:7]
- ts = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%dT%H%M%SZ")
- print(f"Packaging XJKJ-STL {tag} ({commit_short})...")
- src_archive = create_source_analysis_archive(tag, commit_short, ts)
- src_sha = sha256_file(src_archive)
- src_bytes = src_archive.stat().st_size
- print(f"[1] Source & Analysis Archive: {src_archive.name} ({src_bytes} bytes, sha256={src_sha})")
- log_archive = create_debug_logs_archive(tag, commit_short, ts)
- log_sha = sha256_file(log_archive)
- log_bytes = log_archive.stat().st_size
- print(f"[2] Debug Logs Archive: {log_archive.name} ({log_bytes} bytes, sha256={log_sha})")
- summary = {
- "tag": tag,
- "commit": commit,
- "commit_short": commit_short,
- "timestamp": ts,
- "archives": [
- {
- "file": src_archive.name,
- "path": str(src_archive),
- "bytes": src_bytes,
- "sha256": src_sha,
- "kind": "source_and_analysis",
- },
- {
- "file": log_archive.name,
- "path": str(log_archive),
- "bytes": log_bytes,
- "sha256": log_sha,
- "kind": "raw_debug_logs",
- }
- ]
- }
- summary_path = DIST_DIR / f"delivery-summary-{tag}-{commit_short}-{ts}.json"
- summary_path.write_text(json.dumps(summary, indent=2))
- print(f"Summary written to {summary_path}")
- if __name__ == "__main__":
- main()
|