Add script for automatic release pruning
This commit is contained in:
parent
d62e6101b5
commit
4eb20ade1b
2 changed files with 43 additions and 0 deletions
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
|
@ -114,3 +114,7 @@ jobs:
|
|||
hub release create $(for a in artifacts/*; do echo -a $a; done) -m "$NAME" -t "master" "$TAGNAME"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Prune old releases
|
||||
run: ./util/prunetags.sh
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
39
util/prunetags.sh
Executable file
39
util/prunetags.sh
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
git fetch --tags
|
||||
TAGS=( $(git tag -l "autobuild-*" | sort -r) )
|
||||
|
||||
KEEP_LATEST=14
|
||||
KEEP_MONTHLY=12
|
||||
|
||||
LATEST_TAGS=()
|
||||
MONTHLY_TAGS=()
|
||||
|
||||
CUR_MONTH="-1"
|
||||
|
||||
for TAG in ${TAGS[@]}; do
|
||||
if [[ ${#LATEST_TAGS[@]} -lt ${KEEP_LATEST} ]]; then
|
||||
LATEST_TAGS+=( "$TAG" )
|
||||
fi
|
||||
|
||||
if [[ ${#MONTHLY_TAGS[@]} -lt ${KEEP_MONTHLY} ]]; then
|
||||
TAG_MONTH="$(echo $TAG | cut -d- -f3)"
|
||||
|
||||
if [[ ${TAG_MONTH} != ${CUR_MONTH} ]]; then
|
||||
CUR_MONTH="${TAG_MONTH}"
|
||||
MONTHLY_TAGS+=( "$TAG" )
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for TAG in ${LATEST_TAGS[@]} ${MONTHLY_TAGS[@]}; do
|
||||
TAGS=( "${TAGS[@]/$TAG}" )
|
||||
done
|
||||
|
||||
for TAG in ${TAGS[@]}; do
|
||||
echo "Deleting ${TAG}"
|
||||
hub release delete "${TAG}"
|
||||
git tag -d "${TAG}"
|
||||
done
|
||||
|
||||
git push --tags --prune
|
Loading…
Reference in a new issue