2022-10-25 15:17:44 +03:00
|
|
|
|
{ stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }:
|
2021-03-21 02:57:24 +03:00
|
|
|
|
{ packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }:
|
2017-12-25 12:46:52 +03:00
|
|
|
|
|
|
|
|
|
let
|
2021-03-21 02:57:24 +03:00
|
|
|
|
python = python3.withPackages (p: [ p.requests p.libversion ]);
|
2022-02-16 20:52:36 +03:00
|
|
|
|
package = lib.attrByPath (lib.splitString "." attrPath) (throw "Cannot find attribute ‘${attrPath}’.") pkgs;
|
|
|
|
|
packageVersion = lib.getVersion package;
|
2022-02-16 21:13:24 +03:00
|
|
|
|
upperBound =
|
2020-04-25 01:04:31 +03:00
|
|
|
|
let
|
|
|
|
|
versionComponents = lib.versions.splitVersion packageVersion;
|
|
|
|
|
minorVersion = lib.versions.minor packageVersion;
|
|
|
|
|
minorAvailable = builtins.length versionComponents > 1 && builtins.match "[0-9]+" minorVersion != null;
|
|
|
|
|
nextMinor = builtins.fromJSON minorVersion + 1;
|
|
|
|
|
upperBound = "${lib.versions.major packageVersion}.${builtins.toString nextMinor}";
|
2022-09-24 15:58:58 +03:00
|
|
|
|
in
|
|
|
|
|
if builtins.isBool freeze then
|
|
|
|
|
lib.optionals (freeze && minorAvailable) [ upperBound ]
|
|
|
|
|
else if builtins.isString freeze then
|
|
|
|
|
[ freeze ]
|
|
|
|
|
else
|
|
|
|
|
throw "“freeze” argument needs to be either a boolean, or a version string.";
|
2018-12-02 02:50:37 +03:00
|
|
|
|
updateScript = writeScript "gnome-update-script" ''
|
2022-10-25 15:17:44 +03:00
|
|
|
|
#!${python}/bin/python
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2022-10-25 12:38:59 +03:00
|
|
|
|
from libversion import Version
|
2022-02-16 21:13:24 +03:00
|
|
|
|
|
2022-10-25 15:17:44 +03:00
|
|
|
|
_, attr_path, package_name, package_version, version_policy, *remaining_args = sys.argv
|
2022-02-16 21:13:24 +03:00
|
|
|
|
|
2022-10-25 15:17:44 +03:00
|
|
|
|
flv_args = [
|
|
|
|
|
package_name,
|
|
|
|
|
version_policy,
|
|
|
|
|
os.environ.get("GNOME_UPDATE_STABILITY", "stable"),
|
|
|
|
|
]
|
2022-02-16 21:13:24 +03:00
|
|
|
|
|
2022-10-25 15:17:44 +03:00
|
|
|
|
match remaining_args:
|
|
|
|
|
case []:
|
|
|
|
|
pass
|
|
|
|
|
case [upper_bound]:
|
|
|
|
|
flv_args.append(f"--upper-bound={upper_bound}")
|
|
|
|
|
case other:
|
|
|
|
|
print("gnome-update-script: Received too many arguments.", file=sys.stderr)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
latest_tag = subprocess.check_output(
|
|
|
|
|
[
|
|
|
|
|
"${python}/bin/python",
|
|
|
|
|
"${./find-latest-version.py}",
|
|
|
|
|
*flv_args,
|
|
|
|
|
],
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
2022-10-25 12:38:59 +03:00
|
|
|
|
|
|
|
|
|
if Version(latest_tag) <= Version(package_version):
|
|
|
|
|
# No newer updates found.
|
|
|
|
|
print(json.dumps([]))
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
2022-10-25 15:17:44 +03:00
|
|
|
|
latest_tag = latest_tag.strip()
|
|
|
|
|
subprocess.run(
|
|
|
|
|
[
|
|
|
|
|
"${common-updater-scripts}/bin/update-source-version",
|
|
|
|
|
attr_path,
|
|
|
|
|
latest_tag,
|
|
|
|
|
],
|
|
|
|
|
check=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
report = [
|
|
|
|
|
{
|
2022-10-25 16:10:21 +03:00
|
|
|
|
"attrPath": attr_path,
|
2022-10-25 15:17:44 +03:00
|
|
|
|
"commitBody": f"https://gitlab.gnome.org/GNOME/{package_name}/-/compare/{package_version}...{latest_tag}",
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
print(json.dumps(report))
|
2018-12-02 02:50:37 +03:00
|
|
|
|
'';
|
2022-02-16 20:52:36 +03:00
|
|
|
|
in {
|
|
|
|
|
name = "gnome-update-script";
|
2022-02-16 21:13:24 +03:00
|
|
|
|
command = [ updateScript attrPath packageName packageVersion versionPolicy ] ++ upperBound;
|
2022-02-16 20:52:36 +03:00
|
|
|
|
supportedFeatures = [
|
|
|
|
|
"commit"
|
|
|
|
|
];
|
|
|
|
|
}
|