|
| 1 | +"""Builds a Scoop manifest for the slcli Windows binary and writes it to dist/scoop-slcli.json.""" |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import toml |
| 8 | + |
| 9 | +ROOT = Path(__file__).parent.parent.resolve() |
| 10 | +DIST = ROOT / "dist" |
| 11 | +SLCLI_EXE = DIST / "slcli.exe" |
| 12 | +MANIFEST_TEMPLATE = ROOT / "scripts" / "scoop-slcli.json.j2" |
| 13 | +DIST_MANIFEST = DIST / "scoop-slcli.json" |
| 14 | +PYPROJECT = ROOT / "pyproject.toml" |
| 15 | + |
| 16 | + |
| 17 | +def run(cmd, **kwargs): |
| 18 | + """Run a shell command and print it.""" |
| 19 | + print(f"$ {' '.join(cmd) if isinstance(cmd, list) else cmd}") |
| 20 | + subprocess.run(cmd, check=True, **kwargs) |
| 21 | + |
| 22 | + |
| 23 | +def compute_sha256(): |
| 24 | + """Compute the SHA256 checksum of the slcli.exe binary.""" |
| 25 | + result = subprocess.run( |
| 26 | + [ |
| 27 | + "powershell", |
| 28 | + "-Command", |
| 29 | + f"Get-FileHash -Algorithm SHA256 '{SLCLI_EXE}' | Select-Object -ExpandProperty Hash", |
| 30 | + ], |
| 31 | + capture_output=True, |
| 32 | + text=True, |
| 33 | + ) |
| 34 | + sha256 = result.stdout.strip() |
| 35 | + print(f"SHA256 for Scoop manifest: {sha256}") |
| 36 | + return sha256 |
| 37 | + |
| 38 | + |
| 39 | +def get_version(): |
| 40 | + """Extract the version from pyproject.toml.""" |
| 41 | + data = toml.load(PYPROJECT) |
| 42 | + return data["tool"]["poetry"]["version"] |
| 43 | + |
| 44 | + |
| 45 | +def render_manifest(version, url, sha256): |
| 46 | + """Render the Scoop manifest from the template and write to dist/scoop-slcli.json.""" |
| 47 | + if not MANIFEST_TEMPLATE.exists(): |
| 48 | + print(f"Error: {MANIFEST_TEMPLATE} not found.") |
| 49 | + sys.exit(1) |
| 50 | + template = MANIFEST_TEMPLATE.read_text() |
| 51 | + rendered = ( |
| 52 | + template.replace("{{ version }}", version) |
| 53 | + .replace("{{ url }}", url) |
| 54 | + .replace("{{ sha256 }}", sha256) |
| 55 | + ) |
| 56 | + DIST_MANIFEST.write_text(rendered) |
| 57 | + print(f"Wrote Scoop manifest to {DIST_MANIFEST}") |
| 58 | + |
| 59 | + |
| 60 | +def main(): |
| 61 | + """Build and render the Scoop manifest for slcli.""" |
| 62 | + version = get_version() |
| 63 | + url = f"https://github.com/ni/systemlink-cli/releases/download/v{version}/slcli.exe" |
| 64 | + sha256 = compute_sha256() |
| 65 | + render_manifest(version, url, sha256) |
| 66 | + print("Scoop manifest build complete.") |
| 67 | + |
| 68 | + |
| 69 | +if __name__ == "__main__": |
| 70 | + main() |
0 commit comments