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

66 lines
1.6 KiB
YAML
Raw Normal View History

2025-01-13 13:09:01 -06:00
name: "Maximize build disk space"
description: "Maximize the available disk space by removing unneeded software"
2024-06-14 14:40:02 -05:00
2024-06-14 15:02:01 -05:00
inputs:
purge-packages:
description: whether to remove apt packages
required: false
2025-01-13 13:09:01 -06:00
default: "false"
2024-06-14 15:02:01 -05:00
2024-06-14 14:40:02 -05:00
runs:
using: "composite"
steps:
- name: Disk space report before modification
shell: bash
run: |
2025-01-13 13:09:01 -06:00
echo "==> Available space before cleanup"
echo
df -h
2024-06-14 14:40:02 -05:00
- name: Maximize build disk space
shell: bash
run: |
2025-01-13 13:09:01 -06:00
set -xeuo pipefail
shopt -s globstar
2024-06-14 14:40:02 -05:00
2025-01-13 13:09:01 -06:00
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)
}
2024-06-14 15:02:01 -05:00
2025-01-13 13:09:01 -06:00
echo "Removing unwanted software... "
2024-06-14 15:02:01 -05:00
2025-01-13 13:09:01 -06:00
if [[ "${{ inputs.purge-packages }}" == 'true' ]]; then
sudo apt-get purge \
--allow-remove-essential \
$(non_manifest_packages)
fi
2024-09-17 11:52:08 -05:00
2024-06-14 15:02:01 -05:00
2025-01-13 13:09:01 -06:00
sudo rm -rf \
/var/lib/docker/ \
"$AGENT_TOOLSDIRECTORY" \
/opt &
2024-09-17 11:52:08 -05:00
2025-01-13 13:09:01 -06:00
sudo find /usr/{share,local} \
-mindepth 1 -maxdepth 1 \
-type d \
-not -wholename '/usr/share/git-core' \
-exec rm -rf {} + &
2025-01-13 13:09:01 -06:00
{
sudo swapoff -a
sudo rm -f /mnt/swapfile
} &
2024-06-14 14:40:02 -05:00
2025-01-13 13:09:01 -06:00
wait
echo "... done"
2024-09-17 11:52:08 -05:00
2024-06-14 14:40:02 -05:00
- name: Disk space report after modification
shell: bash
run: |
2025-01-13 13:09:01 -06:00
echo "==> Available space after cleanup"
echo
df -h