unstableGitUpdater: Add option to run the tag through a converter program

This commit is contained in:
OPNA2608 2024-02-28 10:19:51 +01:00
parent 3cd4a35e71
commit c145f59d48

View File

@ -12,6 +12,7 @@
, branch ? null , branch ? null
, hardcodeZeroVersion ? false # Use a made-up version "0" instead of latest tag. Use when there is no previous release, or the project's tagging system is incompatible with what we expect from versions , hardcodeZeroVersion ? false # Use a made-up version "0" instead of latest tag. Use when there is no previous release, or the project's tagging system is incompatible with what we expect from versions
, tagPrefix ? "" # strip this prefix from a tag name , tagPrefix ? "" # strip this prefix from a tag name
, tagConverter ? null # A command to convert more complex tag formats. It receives the git tag via stdin and should convert it into x.y.z format to stdout
, shallowClone ? true , shallowClone ? true
}: }:
@ -23,6 +24,7 @@ let
branch="" branch=""
hardcode_zero_version="" hardcode_zero_version=""
tag_prefix="" tag_prefix=""
tag_converter=""
shallow_clone="" shallow_clone=""
while (( $# > 0 )); do while (( $# > 0 )); do
@ -41,6 +43,9 @@ let
--tag-prefix=*) --tag-prefix=*)
tag_prefix="''${flag#*=}" tag_prefix="''${flag#*=}"
;; ;;
--tag-converter=*)
tag_converter="''${flag#*=}"
;;
--shallow-clone) --shallow-clone)
shallow_clone=1 shallow_clone=1
;; ;;
@ -105,6 +110,9 @@ let
if [[ -n "$tag_prefix" ]]; then if [[ -n "$tag_prefix" ]]; then
last_tag="''${last_tag#$tag_prefix}" last_tag="''${last_tag#$tag_prefix}"
fi fi
if [[ -n "$tag_converter" ]]; then
last_tag="$(echo ''${last_tag#$tag_prefix} | ''${tag_converter})"
fi
if [[ ! "$last_tag" =~ ^[[:digit:]] ]]; then if [[ ! "$last_tag" =~ ^[[:digit:]] ]]; then
echo "Last tag '$last_tag' (after removing prefix '$tag_prefix') does not start with a digit" > /dev/stderr echo "Last tag '$last_tag' (after removing prefix '$tag_prefix') does not start with a digit" > /dev/stderr
exit 1 exit 1
@ -130,6 +138,8 @@ in
"--tag-prefix=${tagPrefix}" "--tag-prefix=${tagPrefix}"
] ++ lib.optionals (branch != null) [ ] ++ lib.optionals (branch != null) [
"--branch=${branch}" "--branch=${branch}"
] ++ lib.optionals (tagConverter != null) [
"--tag-converter=${tagConverter}"
] ++ lib.optionals hardcodeZeroVersion [ ] ++ lib.optionals hardcodeZeroVersion [
"--hardcode-zero-version" "--hardcode-zero-version"
] ++ lib.optionals shallowClone [ ] ++ lib.optionals shallowClone [