forked from lthn/blockchain
ci: prune old releases to keep only latest per branch
After uploading new release assets, delete older beta releases (dev) or older stable releases (main) to conserve disk. Only the latest build per branch is kept on the Forgejo instance; older builds are available on mirrored free hosting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1545a80335
commit
f3df50cba5
1 changed files with 33 additions and 0 deletions
|
|
@ -114,3 +114,36 @@ jobs:
|
|||
fi
|
||||
echo "Uploaded ${FILENAME} (HTTP ${HTTP_CODE})"
|
||||
done
|
||||
|
||||
- name: Prune old releases
|
||||
run: |
|
||||
TAG_PREFIX="${{ github.ref_name == 'main' && 'v6' || 'v6.*-beta' }}"
|
||||
CURRENT_ID="${{ steps.create_release.outputs.id }}"
|
||||
echo "Keeping release ${CURRENT_ID}, pruning older ${TAG_PREFIX} releases..."
|
||||
PAGE=1
|
||||
while true; do
|
||||
RELEASES=$(curl -s "${FORGEJO_URL}/api/v1/repos/${{ github.repository }}/releases?limit=50&page=${PAGE}" \
|
||||
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}")
|
||||
COUNT=$(echo "$RELEASES" | python3 -c "import sys,json; print(len(json.load(sys.stdin)))" 2>/dev/null || echo 0)
|
||||
[ "$COUNT" = "0" ] && break
|
||||
echo "$RELEASES" | python3 -c "
|
||||
import sys, json, fnmatch
|
||||
for r in json.load(sys.stdin):
|
||||
rid = r['id']
|
||||
tag = r['tag_name']
|
||||
if rid == ${CURRENT_ID}:
|
||||
continue
|
||||
if fnmatch.fnmatch(tag, '${TAG_PREFIX}*'):
|
||||
print(f'{rid} {tag}')
|
||||
" | while read -r RID RTAG; do
|
||||
echo "Deleting release ${RTAG} (id=${RID})"
|
||||
curl -s -o /dev/null -X DELETE \
|
||||
"${FORGEJO_URL}/api/v1/repos/${{ github.repository }}/releases/${RID}" \
|
||||
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}"
|
||||
curl -s -o /dev/null -X DELETE \
|
||||
"${FORGEJO_URL}/api/v1/repos/${{ github.repository }}/tags/${RTAG}" \
|
||||
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}"
|
||||
done
|
||||
PAGE=$((PAGE + 1))
|
||||
done
|
||||
echo "Prune complete"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue