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.ymlindex 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=3NOW=$(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 ]; thenecho "Nothing to clean up."exit 0fi- # Get open PR head commit short hashes (includes drafts)+ # Get open PR head commit short hashesOPEN_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" ]; thenLATEST_TIME=$DIR_TIMELATEST_DIR=$dirfidone- 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"; thenREASON="open PR"fi# Keep if newer than MAX_AGE_DAYSif [ -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 ]; thenAGE=$((NOW - DIR_TIME))if [ "$AGE" -lt "$MAX_AGE_SECS" ]; thenAGE_DAYS=$((AGE / 86400))@@ -97,10 +99,10 @@ jobs:fiif [ -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" ]; thengit rm -rf "$dir"fi@@ -109,10 +111,10 @@ jobs:doneecho ""- 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 0fi@@ -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