|
| 1 | +name: "Cleanup Runner Disk Space" |
| 2 | +description: "Frees disk space on the current LINUX GitHub Actions runner" |
| 3 | + |
| 4 | +inputs: |
| 5 | +# default false entries |
| 6 | + clean_toolcache: |
| 7 | + description: "Remove GitHub hostedtoolcache" |
| 8 | + default: "false" |
| 9 | + clean_node: |
| 10 | + description: "Remove Node/NVM" |
| 11 | + default: "false" |
| 12 | +# default true entries |
| 13 | + clean_android: |
| 14 | + description: "Remove Android SDK" |
| 15 | + default: "true" |
| 16 | + clean_dotnet: |
| 17 | + description: "Remove .NET SDK" |
| 18 | + default: "true" |
| 19 | + clean_go: |
| 20 | + description: "Remove Go toolchain" |
| 21 | + default: "true" |
| 22 | + clean_java: |
| 23 | + description: "Remove Java JDKs" |
| 24 | + default: "true" |
| 25 | + clean_rust: |
| 26 | + description: "Remove Rust toolchains" |
| 27 | + default: "true" |
| 28 | + clean_ruby: |
| 29 | + description: "Remove Ruby toolchains" |
| 30 | + default: "true" |
| 31 | + clean_homebrew: |
| 32 | + description: "Remove Homebrew" |
| 33 | + default: "true" |
| 34 | + clean_apt: |
| 35 | + description: "Clean APT (cache, autoremove)" |
| 36 | + default: "true" |
| 37 | + clean_logs: |
| 38 | + description: "Clean system logs" |
| 39 | + default: "true" |
| 40 | + clean_docker: |
| 41 | + description: "Prune Docker unused data" |
| 42 | + default: "true" |
| 43 | + clean_misc: |
| 44 | + description: "Clean misc caches (/tmp, /var/cache, etc.)" |
| 45 | + default: "true" |
| 46 | + |
| 47 | +runs: |
| 48 | + using: "composite" |
| 49 | + steps: |
| 50 | + ######################################################### |
| 51 | + # Safety Check: Abort if not Linux |
| 52 | + ######################################################### |
| 53 | + - name: Verify OS is Linux |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + echo "Runner OS: $RUNNER_OS" |
| 57 | + if [[ "$RUNNER_OS" != "Linux" ]]; then |
| 58 | + echo "❌ This cleanup action only supports Linux runners." |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + - name: Size check |
| 63 | + shell: bash |
| 64 | + run: df -h |
| 65 | + |
| 66 | + ######################################################### |
| 67 | + # Phase 1: Toolcache |
| 68 | + ######################################################### |
| 69 | + - name: Remove GitHub hosted toolcache |
| 70 | + if: ${{ inputs.clean_toolcache == 'true' }} |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + echo "Cleaning /opt/hostedtoolcache ..." |
| 74 | + sudo rm -rf /opt/hostedtoolcache/* |
| 75 | +
|
| 76 | + ######################################################### |
| 77 | + # Phase 2: Android SDK |
| 78 | + ######################################################### |
| 79 | + - name: Remove Android SDK |
| 80 | + if: ${{ inputs.clean_android == 'true' }} |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + echo "Removing Android SDK ..." |
| 84 | + sudo rm -rf /usr/local/lib/android |
| 85 | + sudo rm -rf $ANDROID_HOME || true |
| 86 | + sudo rm -rf /opt/android || true |
| 87 | +
|
| 88 | + ######################################################### |
| 89 | + # Phase 3: .NET |
| 90 | + ######################################################### |
| 91 | + - name: Remove .NET SDK |
| 92 | + if: ${{ inputs.clean_dotnet == 'true' }} |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + echo "Removing .NET SDK ..." |
| 96 | + sudo rm -rf /usr/share/dotnet |
| 97 | +
|
| 98 | + ######################################################### |
| 99 | + # Phase 4: Node / NVM |
| 100 | + ######################################################### |
| 101 | + - name: Remove Node & NVM |
| 102 | + if: ${{ inputs.clean_node == 'true' }} |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + echo "Removing Node.js + NVM ..." |
| 106 | + sudo rm -rf /usr/local/nvm |
| 107 | + sudo rm -rf /usr/local/lib/node_modules |
| 108 | + sudo rm -rf /opt/nodejs || true |
| 109 | +
|
| 110 | + ######################################################### |
| 111 | + # Phase 5: Go |
| 112 | + ######################################################### |
| 113 | + - name: Remove Go toolchain |
| 114 | + if: ${{ inputs.clean_go == 'true' }} |
| 115 | + shell: bash |
| 116 | + run: | |
| 117 | + echo "Removing Go toolchain ..." |
| 118 | + sudo rm -rf /usr/local/go |
| 119 | +
|
| 120 | + ######################################################### |
| 121 | + # Phase 6: Java |
| 122 | + ######################################################### |
| 123 | + - name: Remove Java JDKs |
| 124 | + if: ${{ inputs.clean_java == 'true' }} |
| 125 | + shell: bash |
| 126 | + run: | |
| 127 | + echo "Removing JDKs ..." |
| 128 | + sudo rm -rf /usr/lib/jvm/* |
| 129 | +
|
| 130 | + ######################################################### |
| 131 | + # Phase 7: Rust |
| 132 | + ######################################################### |
| 133 | + - name: Remove Rust toolchain |
| 134 | + if: ${{ inputs.clean_rust == 'true' }} |
| 135 | + shell: bash |
| 136 | + run: | |
| 137 | + echo "Removing Rust toolchains ..." |
| 138 | + sudo rm -rf ~/.cargo || true |
| 139 | + sudo rm -rf ~/.rustup || true |
| 140 | +
|
| 141 | + ######################################################### |
| 142 | + # Phase 8: Ruby |
| 143 | + ######################################################### |
| 144 | + - name: Remove Ruby toolchains |
| 145 | + if: ${{ inputs.clean_ruby == 'true' }} |
| 146 | + shell: bash |
| 147 | + run: | |
| 148 | + echo "Removing Ruby versions ..." |
| 149 | + sudo rm -rf /opt/hostedtoolcache/Ruby || true |
| 150 | + sudo rm -rf /usr/local/lib/ruby || true |
| 151 | +
|
| 152 | + ######################################################### |
| 153 | + # Phase 9: Homebrew |
| 154 | + ######################################################### |
| 155 | + - name: Remove Homebrew |
| 156 | + if: ${{ inputs.clean_homebrew == 'true' }} |
| 157 | + shell: bash |
| 158 | + run: | |
| 159 | + echo "Removing Homebrew ..." |
| 160 | + sudo rm -rf /home/linuxbrew/.linuxbrew |
| 161 | + sudo rm -rf /home/linuxbrew/.cache/* |
| 162 | +
|
| 163 | + ######################################################### |
| 164 | + # Phase 10: APT |
| 165 | + ######################################################### |
| 166 | + - name: APT Cleanup |
| 167 | + if: ${{ inputs.clean_apt == 'true' }} |
| 168 | + shell: bash |
| 169 | + run: | |
| 170 | + echo "Cleaning APT caches ..." |
| 171 | + sudo apt-get clean |
| 172 | + sudo apt-get autoremove -y |
| 173 | + sudo apt-get autoclean |
| 174 | +
|
| 175 | + ######################################################### |
| 176 | + # Phase 11: Logs |
| 177 | + ######################################################### |
| 178 | + - name: Clean system logs |
| 179 | + if: ${{ inputs.clean_logs == 'true' }} |
| 180 | + shell: bash |
| 181 | + run: | |
| 182 | + echo "Cleaning journal logs ..." |
| 183 | + sudo journalctl --vacuum-time=1s |
| 184 | +
|
| 185 | + ######################################################### |
| 186 | + # Phase 12: Docker |
| 187 | + ######################################################### |
| 188 | + - name: Prune Docker |
| 189 | + if: ${{ inputs.clean_docker == 'true' }} |
| 190 | + shell: bash |
| 191 | + run: | |
| 192 | + echo "Pruning Docker resources ..." |
| 193 | + docker system prune -af |
| 194 | + docker volume prune -f |
| 195 | +
|
| 196 | + ######################################################### |
| 197 | + # Phase 13: Misc caches |
| 198 | + ######################################################### |
| 199 | + - name: Remove miscellaneous caches |
| 200 | + if: ${{ inputs.clean_misc == 'true' }} |
| 201 | + shell: bash |
| 202 | + run: | |
| 203 | + echo "Cleaning miscellaneous caches ..." |
| 204 | + sudo rm -rf /var/lib/apt/lists/* |
| 205 | + sudo rm -rf /var/cache/apt/* |
| 206 | + sudo rm -rf /tmp/* |
| 207 | +
|
| 208 | + - name: Size check |
| 209 | + shell: bash |
| 210 | + run: df -h |
0 commit comments