#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Package the cross-built Windows toolkit for release and for native testing. package-windows.py release VERSION EXE OUT_DIR dist/alkane-toolkit-vVERSION-windows-x86_64.zip: one folder holding alkane-toolkit.exe, LICENSE and a README.txt. Prints the zip path. package-windows.py tests CARGO_JSON OUT_ZIP A bundle of the test executables `cargo test --no-run --message-format=json` reported (CARGO_JSON is that output), plus tests.txt naming each one. The native Windows job runs every listed executable on real Windows; the same binaries already ran under Wine. """ import json import pathlib import struct import sys import zipfile ROOT = pathlib.Path(__file__).resolve().parents[1] TARGET = "x86_64-pc-windows-gnu" def release(version: str, exe: str, out_dir: str) -> None: exe_path = pathlib.Path(exe) if exe_path.suffix != ".exe" or not exe_path.is_file(): sys.exit(f"not a Windows executable: {exe}") signed = _has_authenticode_signature(exe_path) name = f"alkane-toolkit-v{version}-windows-x86_64" out = pathlib.Path(out_dir) / f"{name}.zip" out.parent.mkdir(parents=True, exist_ok=True) readme = ( f"alkane-toolkit v{version} (Windows x86_64)\r\n" "\r\n" "Run alkane-toolkit.exe. No installer and no extra runtime are needed:\r\n" "the executable is self-contained and runs on Windows 10 and 11.\r\n" "\r\n" + ( "The executable is signed by BlueFlare Energy Solutions Inc. (Azure Artifact Signing). To check:\r\n" "right-click alkane-toolkit.exe > Properties > Digital Signatures.\r\n" if signed else "This build is not code-signed, so Windows SmartScreen may warn on first\r\n" "run: choose More info > Run anyway.\r\n" ) + "\r\n" "Settings are kept in %APPDATA%\\alkane-toolkit.\r\n" "SSH-based actions use the OpenSSH client built into Windows (ssh.exe);\r\n" "HTTP actions use curl.exe, also built in.\r\n" "\r\n" "Offline demo: run from a Command Prompt with\r\n" " set ALKANE_FAKE_SCAN=1 && alkane-toolkit.exe\r\n" ) with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z: z.write(exe_path, f"{name}/alkane-toolkit.exe") z.write(ROOT / "LICENSE", f"{name}/LICENSE.txt") z.writestr(f"{name}/README.txt", readme) print(out) def _has_authenticode_signature(exe: pathlib.Path) -> bool: """True if the PE file carries a certificate table (an Authenticode signature).""" data = exe.read_bytes() pe = struct.unpack_from(" 0 def tests(cargo_json: str, out_zip: str) -> None: executables = [] for line in pathlib.Path(cargo_json).read_text().splitlines(): try: message = json.loads(line) except json.JSONDecodeError: continue if (message.get("reason") == "compiler-artifact" and message.get("profile", {}).get("test") and message.get("executable")): executables.append(pathlib.Path(message["executable"])) executables = sorted(set(executables)) if not executables: sys.exit("no test executables in the cargo output") out = pathlib.Path(out_zip) out.parent.mkdir(parents=True, exist_ok=True) with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z: names = [] for exe in executables: if exe.suffix != ".exe" or TARGET not in exe.parts: sys.exit(f"not a {TARGET} test executable: {exe}") z.write(exe, exe.name) names.append(exe.name) z.writestr("tests.txt", "\n".join(names) + "\n") print(f"{out} ({len(executables)} test executables)") def main() -> None: if len(sys.argv) == 5 and sys.argv[1] == "release": release(*sys.argv[2:]) elif len(sys.argv) == 4 and sys.argv[1] == "tests": tests(*sys.argv[2:]) else: sys.exit(__doc__) if __name__ == "__main__": main()