Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/cleanup-old-previews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down