evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / in / incus / update.py
blob1db118a596f916f1ac1c03a887dad421e10c55b7
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python -p python3 python3Packages.looseversion common-updater-scripts nurl
4 import argparse
5 import json
6 import os
7 import re
8 from looseversion import LooseVersion
9 from subprocess import run
11 parser = argparse.ArgumentParser()
12 parser.add_argument("--lts", action="store_true")
13 parser.add_argument("--regex")
14 args = parser.parse_args()
16 nixpkgs_path = os.environ["PWD"]
18 attr = "incus"
19 file = f"pkgs/by-name/in/incus/package.nix"
20 if args.lts:
21 attr = "incus-lts"
22 file = f"pkgs/by-name/in/incus/lts.nix"
24 tags = (
25 run(["list-git-tags", "--url=https://github.com/lxc/incus"], capture_output=True)
26 .stdout.decode("utf-8")
27 .splitlines()
29 tags = [t.lstrip("v") for t in tags]
31 latest_version = "0"
32 for tag in tags:
33 if args.regex != None and not re.match(args.regex, tag):
34 continue
36 if LooseVersion(tag) > LooseVersion(latest_version):
37 latest_version = tag
39 current_version = (
40 run(
41 ["nix", "eval", "--raw", "-f", "default.nix", f"{attr}.version"],
42 capture_output=True,
44 .stdout.decode("utf-8")
45 .strip()
48 if LooseVersion(latest_version) <= LooseVersion(current_version):
49 print("No update available")
50 exit(0)
52 print(f"Found new version {latest_version} > {current_version}")
54 run(["update-source-version", attr, latest_version, f"--file={file}"])
56 current_vendor_hash = (
57 run(
59 "nix-instantiate",
60 ".",
61 "--eval",
62 "--strict",
63 "-A",
64 f"{attr}.goModules.drvAttrs.outputHash",
65 "--json",
67 capture_output=True,
69 .stdout.decode("utf-8")
70 .strip()
71 .strip('"')
74 latest_vendor_hash = (
75 run(
76 ["nurl", "--expr", f"(import {nixpkgs_path} {{}}).{attr}.goModules"],
77 capture_output=True,
79 .stdout.decode("utf-8")
80 .strip()
83 with open(file, "r+") as f:
84 file_content = f.read()
85 file_content = re.sub(current_vendor_hash, latest_vendor_hash, file_content)
86 f.seek(0)
87 f.write(file_content)