mirror of
https://github.com/RetroDECK/Vita3K-bin.git
synced 2025-01-19 12:45:38 +00:00
Add workflow to clean old Vita3K releases automatically
This commit is contained in:
parent
be12fc9118
commit
6f88631d5c
52
.github/workflows/clean_old_releases.yml
vendored
Normal file
52
.github/workflows/clean_old_releases.yml
vendored
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
name: Clean Old Vita3K Releases
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *' # Run daily at midnight
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clean-releases:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Git
|
||||||
|
run: |
|
||||||
|
git config user.email "${{ secrets.GIT_MAIL }}"
|
||||||
|
git config user.name "${{ secrets.GIT_USERNAME }}"
|
||||||
|
|
||||||
|
- name: Clean Old Releases
|
||||||
|
run: |
|
||||||
|
# Define the threshold date (15 days ago)
|
||||||
|
THRESHOLD_DATE=$(date -d "15 days ago" +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
|
||||||
|
# Get all releases (handle pagination)
|
||||||
|
ALL_RELEASES=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases?per_page=100&page=1")
|
||||||
|
PAGE_COUNT=$(echo "$ALL_RELEASES" | jq '. | length')
|
||||||
|
|
||||||
|
# Get the latest release ID
|
||||||
|
LATEST_RELEASE=$(echo "$ALL_RELEASES" | jq -r '.[0].id')
|
||||||
|
|
||||||
|
# Loop through pages and get releases older than 1 month (excluding the latest)
|
||||||
|
for ((i=0; i<$PAGE_COUNT; i++)); do
|
||||||
|
RELEASE_ID=$(echo "$ALL_RELEASES" | jq -r ".[$i].id")
|
||||||
|
|
||||||
|
# Skip the latest release
|
||||||
|
if [ "$RELEASE_ID" == "$LATEST_RELEASE" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the release is older than 1 month
|
||||||
|
OLD_RELEASES=$(echo "$ALL_RELEASES" | jq --arg threshold "$THRESHOLD_DATE" ".[$i] | select(.published_at < \$threshold) | .id")
|
||||||
|
|
||||||
|
# Delete old releases
|
||||||
|
for release_id in $OLD_RELEASES; do
|
||||||
|
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
Loading…
Reference in a new issue