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