From 9e33186708a09d5a2cee8830c41945b641014148 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 10 Oct 2025 08:28:18 +0200 Subject: [PATCH] ci(pages_cleanup): remove dirs that don't have existing related branch --- .github/workflows/pages_cleanup.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pages_cleanup.yml b/.github/workflows/pages_cleanup.yml index 58ba548a7..f385763b8 100644 --- a/.github/workflows/pages_cleanup.yml +++ b/.github/workflows/pages_cleanup.yml @@ -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