Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ jobs:
free-disk-space:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
# If there is a problem with this GitHub Actions, this step will fail
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
uses: ./
with:
tool-cache: true

Expand All @@ -17,4 +18,6 @@ jobs:
dotnet: true
haskell: true
large-packages: true
large-packages-keep: |
^llvm-.*$
swap-storage: true
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:

Most of the options are self-explanatory.

When `large-packages` is enabled, you can keep specific packages by setting `large-packages-keep` to
a regular expression; matching packages are skipped when uninstalling large packages.

The option `tool-cache` removes all the pre-cached tools (Node, Go, Python, Ruby, ...) that are loaded in a runner's environment, [installed in the path specified by the `AGENT_TOOLSDIRECTORY` environment variable](https://github.com/actions/virtual-environments/blob/5a2cb18a48bce5da183486b95f5494e4fd0c0640/images/linux/scripts/installers/configure-environment.sh#L25-L29) (the same environment variable is used across Windows/macOS/Linux runners, see an example of its use on [the `setup-python` GitHub Action](https://github.com/actions/setup-python)). This option was [suggested](https://github.com/actions/virtual-environments/issues/2875#issuecomment-1163392159) by [@miketimofeev](https://github.com/miketimofeev).

## Acknowledgement
Expand Down
59 changes: 47 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ inputs:
description: "Remove large packages"
required: false
default: "true"
large-packages-keep:
description: "Regex for packages to keep when removing large packages"
required: false
default: ""

docker-images:
description: "Remove Docker images"
Expand Down Expand Up @@ -113,8 +117,6 @@ runs:
printSeparationLine '=' 80
}



# ======
# SCRIPT
# ======
Expand Down Expand Up @@ -171,16 +173,49 @@ 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..."

runAptRemove() {
local level="$1"
shift

local combined_regex
combined_regex=$(printf '%s\n' "$@" | tr -d "'" | paste -sd'|' -)

local matched
matched=$(dpkg-query -W -f '${binary:Package}\n' | grep -E "$combined_regex" | sort -u || true)

if [[ -z "$matched" ]]; then
return
fi

local keep_regex
keep_regex=$(printf '%s' "${{ inputs.large-packages-keep }}" | sed 's/[[:space:]]\+$//')
if [[ -n "$keep_regex" ]]; then
printf '%s\n' "$matched" | grep -E "$keep_regex" | sed "s/^/::${level}::Keeping package [/;s/$/]/" || true
matched=$(printf '%s\n' "$matched" | grep -Ev "$keep_regex" | sort -u || true)
fi

if [[ -z "$matched" ]]; then
return
fi

local cmd=(sudo apt-get remove -y --fix-missing)
while IFS= read -r pkg; do
cmd+=("$pkg")
done <<< "$matched"

"${cmd[@]}" || echo "::${level}::The command [${cmd[@]}] failed to complete successfully. Proceeding..."
}

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

Expand Down