2022-10-25 14:17:44 +02:00
|
|
|
|
{ stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }:
|
2021-03-21 00:57:24 +01:00
|
|
|
|
{ packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }:
|
2017-12-25 10:46:52 +01:00
|
|
|
|
|
|
|
|
|
let
|
2021-03-21 00:57:24 +01:00
|
|
|
|
python = python3.withPackages (p: [ p.requests p.libversion ]);
|
2022-02-16 18:52:36 +01:00
|
|
|
|
package = lib.attrByPath (lib.splitString "." attrPath) (throw "Cannot find attribute ‘${attrPath}’.") pkgs;
|
|
|
|
|
packageVersion = lib.getVersion package;
|
2022-02-16 19:13:24 +01:00
|
|
|
|
upperBound =
|
2020-04-25 00:04:31 +02: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 14:58:58 +02: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 00:50:37 +01:00
|
|
|
|
updateScript = writeScript "gnome-update-script" ''
|
2022-10-25 14:17:44 +02:00
|
|
|
|
#!${python}/bin/python
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
2022-10-25 11:38:59 +02:00
|
|
|
|
from libversion import Version
|
2022-02-16 19:13:24 +01:00
|
|
|
|
|
2022-10-25 14:17:44 +02:00
|
|
|
|
_, attr_path, package_name, package_version, version_policy, *remaining_args = sys.argv
|
2022-02-16 19:13:24 +01:00
|
|
|
|
|
2022-10-25 14:17:44 +02:00
|
|
|
|
flv_args = [
|
|
|
|
|
package_name,
|
|
|
|
|
version_policy,
|
|
|
|
|
os.environ.get("GNOME_UPDATE_STABILITY", "stable"),
|
|
|
|
|
]
|
2022-02-16 19:13:24 +01:00
|
|
|
|
|
2022-10-25 14:17:44 +02: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 11:38:59 +02:00
|
|
|
|
|
|
|
|
|
if Version(latest_tag) <= Version(package_version):
|
|
|
|
|
# No newer updates found.
|
|
|
|
|
print(json.dumps([]))
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
2022-10-25 14:17:44 +02: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 15:10:21 +02:00
|
|
|
|
"attrPath": attr_path,
|
2022-10-25 14:17:44 +02:00
|
|
|
|
"commitBody": f"https://gitlab.gnome.org/GNOME/{package_name}/-/compare/{package_version}...{latest_tag}",
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
print(json.dumps(report))
|
2018-12-02 00:50:37 +01:00
|
|
|
|
'';
|
2022-02-16 18:52:36 +01:00
|
|
|
|
in {
|
|
|
|
|
name = "gnome-update-script";
|
2022-02-16 19:13:24 +01:00
|
|
|
|
command = [ updateScript attrPath packageName packageVersion versionPolicy ] ++ upperBound;
|
2022-02-16 18:52:36 +01:00
|
|
|
|
supportedFeatures = [
|
|
|
|
|
"commit"
|
|
|
|
|
];
|
|
|
|
|
}
|