Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: speed up deletings #26

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ runs:
# ======
# MACROS
# ======

fast_rmdir() {
if [[ -d "$1" ]] && [[ -n "$1" ]] && [[ ! "$1" = "/" ]] && [[ ! "$1" = "~" ]]; then
echo "Removing directory: $1"
sudo find "$1" -type f -delete -print | wc -l
sudo rm -rf "$1"
fi
}

list_installed_dpkg() {
dpkg --get-selections $@ | grep -v deinstall | awk '{print $1}'
}

# macro to print a line of equals
# (silly but works)
Expand Down Expand Up @@ -133,7 +145,7 @@ runs:
if [[ ${{ inputs.android }} == 'true' ]]; then
BEFORE=$(getAvailableSpace)

sudo rm -rf /usr/local/lib/android || true
fast_rmdir /usr/local/lib/android || true

AFTER=$(getAvailableSpace)
SAVED=$((AFTER-BEFORE))
Expand All @@ -146,7 +158,7 @@ runs:
BEFORE=$(getAvailableSpace)

# https://github.community/t/bigger-github-hosted-runners-disk-space/17267/11
sudo rm -rf /usr/share/dotnet || true
fast_rmdir /usr/share/dotnet || true

AFTER=$(getAvailableSpace)
SAVED=$((AFTER-BEFORE))
Expand All @@ -158,8 +170,8 @@ runs:
if [[ ${{ inputs.haskell }} == 'true' ]]; then
BEFORE=$(getAvailableSpace)

sudo rm -rf /opt/ghc || true
sudo rm -rf /usr/local/.ghcup || true
fast_rmdir /opt/ghc || true
fast_rmdir /usr/local/.ghcup || true

AFTER=$(getAvailableSpace)
SAVED=$((AFTER-BEFORE))
Expand All @@ -171,17 +183,23 @@ runs:

if [[ ${{ inputs.large-packages }} == 'true' ]]; then
BEFORE=$(getAvailableSpace)

sudo apt-get remove -y '^aspnetcore-.*' || echo "::warning::The command [sudo apt-get remove -y '^aspnetcore-.*'] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^dotnet-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^dotnet-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^llvm-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^llvm-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y 'php.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y 'php.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^mongodb-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mongodb-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^mysql-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mysql-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing || echo "::warning::The command [sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y google-cloud-sdk --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-sdk --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y google-cloud-cli --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-cli --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed to complete successfully. Proceeding..."

pkgs=$(list_installed_dpkg 'aspnetcore-*' 'dotnet-*' 'llvm-*' '*php*' 'mongodb-*' 'mysql-*' azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri 'google-cloud-*' 'gcloud-*' || true)

gcloud_prerm='#!/bin/sh
echo $0
if [ -d "/usr/lib/google-cloud-sdk" ]; then
echo "Cleaning Google Cloud CLI files..."
find /usr/lib/google-cloud-sdk -type f -delete -print | wc -l
rm -rf /usr/lib/google-cloud-sdk
echo "Cleaning Google Cloud CLI manuals..."
find /usr/share/man -type f -name "gcloud*" -delete -print | wc -l
fi'

echo "$gcloud_prerm" | sudo tee /var/lib/dpkg/info/google-cloud-cli-anthoscli.prerm >/dev/null
echo "$gcloud_prerm" | sudo tee /var/lib/dpkg/info/google-cloud-cli.prerm >/dev/null

sudo apt-get remove --autoremove -y $pkgs || echo "::warning::The command [sudo apt-get remove -y] failed to complete successfully. Proceeding..."
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed to complete successfully. Proceeding..."

AFTER=$(getAvailableSpace)
Expand All @@ -207,7 +225,7 @@ runs:
if [[ ${{ inputs.tool-cache }} == 'true' ]]; then
BEFORE=$(getAvailableSpace)

sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
fast_rmdir "$AGENT_TOOLSDIRECTORY" || true

AFTER=$(getAvailableSpace)
SAVED=$((AFTER-BEFORE))
Expand Down