Grep for the Latest Release Version of a git Repo

205 views Asked by At

Doing this to get the latest release version from the Docker Compose git repo gets the latest version without a v prefix in the release tag, but I need the v prefix to be included if the release tag contains it.

COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oE "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | sort --version-sort | tail -n 1`
echo $COMPOSE_VERSION
2.14.2   # desired: v2.14.2

I intent to use COMPOSE_VERSION to construct the download link for the release, so its important to have the v prefix if its found in the release tag.

sh -c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"

Can the grep command for COMPOSE_VERSION be modified to achieve this?


Output of git ls-remote https://github.com/docker/compose | grep refs/tags

$ git ls-remote https://github.com/docker/compose | grep refs/tags
8998bd1adc3def9e6e55b654b16415a46e1ca28b    refs/tags/0.0.1
e0a21e3df48bf7f4b564d7b4802c2b647fb7f8e8    refs/tags/0.0.2
573fae089f665130d056f78f50a98235aeb959ee    refs/tags/0.1.0
cbfbb9899d4772c9872fcf57eeb9de51b409a652    refs/tags/0.1.1
deb7f3c5b602d49e36e18bba120ad554de9b44f2    refs/tags/0.1.2
b43b007b9288d098e854b93f48cce82788bd6760    refs/tags/0.1.3
ddc721ec8ac62c0081ce403ab621b193461197cd    refs/tags/0.1.4
53958cf9df2df77bd8d5c184555acae9af0cd431    refs/tags/0.2.0
a8bc51b22994928482b4d5dd4824abd9133736ce    refs/tags/0.2.1
d368e2fca96486c2a19e24912f63d3e43308dcbc    refs/tags/0.2.2
8c16961afd869172e02db2797f7787e8367c7b83    refs/tags/0.3.0
f5cf9b60b2d1eef601ccd80efe5feb33bcf473f7    refs/tags/0.3.1
9164125177825257be263dee126c42bf32be8241    refs/tags/0.3.2
6dc1a404d5db8b5cf0ffed5298160d304520ab1f    refs/tags/0.4.0
b99bb64487ed699d94d71fe1187635cd7c9494bd    refs/tags/0.4.1
034b66fedbb219f07512ae9ce2c1cf7221830716    refs/tags/0.4.2
e117a7822d4e5224e826b9df2aebfab62f4f8eda    refs/tags/0.5.0
0021a0646892fe9d88e861796e89d7a470b997ca    refs/tags/0.5.1
847ec5b559cf97296c80624774cc4210bbabcac6    refs/tags/0.5.2
6580c5609c11cf90253a8a71088586c161916564    refs/tags/1.0.0
3f4b16181ddce63fd27b31ec008181ed73c35af5    refs/tags/1.0.1
03535a61588e205dfe687707996b1e0d35d065cd    refs/tags/1.1.0
df3221df61801a7162af7e5f01361d4ce2ed1b53    refs/tags/1.1.0-rc1
e4d6a2c2408f58a3e23bf3e117fcefe3f3c14eed    refs/tags/1.1.0-rc2
4bd6f1a0d834296e80425db1bfaf1536ea540697    refs/tags/1.10.0
ecff6f1a9a6f56eeaff378da814dafde9dd53b02    refs/tags/1.10.0-rc1
fb241d0906cd667fec0a36449883d905a00992a1    refs/tags/1.10.0-rc2
b25273892d7c03d8bfa25239b1fc5d5a2e43353d    refs/tags/1.10.1
6de18066586c01eb03091c80da30cbeef681afdd    refs/tags/1.11.0
0ea24e7a805a84f82111de7224961b4ac0c3ee3d    refs/tags/1.11.0-rc1
7c5d5e403111441dabd9c199e6a065649167c700    refs/tags/1.11.1
dfed245b57e9430994741ab05558627e6827d7fa    refs/tags/1.11.2
b31ff33aca5f20292ac1d0b68712f917c538af43    refs/tags/1.12.0
5e0a7939458ee9c1533724b15b27e82b86864418    refs/tags/1.12.0-rc1
08dc2a41524e2bb476aec34a9864e13e325665c3    refs/tags/1.12.0-rc2
1719ceb881890f84d97df7eaa2d000b205879cc8    refs/tags/1.13.0
38af51314e295ad14d24c2a323a164a787e77bf7    refs/tags/1.13.0-rc1
c7bdf9e3927cdcae7db3fe48d0d7c3b582d64541    refs/tags/1.14.0
c18a7ad946f8963db14bd159bbfee4ae9d486b94    refs/tags/1.14.0-rc1
24dae73c6349bf350b6c8bdc37866ca3aabeaa5c    refs/tags/1.14.0-rc2
e12f3b94653807c7e070b041c6a500b0baa88462    refs/tags/1.15.0
2188098f791cd8cc583f5e5002ce4b07c3aa756c    refs/tags/1.15.0-rc1
ea60ca176c558e7d7dc0cd91e90a1d87f687ae9e    refs/tags/1.16.0
9bea70a1dcd936ac555ada74f716c04711ffba4a    refs/tags/1.16.0-rc1
92c936a867d1c8e198bbb669642a21881ce1c17f    refs/tags/1.16.0-rc2
6d1ac219b4c400f1aded03c53244ed452876d61f    refs/tags/1.16.1
ac53b73e7958b825f7235a661c208f4f6f6e90f7    refs/tags/1.17.0
a0f95afcd1cdf781e7eccdc9ed65d27c260e8534    refs/tags/1.17.0-rc1
6d101fb0686a6e380657aaf974bc3efd1471535e    refs/tags/1.17.1
8dd22a962a4295ada9c8a45a5c58d02f8f66333f    refs/tags/1.18.0
e96dfbac2a7982b8703abd3774ab661516096931    refs/tags/1.18.0-rc1
189468b07f295c8df8997e770701be31159ef54e    refs/tags/1.18.0-rc2
9e633ef35af238fd4d375d7bbfc2450316b21387    refs/tags/1.19.0
d149ccd3125604fd7aebba307c1b97a1b1070090    refs/tags/1.19.0-rc1
a186c3142b80d99c62995f6f36e64867ed883701    refs/tags/1.19.0-rc2
cdd02822f53a13d91d590578b8617f217a076393    refs/tags/1.19.0-rc3
39ae91c81c2dd8cddd2cbb3601dee8349a596340    refs/tags/1.2.0
07ea20efe489c4101b6a08fe6f8726923705dfaa    refs/tags/1.2.0rc1
ff3a5451fec509a7eee18ab4ac6431ab713f016a    refs/tags/1.2.0rc2
f69de1166fbc181175a5a76372d0255cd4a46982    refs/tags/1.2.0rc3
b3f23e2d173bdd352a8006b89e3cc70a58e84d2b    refs/tags/1.2.0rc4
ca8d3c6c18d314a7314e383b53472127e00a523f    refs/tags/1.20.0
86428af5bcb96975e4379074c54c1e6c088603d5    refs/tags/1.20.0-rc1
8c4af54257daae922010f75dac3f259fb0f3905d    refs/tags/1.20.0-rc2
5d8c71b2c630f9eeeed7c755bb8dad4b24f8cdb7    refs/tags/1.20.1
5920eb082ca60c5e66fdd856b28807b0c97a33dc    refs/tags/1.21.0
1d329808cc5c8b6f97a7fd23503f0a48c432f302    refs/tags/1.21.0-rc1
456ff4be0f1d3580cfcd98c26b913117ee5478b4    refs/tags/1.21.1
0898c783ad2e0d01bd55b47fcb9eb7183edc1015    refs/tags/1.21.2
e20d808ed2a0d542c6e65de4818a2ee27073d774    refs/tags/1.22.0
bdd7d476405c5b66845a5e40ea1009e6bedbf3b0    refs/tags/1.22.0-rc1
5985d046e3cd42f784d6af43b14deafd16d21528    refs/tags/1.22.0-rc2
a7ca78d854674b8601f06f8d5f790050a7b14744    refs/tags/1.23.0
c5d5d42158971ad9763a378e624311e66d7a65c8    refs/tags/1.23.0-rc1
82e265b806d1303920f47363aea656045be4e3fb    refs/tags/1.23.0-rc2
7bd4291f902bd03a179fe9b87fb8fac04f62e207    refs/tags/1.23.0-rc3
3727fd3fb96ddc5ac43dd4921500133e0dd32827    refs/tags/1.23.1
b0c10cb876496c68bb23447e81eb8f3258e52bb7    refs/tags/1.23.2
d9fa8158c39f9f4b9d60865e7cf44909b57f5c31    refs/tags/1.24.0
82db4fd4f225ece55bf464126411e8687f3f3a38    refs/tags/1.24.0-rc1
3a3288c54bbea4aa197a3eb9e7c453d664c469e9    refs/tags/1.24.0-rc3
85d940909e941915ea5a5e1e5c2f8bd0a086948e    refs/tags/1.24.1
4038169d96ca176542c5265e21f4b18ee64b1dd9    refs/tags/1.25.0
2bc4161526162317934556dd702c19b70a2d8632    refs/tags/1.25.0-rc1
2c668e237d07b518630139b185f3337dbcbd5250    refs/tags/1.25.0-rc2
ea22d5821c849a6a83da551f9d10dcd5a645bd65    refs/tags/1.25.0-rc3
f6b6cd22df73466cbe089b4545212905e0a27e31    refs/tags/1.25.0-rc4
cc93c9768921a6d91e511a33c3a4bcba74a6f411    refs/tags/1.25.1
a23f39127e8fdf359d9fab199fa5745066b80c8b    refs/tags/1.25.1-rc1
e9f9a1e9e1edabe25f3c6494aa7f3a5a5f7db7d2    refs/tags/1.25.2-rc1
d4d1b42beaee6346b399cd190b3719537413c83b    refs/tags/1.25.3
8d51620a78c25eef161cc4a49ea0acc1dbcf1f2c    refs/tags/1.25.4
c1a5734cade08a742601ec7172787df4d3e1e332    refs/tags/1.25.4-rc1
36a5d4d401d825d8f0957770c9d5baf325f501b7    refs/tags/1.25.4-rc2
8a1c60f64e77b3949cd4b08bc96d9020b45dc9a3    refs/tags/1.25.5
4afe60f271d29a3945927702da55e9aa7a95a1d7    refs/tags/1.25.5-rc1
4afe60f271d29a3945927702da55e9aa7a95a1d7    refs/tags/1.25.5-rc2
d445165955c564df6b797ae5f4f477cd332c5a53    refs/tags/1.26.0
07cab5137865ce01df3fc8a8f582444efb20596d    refs/tags/1.26.0-rc1
07cab5137865ce01df3fc8a8f582444efb20596d    refs/tags/1.26.0-rc2
46118bc5e0562d442a86b2cb6f0ca94d5f9f3c57    refs/tags/1.26.0-rc3
d279b7a891736af3109a0bd42991cd8344059a31    refs/tags/1.26.0-rc4
3d94f4421790d6820a8dca1cb764d052e060810b    refs/tags/1.26.0-rc5
d0899ca124a1d1bfac043c04654f3dcf9246b661    refs/tags/1.26.0-test
f216ddbf05c131058cb11323023f8b43cd381926    refs/tags/1.26.1
eefe0d319f966288a8c0438aa51822af8668ee06    refs/tags/1.26.2
980ec85bf45b6dc34cd4f37bf7736832337e7fe1    refs/tags/1.27.0
f9228ae43ca098f978600207a8885cef90e0f807    refs/tags/1.27.0-rc1
94e4316ba59d740855a2c960fc56b61f83e25f99    refs/tags/1.27.0-rc2
b920010afeb8f7dcf2695f93bdd6a6f8e91b5a64    refs/tags/1.27.0-rc3
ad87891ef8aef6fc2b214d31dae0c292801ec825    refs/tags/1.27.0-rc4
509cfb9979d093907792ef7611ca569362cbb95a    refs/tags/1.27.1
18f557f920bdc209d354233e8656ed9cc8fcb116    refs/tags/1.27.2
4092ae5d5a60fe8ad46bb414dbbf488dfccedc1a    refs/tags/1.27.3
405241920ee23c47d423a7ec5a0514aad7f6a421    refs/tags/1.27.4
d02a7b1aceb99a781145b3b236ee9897867cfd5c    refs/tags/1.28.0
1f469474bfbbf457d1c507cb54a1a2349ce9a487    refs/tags/1.28.0-rc1
f1e3c3561dd2373a0a71d7c33bfb73f1fded8a84    refs/tags/1.28.0-rc2
8efc791dd44b15bad2656d96349a8635ffb64e19    refs/tags/1.28.0-rc3
0e529bf29bb13680c24b8542670fea9e4f18927e    refs/tags/1.28.1
67630359cf4fedbdedc43690958576a90889f4c7    refs/tags/1.28.2
1473615283d32c93906a3d8ccf73402483785a6d    refs/tags/1.28.3
cabd5cfb4fb8e2d4f3f186b52e3624372ce58eae    refs/tags/1.28.4
c4eb3a1f475ca486340d4d5314ddf47555b2b1c6    refs/tags/1.28.5
5db8d86f127848367e4d721e992c188923c89d42    refs/tags/1.28.6
0773730525fd19fbc8653cbefdfac15877ab70be    refs/tags/1.29.0
c34c88b217fae0a985a7b28dbde755a11e5a2cb6    refs/tags/1.29.1
5becea4ca9f68875334c92f191a13482bcd6e5cf    refs/tags/1.29.2
00f61196a44ee140f389a51e50d39d1b846ba180    refs/tags/1.3.0
6171d8fb1fdf85192fc49579a3f3d435f5a9332a    refs/tags/1.3.0rc1
1e963618b838f383fce2f117be920fb82d14a89e    refs/tags/1.3.0rc2
3ad449548236d3968cfddc104df8f91b1585bf3c    refs/tags/1.3.0rc3
4d4ef4e0b3744944fc2b68fca52a785bc481f12a    refs/tags/1.3.1
95cf195dbd6509d7292fefd01d70f284fe0d4dd0    refs/tags/1.3.2
8cff440800a6098eba36cbce25bfef34e939b139    refs/tags/1.3.3
28139ab90dd1be21a3a9a0e768dc1f545ef5fe00    refs/tags/1.4.0
818517e0cd7b374dabf755717f2fddb9597824aa    refs/tags/1.4.0rc1
75da562ab40b80beae191f47e0a3f06506656f16    refs/tags/1.4.0rc2
02bbdc1fed2c3c64c73c29e438839d553a311d5d    refs/tags/1.4.0rc3
b24ca75914811af016e2b7fca6b33f4b8e5cda8a    refs/tags/1.4.1
7b5d5fcd58c871385613be4fc0dc371e62132858    refs/tags/1.4.2
77ff37a853b36e83de377cc83e7ff59eee11fc9c    refs/tags/1.5.0
709bd9c363c1f48138ab671b9505569057b5e04b    refs/tags/1.5.0rc1
8cc8e614740a71234cb7d1d3d5456c2c316a022c    refs/tags/1.5.0rc2
be6b811c4e9a1e8f22f2216c128b9bc91f4ebfdd    refs/tags/1.5.0rc3
4628e93fb2ee8e09f9410016574be58a5c2973ed    refs/tags/1.5.1
7240ff35eeac36d7fb53892af495bb172e0e00c2    refs/tags/1.5.2
d99cad60e73ad81be3f621b6e9dfef9c9d9facb5    refs/tags/1.6.0
d2556a1347a7a93171431b0d17da9f127142f6a0    refs/tags/1.6.0-rc1
695c692be6347d47669270958bb0bbe1c383773a    refs/tags/1.6.0-rc2
a75c16cb1be80f2c8e94120b7a79e3ddbd901419    refs/tags/1.6.1
4d720279a0a1152af70dee720a67c395392aaff3    refs/tags/1.6.2
0d7bf73446cd597e263f23b85c9fd1ea352735a6    refs/tags/1.7.0
1ad88662c04c0b8a8a119f051323af93c8a4d0ab    refs/tags/1.7.0-rc1
ea2d526246becbfa9cd38486958448bc1c6f606b    refs/tags/1.7.0-rc2
6c29830127c0328d2c790abc38a89cba69956d7a    refs/tags/1.7.1
94f7016fb73a7174c5249c0ca2abfab44663ce7a    refs/tags/1.8.0
9bf6bc6dbdb42c61defe97b98ec83f5f6ba63b98    refs/tags/1.8.0-rc1
c72c966abcebf15496af8ef29c8143967089aee3    refs/tags/1.8.0-rc2
878cff1d4ed38cef8d51ac0994f8105c641018ae    refs/tags/1.8.1
25853874c457851245cc2b4d5beb26f41a28cded    refs/tags/1.9.0
28788bd9b5f708c4dc96ba3921a0b63d3bd829a2    refs/tags/1.9.0-rc1
a2da43b997208eb7af90217252ae3cea0efef4ea    refs/tags/1.9.0-rc2
fcd38d3c4b1c4d8788dba802217779272362ccee    refs/tags/1.9.0-rc3
181a4e990eeb2ff2f92bf41486f5d31f35d38137    refs/tags/1.9.0-rc4
f46c203256b4ae6fe6a25523a5537120d824bab0    refs/tags/docs-v1.7.1-2016-05-31
9c69b95112fc6f95be65d77bb878c157b8b81dab    refs/tags/docs-v1.7.1-2016-05-31^{}
b4b847c2dc181af1ac3580a6cd88beb452609e18    refs/tags/docs-v1.7.1-2016-06-28
93cc2675c8f97e1a30b3bf2dbc287f0295ffc4fa    refs/tags/docs-v1.7.1-2016-06-28^{}
87af4b190e4de3b74db92e3d772cc66911e24fd0    refs/tags/docs-v1.7.1-2016-07-20
b1612c2acad0944474aa03481579441d3d77bf96    refs/tags/docs-v1.7.1-2016-07-20^{}
31d5575e9f1ceabe8a0869f68b093f2410b13b12    refs/tags/docs-v1.8.0-2016-08-03
429320a4f8f4040b273fd4d1be9f1d0b1283dc23    refs/tags/docs-v1.8.0-2016-08-03^{}
698e2846a82dbc48c14a017890f826e3d63ab783    refs/tags/v1.25.2
be4b7b559dd8e7bcddfae697fc132e18ab154b83    refs/tags/v1.25.2-rc2
7c47673d4af41d79900e6c70bc1a3f9f17bdd387    refs/tags/v2.0.0
1a73d1412d562e32effbe7b322f17e8d77ad7755    refs/tags/v2.0.0-rc.3
a23c64688b2e324158900500d744f957b8aecc17    refs/tags/v2.0.1
0a81a98b7dc6b2604922f9d6992c250f03304c5d    refs/tags/v2.0.1^{}
98b3353cbcc2cf01bbd5a4ca13928ccf6dc9a283    refs/tags/v2.1.0
e6599c7213f70b0a47b410450394c07e0b0245c9    refs/tags/v2.1.1
f880b4129c0498299f2d731280093093c719b24e    refs/tags/v2.10.0
1f527e98608b4da8d7176a56b276c4f9f2af98fe    refs/tags/v2.10.1
88406491c962d598106c56948a383bc5bed6178b    refs/tags/v2.10.1^{}
1135ca7b4c4b9b45e84aaa4cbfea54459533a0d5    refs/tags/v2.10.2
69651136cfc2d1d7556b386e98de56b1b1854430    refs/tags/v2.10.2^{}
c4d79e60b6d27dd437cea8bc555086abceca3606    refs/tags/v2.11.0
db882416985a2d36ee82f869920ad9ce9d4c2caa    refs/tags/v2.11.1
3e19e6611d8f16dc4346463e9ecb22a09934b77c    refs/tags/v2.11.2
616777eb4ad4d1101622d6727d9b7adaeb7943bb    refs/tags/v2.11.2^{}
32ae036fd013566cc45ceef35f5f5b7cb29725bc    refs/tags/v2.12.0
e8ea3ad29f3c66356c808f9efdb3d9c87c542d68    refs/tags/v2.12.1
f472ce3493e80d4e84a6dfd4e1a135109e40967e    refs/tags/v2.12.2
8c5d7baa7d28132ed9aeab14f11abf23b30846ec    refs/tags/v2.13.0
3daf8d2b4960266961f26464a88ecd066ea4a7c4    refs/tags/v2.14.0
6ed9a7928f649c59cdcc78b5884e4340b0a44a64    refs/tags/v2.14.0^{}
0eaa249222cc94d5cea2a3cf4f690f4d3153fbec    refs/tags/v2.14.1
ab791877ef6548697e6a7ff7c8e490964d88c5d7    refs/tags/v2.14.2
e1a38f984b7d00f7301e865c35423c7a80197e0e    refs/tags/v2.2.0
32005b0bfee3c731073a88c34576d2d572a27b4e    refs/tags/v2.2.1
e2f33af831ae9edcfa8efd53dfe24a36337a8250    refs/tags/v2.2.2
6dc6bedb60d486691a4b53e0b88273b978523786    refs/tags/v2.2.3
c64b044b7e235299e6b4352cc5e78c5ea678c136    refs/tags/v2.3.0
0ef4b90fae0d54bd4555eda877abf082afa4a2b1    refs/tags/v2.3.1
a2b9c812543e0aad501d9d12096e4e3877890b7d    refs/tags/v2.3.2
42710b7c4356ef9b196b07a3286d35f7692e625d    refs/tags/v2.3.3
be187bae649521f5776033284a511da0fbaf8058    refs/tags/v2.3.4
804ef4af5b1523bb4e860d2666377a99ccbc5f8b    refs/tags/v2.4.0
8d815ff587d7d5da90835a5007859edb9fafff61    refs/tags/v2.4.1
41b3967cb521a7c7254155a70fbafa5f5ae02aad    refs/tags/v2.5.0
7e3564b7ad057dc224a53d7ed505b7462bb5c5f9    refs/tags/v2.5.1
6756732fe45285f61d459809c36eed0f28fdd58b    refs/tags/v2.6.0
68cf8d5ca0d4852e17aca6fb2d9d08cf2baa3b73    refs/tags/v2.6.1
0b2281348bd6acd5daed42aaafb52cbc04deba02    refs/tags/v2.7.0
9a131a0734335bfa4c1cc7f815af1041bedf1fd1    refs/tags/v2.8.0
7289e87a38504158038c3bc2075d4d4acd922340    refs/tags/v2.9.0
1

There are 1 answers

0
TBA On BEST ANSWER

You can add v as an optional prefix to your grep command regex

git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oE "(v?)[0-9]+\.[0-9][0-9]+\.[0-9]+$" | sort --version-sort | tail -n 1

This will leave the prefix v if it's found in the release tag