Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(ci): rewrite cleanup workflow to avoid SIGPIPE on 600+ dirs

Cindy Zhangaa8be0794a6d
diff --git a/.github/workflows/cleanup-previews.yml b/.github/workflows/cleanup-previews.yml
index dec7069abe..bf75d90ad4 100644
--- a/.github/workflows/cleanup-previews.yml
+++ b/.github/workflows/cleanup-previews.yml
@@ -30,42 +30,44 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRY_RUN: ${{ inputs.dry_run || 'false' }}
run: |
- set -euo pipefail
-
MAX_AGE_DAYS=3
NOW=$(date +%s)
MAX_AGE_SECS=$((MAX_AGE_DAYS * 86400))
- echo "🧹 Cleanup config:"
- echo " Max age: ${MAX_AGE_DAYS} days"
- echo " Dry run: ${DRY_RUN}"
+ echo "Cleanup config:"
+ echo " Max age: ${MAX_AGE_DAYS} days"
+ echo " Dry run: ${DRY_RUN}"
echo ""
# Get all 7-char hex directories (preview deployments)
PREVIEW_DIRS=$(ls -d [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f] 2>/dev/null || true)
TOTAL=$(echo "$PREVIEW_DIRS" | grep -c . || echo 0)
- echo "πŸ“ Found ${TOTAL} preview directories"
+ echo "Found ${TOTAL} preview directories"
if [ "$TOTAL" -eq 0 ]; then
echo "Nothing to clean up."
exit 0
fi
- # Get open PR head commit short hashes (includes drafts)
+ # Get open PR head commit short hashes
OPEN_PR_HASHES=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --json headRefOid --jq '.[].headRefOid[:7]' || true)
- echo "πŸ”“ Open PR hashes: $(echo "$OPEN_PR_HASHES" | grep -c . || echo 0)"
+ echo "Open PR hashes: $(echo "$OPEN_PR_HASHES" | grep -c . || echo 0)"
- # Find the latest deployment (most recently added directory)
+ # Get timestamps for all directories using filesystem mtime
+ # (avoids running git log 600+ times which causes SIGPIPE with pipefail)
LATEST_DIR=""
LATEST_TIME=0
+ declare -A DIR_TIMES
+
for dir in $PREVIEW_DIRS; do
- DIR_TIME=$(git log --format=%ct --diff-filter=A -- "${dir}/" 2>/dev/null | head -1)
- if [ -n "$DIR_TIME" ] && [ "$DIR_TIME" -gt "$LATEST_TIME" ]; then
+ DIR_TIME=$(stat -c %Y "$dir" 2>/dev/null || echo 0)
+ DIR_TIMES[$dir]=$DIR_TIME
+ if [ "$DIR_TIME" -gt "$LATEST_TIME" ]; then
LATEST_TIME=$DIR_TIME
LATEST_DIR=$dir
fi
done
- echo "πŸ“Œ Latest deployment: ${LATEST_DIR}"
+ echo "Latest deployment: ${LATEST_DIR}"
echo ""
DELETED=0
@@ -80,14 +82,14 @@ jobs:
fi
# Keep if open PR
- if [ -z "$REASON" ] && echo "$OPEN_PR_HASHES" | grep -q "^${dir}$"; then
+ if [ -z "$REASON" ] && echo "$OPEN_PR_HASHES" | grep -qx "$dir"; then
REASON="open PR"
fi
# Keep if newer than MAX_AGE_DAYS
if [ -z "$REASON" ]; then
- DIR_TIME=$(git log --format=%ct --diff-filter=A -- "${dir}/" 2>/dev/null | head -1)
- if [ -n "$DIR_TIME" ]; then
+ DIR_TIME="${DIR_TIMES[$dir]:-0}"
+ if [ "$DIR_TIME" -gt 0 ]; then
AGE=$((NOW - DIR_TIME))
if [ "$AGE" -lt "$MAX_AGE_SECS" ]; then
AGE_DAYS=$((AGE / 86400))
@@ -97,10 +99,10 @@ jobs:
fi
if [ -n "$REASON" ]; then
- echo " βœ“ KEEP ${dir} β€” ${REASON}"
+ echo " KEEP ${dir} - ${REASON}"
KEPT=$((KEPT + 1))
else
- echo " βœ— DELETE ${dir}"
+ echo " DELETE ${dir}"
if [ "$DRY_RUN" != "true" ]; then
git rm -rf "$dir"
fi
@@ -109,10 +111,10 @@ jobs:
done
echo ""
- echo "πŸ“Š Summary: ${DELETED} deleted, ${KEPT} kept (of ${TOTAL})"
+ echo "Summary: ${DELETED} deleted, ${KEPT} kept (of ${TOTAL})"
if [ "$DRY_RUN" = "true" ]; then
- echo "🏜️ Dry run β€” no changes committed"
+ echo "Dry run - no changes committed"
exit 0
fi
@@ -121,7 +123,7 @@ jobs:
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: cleanup ${DELETED} stale preview deployments"
git push origin gh-pages
- echo "βœ… Pushed cleanup commit"
+ echo "Pushed cleanup commit"
else
- echo "βœ… Nothing to clean up"
+ echo "Nothing to clean up"
fi