diff --git a/.github/workflows/cleanup-old-previews.yml b/.github/workflows/cleanup-old-previews.yml index f250c4635..24a8ac111 100644 --- a/.github/workflows/cleanup-old-previews.yml +++ b/.github/workflows/cleanup-old-previews.yml @@ -5,6 +5,7 @@ on: # Run weekly on Sunday at midnight UTC - cron: '0 0 * * 0' workflow_dispatch: # Allow manual trigger + pull_request: # For testing permissions: contents: write @@ -35,7 +36,8 @@ jobs: dir="${dir%/}" # Get the date of the first commit that added this folder - FIRST_COMMIT_DATE=$(git log --diff-filter=A --format=%ct --reverse -- "$dir" | head -1) + # Disable pipefail in subshell to avoid SIGPIPE (exit 141) when head closes early + FIRST_COMMIT_DATE=$(set +o pipefail; git log --diff-filter=A --format=%ct --reverse -- "$dir" | head -1) if [ -z "$FIRST_COMMIT_DATE" ]; then echo "Warning: Could not find creation date for $dir, skipping" @@ -56,7 +58,17 @@ jobs: echo "" echo "DELETED_FOLDERS=$DELETED_FOLDERS" >> "$GITHUB_ENV" + - name: Summary (dry-run on PR) + if: github.event_name == 'pull_request' + run: | + if [ -z "$DELETED_FOLDERS" ]; then + echo "Dry-run: No folders would be deleted" + else + echo "Dry-run: Would delete:$DELETED_FOLDERS" + fi + - name: Commit and push changes + if: github.event_name != 'pull_request' run: | if [ -z "$DELETED_FOLDERS" ]; then echo "No folders to delete"