cleanup-ci-artifacts.sh
1 #!/bin/bash 2 # CI Artifact Cleanup Script 3 # Removes build artifacts and temporary files after CI runs 4 5 set -e 6 7 echo "=== CI Artifact Cleanup ===" 8 9 # Get the workspace directory (typically the repo root) 10 WORKSPACE="${GITHUB_WORKSPACE:-$(pwd)}" 11 echo "Workspace: $WORKSPACE" 12 13 # Function to safely remove directory if it exists 14 safe_rm() { 15 local dir="$1" 16 if [ -d "$dir" ]; then 17 echo "Removing: $dir ($(du -sh "$dir" 2>/dev/null | cut -f1))" 18 rm -rf "$dir" 19 fi 20 } 21 22 # Rust build artifacts 23 if [ -d "$WORKSPACE/target" ]; then 24 echo "Cleaning Rust target directory..." 25 safe_rm "$WORKSPACE/target" 26 fi 27 28 # Node.js build artifacts 29 safe_rm "$WORKSPACE/node_modules" 30 safe_rm "$WORKSPACE/dist" 31 safe_rm "$WORKSPACE/build" 32 33 # Python artifacts 34 find "$WORKSPACE" -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true 35 find "$WORKSPACE" -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true 36 safe_rm "$WORKSPACE/.pytest_cache" 37 safe_rm "$WORKSPACE/.coverage" 38 39 # Go artifacts 40 safe_rm "$WORKSPACE/bin" 41 42 # Clean up old rustc temp files in /tmp (older than 1 day) 43 echo "Cleaning old rustc temp files..." 44 find /tmp -maxdepth 1 -name "rustc*" -type d -mtime +1 -exec rm -rf {} + 2>/dev/null || true 45 46 # Clean up workspace temp directories 47 find "$WORKSPACE" -type d -name "tmp" -o -name "temp" | while read -r tmpdir; do 48 safe_rm "$tmpdir" 49 done 50 51 echo "=== Cleanup complete ===" 52 53 # Show remaining disk usage 54 echo "Current disk usage:" 55 df -h / | tail -1