2022-10-30 15:09:59 +00:00
|
|
|
|
{ stdenv, pkgs, lib, writeScript, python3, common-updater-scripts }:
|
2021-05-20 23:08:51 +00:00
|
|
|
|
{ packageName, attrPath ? packageName, versionPolicy ? "tagged", freeze ? false }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
|
let
|
2021-05-20 23:08:51 +00:00
|
|
|
|
python = python3.withPackages (p: [ p.requests p.libversion ]);
|
2022-03-05 16:20:37 +00:00
|
|
|
|
package = lib.attrByPath (lib.splitString "." attrPath) (throw "Cannot find attribute ‘${attrPath}’.") pkgs;
|
|
|
|
|
packageVersion = lib.getVersion package;
|
|
|
|
|
upperBound =
|
2020-04-24 23:36:52 +00: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-30 11:47:45 +00: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.";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
updateScript = writeScript "gnome-update-script" ''
|
2022-10-30 15:09:59 +00:00
|
|
|
|
#!${python}/bin/python
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
from libversion import Version
|
|
|
|
|
|
|
|
|
|
_, attr_path, package_name, package_version, version_policy, *remaining_args = sys.argv
|
|
|
|
|
|
|
|
|
|
flv_args = [
|
|
|
|
|
package_name,
|
|
|
|
|
version_policy,
|
|
|
|
|
os.environ.get("GNOME_UPDATE_STABILITY", "stable"),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if Version(latest_tag) <= Version(package_version):
|
|
|
|
|
# No newer updates found.
|
|
|
|
|
print(json.dumps([]))
|
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
latest_tag = latest_tag.strip()
|
|
|
|
|
subprocess.run(
|
|
|
|
|
[
|
|
|
|
|
"${common-updater-scripts}/bin/update-source-version",
|
|
|
|
|
attr_path,
|
|
|
|
|
latest_tag,
|
|
|
|
|
],
|
|
|
|
|
check=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
report = [
|
|
|
|
|
{
|
|
|
|
|
"attrPath": attr_path,
|
|
|
|
|
"commitBody": f"https://gitlab.gnome.org/GNOME/{package_name}/-/compare/{package_version}...{latest_tag}",
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
print(json.dumps(report))
|
2020-04-24 23:36:52 +00:00
|
|
|
|
'';
|
2022-03-05 16:20:37 +00:00
|
|
|
|
in {
|
|
|
|
|
name = "gnome-update-script";
|
|
|
|
|
command = [ updateScript attrPath packageName packageVersion versionPolicy ] ++ upperBound;
|
|
|
|
|
supportedFeatures = [
|
|
|
|
|
"commit"
|
|
|
|
|
];
|
|
|
|
|
}
|