biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / desktops / gnome / update.nix
blobce8ed07a5ae3c76c33c9f28dc0309ae16de1e5a6
1 { stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }:
2 { packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }:
4 let
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;
8   upperBound =
9     let
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}";
15     in
16     if builtins.isBool freeze then
17       lib.optionals (freeze && minorAvailable) [ upperBound ]
18     else if builtins.isString freeze then
19       [ freeze ]
20     else
21       throw "“freeze” argument needs to be either a boolean, or a version string.";
22   updateScript = writeScript "gnome-update-script" ''
23     #!${python}/bin/python
24     import json
25     import os
26     import subprocess
27     import sys
28     from libversion import Version
30     _, attr_path, package_name, package_version, version_policy, *remaining_args = sys.argv
32     flv_args = [
33         package_name,
34         version_policy,
35         os.environ.get("GNOME_UPDATE_STABILITY", "stable"),
36     ]
38     match remaining_args:
39         case []:
40             pass
41         case [upper_bound]:
42             flv_args.append(f"--upper-bound={upper_bound}")
43         case other:
44             print("gnome-update-script: Received too many arguments.", file=sys.stderr)
45             sys.exit(1)
47     latest_tag = subprocess.check_output(
48         [
49             "${python}/bin/python",
50             "${./find-latest-version.py}",
51             *flv_args,
52         ],
53         encoding="utf-8",
54     )
56     if Version(latest_tag) <= Version(package_version):
57         # No newer updates found.
58         print(json.dumps([]))
59         sys.exit(0)
61     latest_tag = latest_tag.strip()
62     subprocess.run(
63         [
64             "${common-updater-scripts}/bin/update-source-version",
65             attr_path,
66             latest_tag,
67         ],
68         check=True,
69     )
71     report = [
72         {
73             "attrPath": attr_path,
74             "commitBody": f"https://gitlab.gnome.org/GNOME/{package_name}/-/compare/{package_version}...{latest_tag}",
75         },
76     ]
78     print(json.dumps(report))
79   '';
80 in {
81   name = "gnome-update-script";
82   command = [ updateScript attrPath packageName packageVersion versionPolicy ] ++ upperBound;
83   supportedFeatures = [
84     "commit"
85   ];