ci: free disk space on self-hosted runner before each job
All checks were successful
Deploy to Frontend Servers / deploy (push) Successful in 33s

Add a pre-checkout cleanup step that removes stale act caches,
old setup-node/npm cache entries, dangling docker resources, and
leftover /tmp files older than 2h. Prevents recurring ENOSPC
failures on the EC2 self-hosted runner.

Note: the very first run after this change may still fail if the
runner disk was already at 100% beforehand; one-time manual cleanup
on the host is required to bootstrap.
This commit is contained in:
TerryM
2026-05-30 00:10:39 +08:00
parent f3c51725fb
commit b370bf756c

View File

@@ -10,6 +10,36 @@ jobs:
runs-on: self-hosted
steps:
- name: Free disk space
run: |
set +e
echo "=== Disk before cleanup ==="
df -h
# Stale act runner workspaces from previous jobs (older than 60 min).
if [ -d "$HOME/.cache/act" ]; then
du -sh "$HOME/.cache/act" 2>/dev/null
find "$HOME/.cache/act" -mindepth 1 -maxdepth 1 -type d -mmin +60 -exec rm -rf {} + 2>/dev/null
fi
# Stale runner workspaces under common locations.
for dir in "$HOME/actions-runner/_work" "$HOME/.cache/setup-node" "$HOME/.npm/_cacache"; do
if [ -d "$dir" ]; then
find "$dir" -mindepth 1 -maxdepth 2 -mmin +1440 -exec rm -rf {} + 2>/dev/null
fi
done
# Docker leftovers if docker is available.
if command -v docker >/dev/null 2>&1; then
docker image prune -af --filter "until=24h" 2>/dev/null
docker container prune -f --filter "until=24h" 2>/dev/null
docker builder prune -af --filter "until=24h" 2>/dev/null
fi
# Stale /tmp files older than 2h, keep currently-running runner files.
find /tmp -mindepth 1 -maxdepth 1 -mmin +120 \
-not -name 'runner*' -not -name 'act*' \
-exec rm -rf {} + 2>/dev/null
echo "=== Disk after cleanup ==="
df -h
exit 0
- name: Checkout code
uses: actions/checkout@v4