1 { stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }:
2 { packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }:
5 python = python3.withPackages (p: [ p.requests p.libversion ]);
6 package = lib.attrByPath (lib.splitString "." attrPath) (throw "Cannot find attribute ‘${attrPath}’.") pkgs;
7 packageVersion = lib.getVersion package;
10 versionComponents = lib.versions.splitVersion packageVersion;
11 minorVersion = lib.versions.minor packageVersion;
12 minorAvailable = builtins.length versionComponents > 1 && builtins.match "[0-9]+" minorVersion != null;
13 nextMinor = builtins.fromJSON minorVersion + 1;
14 upperBound = "${lib.versions.major packageVersion}.${builtins.toString nextMinor}";
16 if builtins.isBool freeze then
17 lib.optionals (freeze && minorAvailable) [ upperBound ]
18 else if builtins.isString freeze then
21 throw "“freeze” argument needs to be either a boolean, or a version string.";
22 updateScript = writeScript "gnome-update-script" ''
23 #!${python}/bin/python
28 from libversion import Version
30 _, attr_path, package_name, package_version, version_policy, *remaining_args = sys.argv
35 os.environ.get("GNOME_UPDATE_STABILITY", "stable"),
42 flv_args.append(f"--upper-bound={upper_bound}")
44 print("gnome-update-script: Received too many arguments.", file=sys.stderr)
47 latest_tag = subprocess.check_output(
49 "${python}/bin/python",
50 "${./find-latest-version.py}",
56 if Version(latest_tag) <= Version(package_version):
57 # No newer updates found.
61 latest_tag = latest_tag.strip()
64 "${common-updater-scripts}/bin/update-source-version",
73 "attrPath": attr_path,
74 "commitBody": f"https://gitlab.gnome.org/GNOME/{package_name}/-/compare/{package_version}...{latest_tag}",
78 print(json.dumps(report))
81 name = "gnome-update-script";
82 command = [ updateScript attrPath packageName packageVersion versionPolicy ] ++ upperBound;