prunetags.sh 767 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. set -e
  3. git fetch --tags
  4. TAGS=( $(git tag -l "autobuild-*" | sort -r) )
  5. KEEP_LATEST=14
  6. KEEP_MONTHLY=24
  7. LATEST_TAGS=()
  8. MONTHLY_TAGS=()
  9. CUR_MONTH="-1"
  10. for TAG in ${TAGS[@]}; do
  11. if [[ ${#LATEST_TAGS[@]} -lt ${KEEP_LATEST} ]]; then
  12. LATEST_TAGS+=( "$TAG" )
  13. fi
  14. if [[ ${#MONTHLY_TAGS[@]} -lt ${KEEP_MONTHLY} ]]; then
  15. TAG_MONTH="$(echo $TAG | cut -d- -f3)"
  16. if [[ ${TAG_MONTH} != ${CUR_MONTH} ]]; then
  17. CUR_MONTH="${TAG_MONTH}"
  18. MONTHLY_TAGS+=( "$TAG" )
  19. fi
  20. fi
  21. done
  22. for TAG in ${LATEST_TAGS[@]} ${MONTHLY_TAGS[@]}; do
  23. TAGS=( "${TAGS[@]/$TAG}" )
  24. done
  25. for TAG in ${TAGS[@]}; do
  26. echo "Deleting ${TAG}"
  27. gh release delete --cleanup-tag --yes "${TAG}"
  28. done
  29. git push --tags --prune