oizys/.github/actions/clean-disk/action.yml

69 lines
1.8 KiB
YAML

name: 'Maximize build disk space'
description: 'Maximize the available disk space by removing unneeded software'
inputs:
purge-packages:
description: whether to remove apt packages
required: false
default: 'false'
runs:
using: "composite"
steps:
- name: Disk space report before modification
shell: bash
run: |
echo "==> Available space before cleanup"
echo
df -h
- name: Maximize build disk space
shell: bash
run: |
set -euo pipefail
shopt -s globstar
non_manifest_packages() {
comm -2 -3 \
<(sudo apt-mark showmanual | sort -u) \
<(grep --perl-regexp --only-matching '^[\w-.+]+' "${{ github.action_path }}"/ubuntu-24.04.1-live-server-amd64.manifest | sort -u)
}
echo "Removing unwanted software... "
if [[ "${{ inputs.purge-packages }}" == 'true' ]]; then
sudo apt-get purge \
--allow-remove-essential \
$(non_manifest_packages)
fi
sudo rm -rf \
/var/lib/docker/ \
"$AGENT_TOOLSDIRECTORY" \
/opt \
/usr/local/** &
find /usr/share -maxdepth -m -type d -not -name 'git-core' -delete
# for f in /usr/share/**/!(git-core); do
# sudo rm -rf $f &
# done
# nix flake update wants to find git-core templates
# /usr/share/git-core/templates
# /usr/share/**
{
sudo swapoff -a
sudo rm -f /mnt/swapfile
} &
wait
echo "... done"
- name: Disk space report after modification
shell: bash
run: |
echo "==> Available space after cleanup"
echo
df -h