package-image: version release ZIP from latest git commit

This commit is contained in:
Luxferre committed 2026-11-28 11:36:56 +02:00
1 parent fff3622001
commit f44f1bb588
4 files changed
+95 -14

No files matched your search

+53 -10
View File
@@ -820,6 +820,7 @@ def test_firmware_injection_ext4():
def test_release_zip_packager():
import datetime
import zipfile
if not all(shutil.which(cmd) for cmd in ("mke2fs", "debugfs", "e2fsck")):
@@ -829,7 +830,38 @@ def test_release_zip_packager():
pkg_mod = _load_mod(
"package_release_zip", os.path.join(SCRIPTS_DIR, "package-release-zip.py")
)
git_res = subprocess.run(
["git", "-C", BASE_DIR, "log", "-1", "--format=%ct %h"],
capture_output=True, text=True, check=True,
)
git_ts_str, git_sha = git_res.stdout.strip().split()
expected_date = datetime.datetime.fromtimestamp(
int(git_ts_str), tz=datetime.timezone.utc
).strftime("%Y%m%d")
expected_ver = f"{expected_date}-{git_sha}"
with tempfile.TemporaryDirectory(prefix="geminux-zip-test-") as tmp:
saved_ver = os.environ.pop("GEMINUX_VERSION", None)
saved_cname = os.environ.pop("GEMINUX_CODENAME", None)
try:
assert pkg_mod.resolve_release_version() == expected_ver
assert pkg_mod.resolve_release_version() != "0.1.0"
assert pkg_mod.resolve_release_version("custom-1.2") == "custom-1.2"
os.environ["GEMINUX_VERSION"] = "env-9.9"
assert pkg_mod.resolve_release_version() == "env-9.9"
os.environ.pop("GEMINUX_VERSION", None)
fallback_ver = pkg_mod.resolve_release_version(repo_dir=tmp)
assert isinstance(fallback_ver, str) and len(fallback_ver) > 0
finally:
if saved_ver is not None:
os.environ["GEMINUX_VERSION"] = saved_ver
else:
os.environ.pop("GEMINUX_VERSION", None)
if saved_cname is not None:
os.environ["GEMINUX_CODENAME"] = saved_cname
else:
os.environ.pop("GEMINUX_CODENAME", None)
sysroot = os.path.join(tmp, "sysroot")
os.makedirs(os.path.join(sysroot, "etc", "ssh"), exist_ok=True)
os.makedirs(os.path.join(sysroot, "root", ".ssh"), exist_ok=True)
@@ -866,22 +898,24 @@ def test_release_zip_packager():
)
orig_root_sha = flash_mtk.sha256_file(root_img)
out_zip = os.path.join(tmp, "geminux-0.1.0-helio-gemini-x27.zip")
pkg_env = dict(os.environ)
pkg_env.pop("GEMINUX_VERSION", None)
pkg_env.pop("GEMINUX_CODENAME", None)
top = f"geminux-{expected_ver}-helio-gemini-x27"
out_zip = os.path.join(tmp, f"{top}.zip")
res = subprocess.run(
[
os.path.join(BASE_DIR, "package-image.sh"),
"--images-dir", img_dir,
"--output", out_zip,
"--version", "0.1.0",
"--codename", "helio",
],
capture_output=True, text=True, check=False,
env=pkg_env, capture_output=True, text=True, check=False,
)
assert res.returncode == 0, f"package-image.sh failed:\n{res.stdout}\n{res.stderr}"
assert flash_mtk.sha256_file(root_img) == orig_root_sha, "Source rootfs image was mutated!"
assert os.path.isfile(out_zip) and os.path.isfile(out_zip + ".sha256")
top = "geminux-0.1.0-helio-gemini-x27"
with zipfile.ZipFile(out_zip, "r") as zf:
assert zf.testzip() is None
names = set(zf.namelist())
@@ -905,8 +939,16 @@ def test_release_zip_packager():
sh_info = zf.getinfo(f"{top}/flash-mtk.sh")
assert ((sh_info.external_attr >> 16) & 0o111) == 0o111, "flash-mtk.sh missing +x attr"
txt = zf.read(f"{top}/FLASH-INSTRUCTIONS.txt").decode("utf-8")
for needle in ("./flash-mtk.sh --flash-full", "sha256sum -c SHA256SUMS.txt", "LEFT USB-C port", "Docker is NOT required"):
for needle in (
f"Release: {expected_ver} (helio)",
f"unzip {top}.zip",
"./flash-mtk.sh --flash-full",
"sha256sum -c SHA256SUMS.txt",
"LEFT USB-C port",
"Docker is NOT required",
):
assert needle in txt, f"FLASH-INSTRUCTIONS.txt missing {needle!r}"
assert "0.1.0" not in txt, "FLASH-INSTRUCTIONS.txt unexpectedly contains fallback version 0.1.0"
# Extract with unzip to verify preserved executable bits, SHA256SUMS, and flasher launch
ext_dir = os.path.join(tmp, "extracted")
@@ -936,23 +978,24 @@ def test_release_zip_packager():
assert not fw_mod._debugfs_path_exists(sanitized_img, "/root/.ssh/authorized_keys")
assert not fw_mod._debugfs_path_exists(sanitized_img, "/home/user/.ssh/authorized_keys")
stripped_zip = os.path.join(tmp, "geminux-0.1.0-helio-gemini-x27-stripped.zip")
stripped_top = "geminux-custom-ver-helio-gemini-x27"
stripped_zip = os.path.join(tmp, f"{stripped_top}-stripped.zip")
sres = subprocess.run(
[
os.path.join(BASE_DIR, "package-image.sh"),
"--images-dir", img_dir,
"--output", stripped_zip,
"--version", "0.1.0",
"--version", "custom-ver",
"--codename", "helio",
"--strip-firmware",
],
capture_output=True, text=True, check=False,
env=pkg_env, capture_output=True, text=True, check=False,
)
assert sres.returncode == 0, f"package-image.sh --strip-firmware failed:\n{sres.stdout}\n{sres.stderr}"
strip_dir = os.path.join(tmp, "extracted-stripped")
os.makedirs(strip_dir, exist_ok=True)
subprocess.run(["unzip", "-q", stripped_zip, "-d", strip_dir], check=True)
stripped_img = os.path.join(strip_dir, top, "images", "geminux-rootfs.img")
stripped_img = os.path.join(strip_dir, stripped_top, "images", "geminux-rootfs.img")
assert subprocess.run(["e2fsck", "-fn", stripped_img], capture_output=True).returncode == 0
assert fw_mod.debugfs_ls(stripped_img, "lib/firmware/mediatek/mt6797") == []
print("[PASS] Release ZIP packager (sanitized rootfs, FLASH-INSTRUCTIONS.txt, SHA256SUMS, runnable flasher) verified")