milahu / nixpkgs

Nix Packages collection
MIT License
0 stars 0 forks source link

nix-init: sort git tags by date #40

Open milahu opened 3 months ago

milahu commented 3 months ago

example: https://github.com/alejandroautalan/pygubu/tags

expectd: latest version by date is v0.34

actual: sort by version

$ git ls-remote https://github.com/alejandroautalan/pygubu | grep refs/tags/ | sort -k2 -V -r | head -n1 
a730511be5ea10c7dbb1356c182d7f20847e7543        refs/tags/v10.9

also wrong: use the raw sort order of git ls-remote

$ git ls-remote https://github.com/alejandroautalan/pygubu | grep refs/tags/ | head -n1 
11ee7b385031d493faa241bf81e407c69c5b67ef        refs/tags/v0.10.3

expected: sort by date

with https://stackoverflow.com/a/78242565/10440128

repo=alejandroautalan/pygubu

curl -s "https://github.com/$repo/tags" |
grep -oE \
-e ' href="/'"$repo"'/releases/tag/[^"]+" data-' \
-e ' datetime="[^"]+"' \
-e ' href="/'"$repo"'/commit/[0-9a-f]{40,}"' |
cut -d'"' -f2 |
sed -E 's,^.*/(commit|releases/tag)/,,' |
while read name && read time && read hash; do
  echo "$time $hash $name"
done

output for https://github.com/alejandroautalan/pygubu/tags

2024-02-13T01:27:59Z 7da91e4c94231974770b98b1955e64ed5e888ea8 v0.34
2024-02-11T04:50:12Z 4463c6f3f3fd95be1d99ac518965ed228cd1bb2e v0.33
2024-01-07T01:37:37Z 2d65b4896cb7a95db5b30adbad9c79bcb06f9d54 v0.32
2023-05-29T00:56:28Z 52e2d55064b67fa779030e54670cab137ba3421e v0.31
2023-03-02T04:09:50Z 7914476dd8a0ea0f22a213dcde9c17257d9e6d65 v0.30
2023-01-17T17:54:15Z 880adeaa5189d435920d5d05426b9004b611d927 v0.29
2022-12-12T04:06:11Z 99b7a99fb5a60d7785a29d1687b4197c56eefcae v0.28
2022-11-19T20:46:25Z 402c865bf8fcd6b2869d08aaf5e5896bb63eda99 v0.27
2022-11-01T03:34:52Z d675b07f987dd57cc16dcce085f572ab9b655896 v0.26.2
2022-09-27T21:50:02Z 87ef459144583e81f190279e59b0879570b0bd40 v0.26.1

probably both solutions can be wrong in rare cases ...

but i would expect that "sort by date" is more stable since mistakes are made early in projects and the development workflow gets better over time

ping @figsoda @pschmitt @Ninja3047