mirror of
https://github.com/RetroDECK/Cooker.git
synced 2024-11-25 14:45:38 +00:00
Update delete-old-releases.yml
This commit is contained in:
parent
9e29aa6ab3
commit
eee266cc57
45
.github/workflows/delete-old-releases.yml
vendored
45
.github/workflows/delete-old-releases.yml
vendored
|
@ -1,46 +1,33 @@
|
||||||
name: Delete Old Releases
|
name: Clean Old Releases
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * 0' # Runs every Sunday at midnight
|
- cron: '0 0 * * *' # Run daily at midnight
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
delete-old-releases:
|
clean-releases:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Git
|
- name: Set up Git
|
||||||
run: |
|
run: |
|
||||||
git config --global user.name 'GitHub Actions'
|
git config user.email "${{ secrets.GIT_MAIL }}"
|
||||||
git config --global user.email 'actions@github.com'
|
git config user.name "${{ secrets.GIT_USERNAME }}"
|
||||||
|
|
||||||
- name: List releases
|
- name: Clean Old Releases
|
||||||
id: list-releases
|
|
||||||
run: |
|
run: |
|
||||||
echo "::set-output name=releases::$(gh release list --json name,created_at --limit 100 --format json)"
|
# Define the threshold date (1 month ago)
|
||||||
|
THRESHOLD_DATE=$(date -d "1 month ago" +%Y-%m-%dT%H:%M:%SZ)
|
||||||
|
|
||||||
- name: Delete old releases
|
# Get releases older than 1 month
|
||||||
run: |
|
OLD_RELEASES=$(jq --arg threshold "$THRESHOLD_DATE" '. | select(.published_at < $threshold) | .id' <<< "$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/$GITHUB_REPOSITORY/releases)")
|
||||||
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
|
# Delete old releases
|
||||||
_jq() {
|
for release_id in $OLD_RELEASES; do
|
||||||
echo ${release} | base64 --decode | jq -r ${1}
|
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id"
|
||||||
}
|
|
||||||
|
|
||||||
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
|
done
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
Loading…
Reference in a new issue