Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinatorTime authored Oct 26, 2023
1 parent b293af8 commit d110323
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions .github/workflows/clear-old-releases.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
name: Delete Old Releases
name: Delete Old Release Files

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"

jobs:
delete_old_releases:
delete_old_files:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check out code
uses: actions/checkout@v2

- name: Delete old releases
run: |
ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}
REPO_OWNER=MartinatorTime
REPO_NAME=vaultwarden
- name: Set up Git
run: git config --global user.email "[email protected]" && git config --global user.name "GitHub Actions"

RELEASES=$(curl -H "Authorization: token $ACCESS_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases")
for release in $(echo $RELEASES | jq -r '.[] | select(.published_at | fromdateiso8601 < (now - 7*24*3600)) | .id'); do
echo "Deleting release $release"
curl -X DELETE -H "Authorization: token $ACCESS_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/$release"
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: List releases
run: |
for release in $(gh release list -L 100 | awk '{if(NR>1)print $1}'); do
release_date=$(gh release view $release | grep "Created: " | awk '{print $2}')
release_timestamp=$(date -d "$release_date" +%s)
current_timestamp=$(date +%s)
age_in_days=$(((current_timestamp - release_timestamp) / 86400))
if [ $age_in_days -gt 7 ]; then
echo "Deleting files in release $release (created $age_in_days days ago)"
for file in $(gh release view $release --json name -q ".assets[].name" | jq -r .[]); do
gh release delete $release --title $file
done
fi
done

0 comments on commit d110323

Please sign in to comment.