ci(pages_cleanup): remove dirs that don't have existing related branch

This commit is contained in:
Tim 2025-10-10 08:28:18 +02:00
parent ad5ab5c634
commit 9e33186708

View file

@ -18,13 +18,30 @@ jobs:
ref: gh-pages
fetch-depth: 0
- name: Delete directories older than 1 year
- name: Delete directories that don't have existing branch
run: |
for dir in $(find . -mindepth 1 -maxdepth 2 -type d -not -path '*/\.*'); do
if ! git log -1 --since="1 year ago" -- "$dir" | grep -q .; then
echo "Deleting $dir"
rm -rf "$dir"
fi
branches=( $(git branch -r | grep origin | grep -v HEAD | sed 's|origin/||') )
declare -p branches
find . -mindepth 1 -maxdepth 2 -type d -not -path '*/\.*' | while read -r dir; do
path="${dir#./}"
if [[ " ${branches[*]} " =~ " $path " ]]; then
continue
fi
keep_parent=false
for branch in "${branches[@]}"; do
if [[ "$branch" == "$path/"* ]]; then
keep_parent=true
break
fi
done
if ! $keep_parent; then
echo "Deleting $dir"
rm -rf "$dir"
fi
done
- name: Commit and push