|
| 1 | +#!/usr/bin/env nix-shell |
| 2 | +#!nix-shell -i python3 -p python3 nix-update |
| 3 | +"""Update script for nethermind package. |
| 4 | +
|
| 5 | +nix-update handles version and source hash but cannot update nuget-deps.json. |
| 6 | +This script runs nix-update first, then uses the package's fetch-deps script |
| 7 | +to regenerate nuget-deps.json. |
| 8 | +""" |
| 9 | + |
| 10 | +import subprocess |
| 11 | +import sys |
| 12 | +from pathlib import Path |
| 13 | + |
| 14 | +SCRIPT_DIR = Path(__file__).parent |
| 15 | +FLAKE_ROOT = SCRIPT_DIR.parent.parent |
| 16 | +NUGET_DEPS = SCRIPT_DIR / "nuget-deps.json" |
| 17 | + |
| 18 | + |
| 19 | +def run_nix_update() -> bool: |
| 20 | + """Run nix-update to handle version and source hash.""" |
| 21 | + print("Running nix-update...") |
| 22 | + result = subprocess.run( |
| 23 | + [ |
| 24 | + "nix-update", |
| 25 | + "--flake", |
| 26 | + "nethermind", |
| 27 | + "--version-regex", |
| 28 | + "^([0-9]+\\.[0-9]+\\.[0-9]+)$", |
| 29 | + # https://github.com/Mic92/nix-update/issues/563 |
| 30 | + "--src-only", |
| 31 | + ], |
| 32 | + cwd=FLAKE_ROOT, |
| 33 | + ) |
| 34 | + return result.returncode == 0 |
| 35 | + |
| 36 | + |
| 37 | +def update_nuget_deps() -> None: |
| 38 | + """Regenerate nuget-deps.json using the package's fetch-deps script.""" |
| 39 | + print("Building fetch-deps script...") |
| 40 | + result = subprocess.run( |
| 41 | + [ |
| 42 | + "nix", |
| 43 | + "build", |
| 44 | + ".#nethermind.fetch-deps", |
| 45 | + "--no-link", |
| 46 | + "--print-out-paths", |
| 47 | + ], |
| 48 | + capture_output=True, |
| 49 | + text=True, |
| 50 | + check=True, |
| 51 | + cwd=FLAKE_ROOT, |
| 52 | + ) |
| 53 | + fetch_deps_script = result.stdout.strip() |
| 54 | + |
| 55 | + print("Regenerating nuget-deps.json...") |
| 56 | + subprocess.run( |
| 57 | + [fetch_deps_script, str(NUGET_DEPS)], |
| 58 | + check=True, |
| 59 | + cwd=FLAKE_ROOT, |
| 60 | + ) |
| 61 | + |
| 62 | + |
| 63 | +def main() -> None: |
| 64 | + if not run_nix_update(): |
| 65 | + print("nix-update failed") |
| 66 | + sys.exit(1) |
| 67 | + |
| 68 | + update_nuget_deps() |
| 69 | + print("Done") |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + main() |
0 commit comments