2024-04-14 17:45:08 +02:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, common-updater-scripts
|
|
|
|
, coreutils
|
|
|
|
, gnugrep
|
|
|
|
, gnused
|
|
|
|
, nix
|
|
|
|
, writeScript
|
|
|
|
}:
|
2020-04-13 22:57:30 +02:00
|
|
|
|
2022-09-27 22:49:23 +02:00
|
|
|
{ name ? null
|
|
|
|
, pname ? null
|
|
|
|
, version ? null
|
|
|
|
, attrPath ? null
|
2020-04-13 22:57:30 +02:00
|
|
|
, versionLister
|
2024-06-25 00:24:25 +02:00
|
|
|
, allowedVersions ? ""
|
2020-05-04 04:11:17 +02:00
|
|
|
, ignoredVersions ? ""
|
2020-04-13 22:57:30 +02:00
|
|
|
, rev-prefix ? ""
|
2020-04-15 17:07:01 +02:00
|
|
|
, odd-unstable ? false
|
|
|
|
, patchlevel-unstable ? false
|
2020-04-13 22:57:30 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
# where to print git commands and debugging messages
|
|
|
|
fileForGitCommands = "update-git-commits.txt";
|
|
|
|
|
2024-04-14 17:45:08 +02:00
|
|
|
grep = lib.getExe gnugrep;
|
|
|
|
sed = lib.getExe gnused;
|
|
|
|
|
2020-04-13 22:57:30 +02:00
|
|
|
# shell script to update package
|
2022-09-27 22:49:23 +02:00
|
|
|
updateScript = writeScript "generic-update-script.sh" ''
|
2020-04-13 22:57:30 +02:00
|
|
|
#! ${stdenv.shell}
|
|
|
|
set -o errexit
|
|
|
|
set -x
|
|
|
|
|
2022-09-27 22:49:23 +02:00
|
|
|
name="$1"
|
|
|
|
pname="$2"
|
|
|
|
version="$3"
|
|
|
|
attr_path="$4"
|
|
|
|
version_lister="$5"
|
2024-06-25 00:24:25 +02:00
|
|
|
allowed_versions="$6"
|
|
|
|
ignored_versions="$7"
|
|
|
|
rev_prefix="$8"
|
|
|
|
odd_unstable="$9"
|
|
|
|
patchlevel_unstable="$${10}"
|
2022-09-27 22:49:23 +02:00
|
|
|
|
|
|
|
[[ -n "$name" ]] || name="$UPDATE_NIX_NAME"
|
|
|
|
[[ -n "$pname" ]] || pname="$UPDATE_NIX_PNAME"
|
|
|
|
[[ -n "$version" ]] || version="$UPDATE_NIX_OLD_VERSION"
|
|
|
|
[[ -n "$attr_path" ]] || attr_path="$UPDATE_NIX_ATTR_PATH"
|
2020-04-13 22:57:30 +02:00
|
|
|
|
|
|
|
# print header
|
2022-09-27 22:49:23 +02:00
|
|
|
echo "# $name" >> ${fileForGitCommands}
|
2020-04-13 22:57:30 +02:00
|
|
|
|
2020-05-04 04:11:17 +02:00
|
|
|
function version_is_ignored() {
|
|
|
|
local tag="$1"
|
2024-06-25 00:24:25 +02:00
|
|
|
[ -n "$ignored_versions" ] && ${grep} -E -e "$ignored_versions" <<< "$tag"
|
2020-05-04 04:11:17 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 22:57:30 +02:00
|
|
|
function version_is_unstable() {
|
|
|
|
local tag="$1"
|
|
|
|
local enforce="$2"
|
|
|
|
if [ -n "$odd_unstable" -o -n "$enforce" ]; then
|
2024-04-14 17:45:08 +02:00
|
|
|
local minor=$(echo "$tag" | ${sed} -rne 's,^[0-9]+\.([0-9]+).*,\1,p')
|
2020-04-13 22:57:30 +02:00
|
|
|
if [ $((minor % 2)) -eq 1 ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -n "$patchlevel_unstable" -o -n "$enforce" ]; then
|
2024-04-14 17:45:08 +02:00
|
|
|
local patchlevel=$(echo "$tag" | ${sed} -rne 's,^[0-9]+\.[0-9]+\.([0-9]+).*$,\1,p')
|
2020-04-13 22:57:30 +02:00
|
|
|
if ((patchlevel >= 90)); then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2022-09-15 20:32:57 +02:00
|
|
|
tags=$(sh -c "$version_lister --pname=$pname --attr-path=$attr_path --file=\"${fileForGitCommands}\"") || exit 1
|
2020-04-13 22:57:30 +02:00
|
|
|
|
|
|
|
# print available tags
|
|
|
|
for tag in $tags; do
|
|
|
|
echo "# found $pname version: $tag" >> ${fileForGitCommands}
|
|
|
|
done
|
|
|
|
|
|
|
|
# cut any revision prefix not used in the NixOS package version
|
|
|
|
if [ -n "$rev_prefix" ]; then
|
2024-04-14 17:45:08 +02:00
|
|
|
tags=$(echo "$tags" | ${grep} "^$rev_prefix")
|
|
|
|
tags=$(echo "$tags" | ${sed} -e "s,^$rev_prefix,,")
|
2020-04-13 22:57:30 +02:00
|
|
|
fi
|
2024-04-14 17:45:08 +02:00
|
|
|
tags=$(echo "$tags" | ${grep} "^[0-9]")
|
2024-06-25 00:24:25 +02:00
|
|
|
if [ -n "$allowed_versions" ]; then
|
|
|
|
tags=$(echo "$tags" | ${grep} -E -e "$allowed_versions")
|
|
|
|
fi
|
2020-04-13 22:57:30 +02:00
|
|
|
|
|
|
|
# sort the tags in decreasing order
|
|
|
|
tags=$(echo "$tags" | ${coreutils}/bin/sort --reverse --version-sort)
|
|
|
|
|
|
|
|
# find the newest tag
|
|
|
|
# do not consider development versions
|
|
|
|
for latest_tag in $tags; do
|
2020-05-04 04:11:17 +02:00
|
|
|
if version_is_ignored "$latest_tag"; then
|
|
|
|
echo "# skip ignored version: $pname-$latest_tag" >> ${fileForGitCommands}
|
|
|
|
latest_tag=
|
|
|
|
elif version_is_unstable "$latest_tag"; then
|
2020-04-13 22:57:30 +02:00
|
|
|
echo "# skip development version: $pname-$latest_tag" >> ${fileForGitCommands}
|
|
|
|
latest_tag=
|
|
|
|
else
|
|
|
|
if version_is_unstable "$latest_tag" "enforce"; then
|
|
|
|
echo "# use potential development version: $pname-$latest_tag" >> ${fileForGitCommands}
|
|
|
|
fi
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$latest_tag" ]; then
|
|
|
|
# print commands to commit the changes
|
|
|
|
if [ "$version" != "$latest_tag" ]; then
|
2022-06-30 20:59:48 +02:00
|
|
|
pfile=$(EDITOR=echo ${nix}/bin/nix edit --extra-experimental-features nix-command -f. "$attr_path")
|
2020-04-13 22:57:30 +02:00
|
|
|
echo " git add $pfile " >> ${fileForGitCommands}
|
|
|
|
echo " git commit -m '$attr_path: $version -> $latest_tag'" >> ${fileForGitCommands}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# update the nix expression
|
2023-12-26 02:54:01 +01:00
|
|
|
${common-updater-scripts}/bin/update-source-version --print-changes "$attr_path" "$latest_tag"
|
|
|
|
else
|
|
|
|
# No changes for commit protocol.
|
|
|
|
echo "[]"
|
2020-04-13 22:57:30 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "" >> ${fileForGitCommands}
|
|
|
|
'';
|
|
|
|
|
2022-09-27 22:49:23 +02:00
|
|
|
in {
|
|
|
|
name = "generic-update-script";
|
2024-06-25 00:24:25 +02:00
|
|
|
command = [ updateScript name pname version attrPath versionLister allowedVersions ignoredVersions rev-prefix odd-unstable patchlevel-unstable ];
|
2023-12-26 02:54:01 +01:00
|
|
|
supportedFeatures = [
|
|
|
|
# Stdout must contain output according to the updateScript commit protocol when the update script finishes with a non-zero exit code.
|
|
|
|
"commit"
|
|
|
|
];
|
2022-09-27 22:49:23 +02:00
|
|
|
}
|