Files

43 lines
1.4 KiB
YAML

# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
name: "Disk Space Cleanup"
author: "Ultralytics"
description: "Cleans up disk space by removing unnecessary tool caches, Docker images, and swap space"
runs:
using: "composite"
steps:
- name: Cleanup disk space
shell: bash
run: |
echo "::group::Disk Space Before Cleanup"
df -h /
echo "::endgroup::"
echo "::group::Remove Tool Cache, Docker Images, and Swap"
toolcache_pid=""
if [ -e /opt/hostedtoolcache ]; then
# Remove tool cache to free up ~15GB of space per https://github.com/ultralytics/ultralytics/pull/15848
rm -rf /opt/hostedtoolcache &
toolcache_pid=$!
fi
docker image prune --all --force &
docker_pid=$!
if [ -n "$toolcache_pid" ]; then
wait "$toolcache_pid" || true
fi
wait "$docker_pid" || true
# Remove swap space to free up ~4GB
for swap_file in /swapfile /mnt/swapfile; do
if [ -f "$swap_file" ]; then
if swapon --show=NAME --noheadings | grep -Fxq "$swap_file"; then
sudo swapoff "$swap_file"
fi
sudo rm -f "$swap_file"
fi
done
echo "::endgroup::"
echo "::group::Disk Space After Cleanup"
df -h /
echo "::endgroup::"