Skip to content

Commit

Permalink
ci: Make clean up based on git date
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltaranto committed Feb 11, 2025
1 parent 5aed0d6 commit 2acaef3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/clean-up-previews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
env:
CI: true
PREVIEW_DIR: preview
DAYS_OLD: 7
DAYS_OLD: 12
steps:
- name: Checkout Repo
uses: actions/checkout@v4
Expand All @@ -18,7 +18,9 @@ jobs:

- name: Delete old preview directories
run: |
for i in `find ${{ env.PREVIEW_DIR }} -mindepth 1 -maxdepth 1 -type d -mtime +${{ env.DAYS_OLD }} -print`; do echo -e "Deleting directory $i";rm -rf $i; done
DATE_FROM_DAYS_AGO=`date --date="${{env.DAYS_OLD}} days ago" +"%Y"-"%m"-"%d" || date -v-${{env.DAYS_OLD}}d +"%Y"-"%m"-"%d"`;
echo $DATE_FROM_DAYS_AGO;
for i in `find ${{ env.PREVIEW_DIR }} -mindepth 1 -maxdepth 1 -type d -print`; do if [[ $(git log --before $DATE_FROM_DAYS_AGO $i | tail -1) ]]; then echo "Deleting directory $i"; rm -rf $i; fi; done
if [[ $(git status --porcelain --untracked-files=no | wc -l) -eq 0 ]]; then echo "No directories to clean up";exit 0; fi
git config --local user.name 'GitHub Actions'
git config --local user.email '[email protected]'
Expand Down

0 comments on commit 2acaef3

Please sign in to comment.