|
| 1 | +import os |
1 | 2 | import requests
|
2 | 3 | import subprocess
|
3 | 4 | import shutil
|
4 | 5 | import sys
|
| 6 | +import tempfile |
| 7 | +import tomllib |
| 8 | + |
| 9 | +from string import Template |
| 10 | + |
| 11 | +# A Hydra eval id must be passed as the argument to this script or an empty |
| 12 | +# string to use latest eval on Hydra |
| 13 | +# TODO: using an empty string is not the cleanest |
| 14 | +# TODO: print script usage |
| 15 | +eval_id = sys.argv[1] |
5 | 16 |
|
6 | 17 | response = requests.get('https://hydra.nixos.org/jobset/experimental-nix-installer/experimental-installer/evals', headers={'Accept': 'application/json'})
|
| 18 | +evals = response.json()['evals'] |
| 19 | + |
| 20 | +if eval_id is not None and eval_id != "": |
| 21 | + eval_id_int = int(eval_id) |
| 22 | + ids = [eval['id'] for eval in evals] |
| 23 | + hydra_eval = next( eval for eval in evals if eval['id'] == eval_id_int ) |
| 24 | +else: |
| 25 | + hydra_eval = evals[0] |
7 | 26 |
|
8 |
| -hydra_eval = response.json()['evals'][0] |
| 27 | + rev = subprocess.run( |
| 28 | + ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, check=True, text=True |
| 29 | + ).stdout.strip() |
| 30 | + |
| 31 | + if not rev in hydra_eval["flake"]: |
| 32 | + raise RuntimeError( |
| 33 | + f"Expected flake with rev {rev} but found flake {hydra_eval['flake']}" |
| 34 | + ) |
9 | 35 |
|
10 | 36 | installers = []
|
11 | 37 |
|
|
22 | 48 | subprocess.call(f"nix-store -r {installer_url}", shell=True)
|
23 | 49 | installers.append((installer_url, system))
|
24 | 50 | else:
|
| 51 | + print( |
| 52 | + f"Build {build_id} not finished. Check status at https://hydra.nixos.org/eval/{hydra_eval['id']}#tabs-unfinished" |
| 53 | + ) |
25 | 54 | sys.exit(0)
|
26 | 55 |
|
27 |
| -subprocess.run(["git", "fetch", "origin", "prerelease"], check=True) |
28 |
| -subprocess.run(["git", "checkout", "-b", "prerelease", "origin/prerelease"], check=True) |
| 56 | +with open("Cargo.toml", "rb") as f: |
| 57 | + cargo_toml = tomllib.load(f) |
| 58 | +version = cargo_toml["package"]["version"] |
| 59 | + |
| 60 | +with tempfile.TemporaryDirectory() as tmpdirname: |
| 61 | + release_files = [] |
| 62 | + for installer_url, system in installers: |
| 63 | + installer_file = f"{tmpdirname}/nix-installer-{system}" |
| 64 | + release_files.append(installer_file) |
| 65 | + print(f"Copying {installer_url} to {installer_file}") |
| 66 | + shutil.copy(f"{installer_url}/bin/nix-installer", installer_file) |
| 67 | + |
| 68 | + # Subsitute version in nix-installer.sh |
| 69 | + original_file = "nix-installer.sh" |
| 70 | + |
| 71 | + with open(original_file, "r") as nix_installer_sh: |
| 72 | + nix_installer_sh_contents = nix_installer_sh.read() |
| 73 | + |
| 74 | + template = Template(nix_installer_sh_contents) |
| 75 | + updated_content = template.safe_substitute(assemble_installer_templated_version=version) |
| 76 | + |
| 77 | + # Write the modified content to the output file |
| 78 | + substituted_file=f"{tmpdirname}/nix-installer.sh" |
| 79 | + with open(substituted_file, "w", encoding="utf-8") as output_file: |
| 80 | + output_file.write(updated_content) |
| 81 | + release_files.append(substituted_file) |
29 | 82 |
|
30 |
| -for installer_url, system in installers: |
31 |
| - shutil.copy(f"{installer_url}/bin/nix-installer", f"nix-installer-{system}") |
| 83 | + subprocess.run( |
| 84 | + [ |
| 85 | + "gh", |
| 86 | + "release", |
| 87 | + "create", |
| 88 | + "--notes", |
| 89 | + f"Release experimental nix installer v{version}", |
| 90 | + "--title", |
| 91 | + f"v{version}", |
| 92 | + "--draft", |
| 93 | + version, |
| 94 | + *release_files, |
| 95 | + ], |
| 96 | + check=True, |
| 97 | + ) |
0 commit comments