-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b293af8
commit d110323
Showing
1 changed file
with
20 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |