From 549b7bda0a0b823c672015177c9e9acf388efc88 Mon Sep 17 00:00:00 2001 From: Philipp Sauter Date: Thu, 21 Sep 2023 19:11:01 +0200 Subject: [PATCH] only publish the last 10 versions --- publish-artifact.sh | 65 ++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/publish-artifact.sh b/publish-artifact.sh index 5d4f313c..907175ce 100755 --- a/publish-artifact.sh +++ b/publish-artifact.sh @@ -11,35 +11,40 @@ aptlydistro=stable aptlycmd="aptly -config=.aptly.conf" gpgkeyflag='-gpg-key=7100E8BFD6199CE0374CB7F003686F8CDE378D41' -# if $aptlycmd mirror show $aptlymirror >/dev/null 2>&1; then -# echo "repo $aptlymirror already exists" -# else -# $aptlycmd mirror create \ -# -filter="(latest)" \ -# $aptlymirror \ -# $archiveurl \ -# $aptlydistro -# fi - -# $aptlycmd mirror update \ -# $aptlymirror - -if $aptlycmd repo show $aptlyrepo >/dev/null 2>&1; then - echo "repo $aptlyrepo already exists" -else - $aptlycmd repo create $aptlyrepo - # $aptlycmd repo import $aptlymirror $aptlyrepo $aptlydistro -fi +# Get the 10 latest Git tags +latest_tags=$(git tag --sort=-v:refname | head -n 10) + +# Create a package query filter for aptly +package_filter="" +for tag in $latest_tags; do + stripped_tag=$(expr "$tag" : '.\(.*\)') + if [ $first_tag_set ]; then + package_filter+=" | " + fi + package_filter+="exoscale-cli (= $stripped_tag)" + first_tag_set=1 +done + +mirrorrepo() { + $aptlycmd mirror create \ + $aptlymirror \ + $archiveurl \ + $aptlydistro + + $aptlycmd mirror update \ + $aptlymirror +} -if echo $artifact | grep -q '.*.deb'; then - $aptlycmd repo add $aptlyrepo $artifact - $aptlycmd publish repo \ - $gpgkeyflag \ - -distribution=$aptlydistro \ - $aptlyrepo \ - $aptlyremote - # $aptlycmd publish update \ - # $gpgkeyflag \ - # $aptlydistro \ - # $aptlyremote +$aptlycmd repo create $aptlyrepo + +if mirrorrepo; then + $aptlycmd repo import $aptlymirror $aptlyrepo "$package_filter" fi + +$aptlycmd repo add $aptlyrepo $artifact + +$aptlycmd publish repo \ + $gpgkeyflag \ + -distribution=$aptlydistro \ + $aptlyrepo \ + $aptlyremote