unstableGitUpdater: Use stableVersion, update to new format, offer hardcoded 0 version

This commit is contained in:
OPNA2608 2024-01-12 12:04:56 +01:00
parent 51403ecd19
commit 222da55eef

View File

@ -10,8 +10,8 @@
# commit. # commit.
{ url ? null # The git url, if empty it will be set to src.gitRepoUrl { url ? null # The git url, if empty it will be set to src.gitRepoUrl
, branch ? null , branch ? null
, stableVersion ? false # Use version format according to RFC 107 (i.e. LAST_TAG+date=YYYY-MM-DD) , 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 when using stable version , tagPrefix ? "" # strip this prefix from a tag name
, shallowClone ? true , shallowClone ? true
}: }:
@ -21,7 +21,7 @@ let
url="" url=""
branch="" branch=""
use_stable_version="" hardcode_zero_version=""
tag_prefix="" tag_prefix=""
shallow_clone="" shallow_clone=""
@ -35,8 +35,8 @@ let
--branch=*) --branch=*)
branch="''${flag#*=}" branch="''${flag#*=}"
;; ;;
--use-stable-version) --hardcode-zero-version)
use_stable_version=1 hardcode_zero_version=1
;; ;;
--tag-prefix=*) --tag-prefix=*)
tag_prefix="''${flag#*=}" tag_prefix="''${flag#*=}"
@ -78,9 +78,8 @@ let
pushd "$tmpdir" pushd "$tmpdir"
commit_date="$(${git}/bin/git show -s --pretty='format:%cs')" commit_date="$(${git}/bin/git show -s --pretty='format:%cs')"
commit_sha="$(${git}/bin/git show -s --pretty='format:%H')" commit_sha="$(${git}/bin/git show -s --pretty='format:%H')"
if [[ -z "$use_stable_version" ]]; then last_tag=""
new_version="unstable-$commit_date" if [[ -z "$hardcode_zero_version" ]]; then
else
depth=100 depth=100
while (( $depth < 10000 )); do while (( $depth < 10000 )); do
last_tag="$(${git}/bin/git describe --tags --abbrev=0 2> /dev/null || true)" last_tag="$(${git}/bin/git describe --tags --abbrev=0 2> /dev/null || true)"
@ -91,14 +90,20 @@ let
depth=$(( $depth * 2 )) depth=$(( $depth * 2 ))
done done
if [[ -z "$last_tag" ]]; then if [[ -z "$last_tag" ]]; then
echo "Cound not found a tag within last 10000 commits" > /dev/stderr echo "Cound not find a tag within last 10000 commits" > /dev/stderr
exit 1 exit 1
fi fi
if [[ -n "$tag_prefix" ]]; then if [[ -n "$tag_prefix" ]]; then
last_tag="''${last_tag#$tag_prefix}" last_tag="''${last_tag#$tag_prefix}"
fi fi
new_version="$last_tag+date=$commit_date" if [[ ! "$last_tag" =~ ^[[:digit:]] ]]; then
echo "Last tag '$last_tag' (after removing prefix '$tag_prefix') does not start with a digit" > /dev/stderr
exit 1
fi
else
last_tag="0"
fi fi
new_version="$last_tag-unstable-$commit_date"
popd popd
# ${coreutils}/bin/rm -rf "$tmpdir" # ${coreutils}/bin/rm -rf "$tmpdir"
@ -113,11 +118,11 @@ in
[ [
updateScript updateScript
"--url=${builtins.toString url}" "--url=${builtins.toString url}"
"--tag-prefix=${tagPrefix}"
] ++ lib.optionals (branch != null) [ ] ++ lib.optionals (branch != null) [
"--branch=${branch}" "--branch=${branch}"
] ++ lib.optionals stableVersion [ ] ++ lib.optionals hardcodeZeroVersion [
"--use-stable-version" "--hardcode-zero-version"
"--tag-prefix=${tagPrefix}"
] ++ lib.optionals shallowClone [ ] ++ lib.optionals shallowClone [
"--shallow-clone" "--shallow-clone"
] ]