delete-old-releases.yml

This commit is contained in:
XargonWan 2023-09-29 10:11:41 +02:00 committed by GitHub
parent b208ab9fe1
commit 344b5849bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

45
.github/workflows/blank.yml vendored Normal file
View file

@ -0,0 +1,45 @@
name: Delete Old Releases
on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight
jobs:
delete-old-releases:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'actions@github.com'
- name: List releases
id: list-releases
run: |
echo "::set-output name=releases::$(gh release list --json name,created_at --limit 100 --format json)"
- name: Delete old releases
run: |
releases=${{ steps.list-releases.outputs.releases }}
current_time=$(date -u +%s)
two_weeks_ago=$(date -u -d "2 weeks ago" +%s)
for release in $(echo $releases | jq -r '.[] | @base64'); do
_jq() {
echo ${release} | base64 --decode | jq -r ${1}
}
release_created_at=$(_jq '.created_at')
release_timestamp=$(date -u -d "$release_created_at" +%s)
if [[ $release_timestamp -lt $two_weeks_ago ]]; then
release_name=$(_jq '.name')
echo "Deleting release: $release_name"
gh release delete "$release_name" -y
fi
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}