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

67 lines
1.6 KiB
YAML
Raw Permalink Normal View History

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