Unverified 提交 ea61dc53 authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

ci: add nightly disk cleanup for self-hosted runner ci1 (#2620)

Adds a scheduled GitHub Actions workflow that safely frees disk space on self-hosted macOS runner `ci1` at 4:00 AM PST to prevent CI from running out of space. ## Changes - **New workflow** `.github/workflows/nightly-runner-cleanup.yml`: Runs daily at 4 AM PST; only executes on runner `ci1` - **Extended cleanup script** `scripts/ci-cleanup-macos.sh`: `CI_NIGHTLY_CLEANUP=1` enables host-level cleanup: - `~/Library/Caches` subdirs (Homebrew, Xcode, LLVM) - npm cache - Runner `_work` dirs older than 2 days - **Documentation** in workflows README with validation steps ## Safety - Only allowlisted paths are deleted - Never removes runner binaries, config, or user data - Manual run via `workflow_dispatch` for testing Made with [Cursor](https://cursor.com) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/2620" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Primarily CI automation changes, but it introduces scheduled `rm -rf` cleanup on a self-hosted runner; an allowlist/guard is present, yet mistakes could still delete useful caches or workspaces and disrupt builds. > > **Overview** > Adds a scheduled `Nightly Runner Cleanup` GitHub Actions workflow that runs daily (and via `workflow_dispatch`) on self-hosted macOS runners, guarded to execute only when `RUNNER_NAME` is `ci1`. > > Extends `scripts/ci-cleanup-macos.sh` with a `CI_NIGHTLY_CLEANUP=1` mode that additionally purges allowlisted `~/Library/Caches` subdirectories and removes stale runner `actions-runner/_work` directories older than 2 days, and updates the workflows README with the new workflow and manual validation steps. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0b108a8a7969060614311f54cd694f0454a6839b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a nightly GitHub Actions workflow to free disk on self-hosted macOS runner ci1 at 4:00 AM PST. Extends the cleanup script with a guarded nightly mode to remove allowlisted caches and stale work dirs so CI doesn’t run out of space. - **New Features** - Added nightly-runner-cleanup.yml: runs daily at 4 AM PST; only executes on runner ci1; supports manual workflow_dispatch. - Updated scripts/ci-cleanup-macos.sh: CI_NIGHTLY_CLEANUP=1 cleans Library/Caches subdirs (Homebrew, Xcode, org.llvm.clang*), npm cache, Playwright browsers, and runner _work dirs older than 2 days; prints mode and disk before/after. - Updated README with manual validation steps. <sup>Written for commit 0b108a8a7969060614311f54cd694f0454a6839b. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --------- Co-authored-by: 's avatarCursor <cursoragent@cursor.com> Co-authored-by: 's avatardevin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
上级 932ae082
# Nightly disk cleanup for self-hosted macOS CI runners (e.g. ci1).
# Runs at 4:00 AM PST to prevent disk exhaustion from CI workloads.
# Safe to run manually via workflow_dispatch for testing.
name: Nightly Runner Cleanup
on:
schedule:
# 4:00 AM PST = 12:00 UTC (PST is UTC-8)
- cron: "0 12 * * *"
workflow_dispatch:
jobs:
cleanup:
runs-on: [self-hosted, macOS, ARM64]
steps:
- name: Guard — run only on ci1
id: guard
run: |
if [ "$RUNNER_NAME" = "ci1" ]; then
echo "run_cleanup=true" >> "$GITHUB_OUTPUT"
echo "Running cleanup on runner: $RUNNER_NAME"
else
echo "run_cleanup=false" >> "$GITHUB_OUTPUT"
echo "Skipping cleanup: runner is '$RUNNER_NAME', expected ci1"
fi
- name: Checkout (for cleanup script)
if: steps.guard.outputs.run_cleanup == 'true'
uses: actions/checkout@v4
- name: Nightly disk cleanup
if: steps.guard.outputs.run_cleanup == 'true'
env:
CI_NIGHTLY_CLEANUP: "1"
run: bash scripts/ci-cleanup-macos.sh
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
# Intended to run as a post-job step in GitHub Actions workflows that use # Intended to run as a post-job step in GitHub Actions workflows that use
# self-hosted macOS ARM64 runners. Safe to run multiple times (idempotent). # self-hosted macOS ARM64 runners. Safe to run multiple times (idempotent).
# #
# Set CI_NIGHTLY_CLEANUP=1 for nightly runs to also clean host-level caches
# (Library/Caches subdirs, runner _work stale dirs). Only allowlisted paths.
#
# What it cleans: # What it cleans:
# 1. Build outputs (out/, out-macos.tar) # 1. Build outputs (out/, out-macos.tar)
# 2. Blob reports (blob-report/) # 2. Blob reports (blob-report/)
...@@ -11,10 +14,16 @@ ...@@ -11,10 +14,16 @@
# 4. Old Playwright browsers (keeps only the current version) # 4. Old Playwright browsers (keeps only the current version)
# 5. npm cache artifacts (_cacache, _logs) # 5. npm cache artifacts (_cacache, _logs)
# 6. Old runner diagnostics (_diag/*.log older than 7 days) # 6. Old runner diagnostics (_diag/*.log older than 7 days)
# 7. [Nightly only] ~/Library/Caches subdirs, runner _work (older than 2 days)
set -euo pipefail set -euo pipefail
echo "=== CI Cleanup (macOS self-hosted) ===" echo "=== CI Cleanup (macOS self-hosted) ==="
if [ "${CI_NIGHTLY_CLEANUP:-0}" = "1" ]; then
echo "Mode: nightly (host-level + workspace)"
else
echo "Mode: per-job (workspace only)"
fi
df -h / | tail -1 | awk '{print "Disk before cleanup: "$4" available ("$5" used)"}' df -h / | tail -1 | awk '{print "Disk before cleanup: "$4" available ("$5" used)"}'
bytes_before=$(df -k / | tail -1 | awk '{print $4}') bytes_before=$(df -k / | tail -1 | awk '{print $4}')
...@@ -115,6 +124,40 @@ if [ -d "$RUNNER_DIR/_diag" ]; then ...@@ -115,6 +124,40 @@ if [ -d "$RUNNER_DIR/_diag" ]; then
fi fi
fi fi
# ---------------------------------------------------------------------------
# 7. [Nightly only] Host-level caches and stale runner _work
# Only when CI_NIGHTLY_CLEANUP=1. Allowlisted paths only.
# ---------------------------------------------------------------------------
if [ "${CI_NIGHTLY_CLEANUP:-0}" = "1" ]; then
CACHES="$HOME/Library/Caches"
# Allowlisted subdirs (never wipe entire Caches)
for subdir in Homebrew com.apple.dt.Xcode; do
d="$CACHES/$subdir"
if [ -d "$d" ]; then
size=$(du -sh "$d" 2>/dev/null | cut -f1 || echo "?")
echo "Removing cache: $d (${size})"
rm -rf "$d"
fi
done
for d in "$CACHES"/org.llvm.clang*; do
[ -d "$d" ] || continue
size=$(du -sh "$d" 2>/dev/null | cut -f1 || echo "?")
echo "Removing cache: $d (${size})"
rm -rf "$d"
done
# Runner _work: remove stale job workspaces older than 2 days
if [ -d "$RUNNER_DIR/_work" ]; then
stale=$(find "$RUNNER_DIR/_work" -mindepth 1 -maxdepth 1 -type d -mtime +2 2>/dev/null || true)
if [ -n "$stale" ]; then
echo "Removing stale _work dirs (older than 2 days):"
echo "$stale"
echo "$stale" | while IFS= read -r dir; do rm -rf "$dir"; done
fi
fi
fi
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Summary # Summary
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论