2020-04-24 23:36:52 +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 ]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
upperBoundFlag =
|
|
|
|
|
let
|
2020-05-03 17:38:23 +00:00
|
|
|
|
package = lib.attrByPath (lib.splitString "." attrPath) (throw "Cannot find attribute ‘${attrPath}’.") pkgs;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
packageVersion = lib.getVersion package;
|
|
|
|
|
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}";
|
2020-05-03 17:38:23 +00:00
|
|
|
|
in lib.optionalString (freeze && minorAvailable) ''--upper-bound="${upperBound}"'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
updateScript = writeScript "gnome-update-script" ''
|
|
|
|
|
#!${stdenv.shell}
|
|
|
|
|
set -o errexit
|
|
|
|
|
package_name="$1"
|
|
|
|
|
attr_path="$2"
|
|
|
|
|
version_policy="$3"
|
|
|
|
|
PATH=${lib.makeBinPath [ common-updater-scripts python ]}
|
|
|
|
|
latest_tag=$(python "${./find-latest-version.py}" "$package_name" "$version_policy" "stable" ${upperBoundFlag})
|
|
|
|
|
update-source-version "$attr_path" "$latest_tag"
|
|
|
|
|
'';
|
|
|
|
|
in [ updateScript packageName attrPath versionPolicy ]
|