Skip to content

Commit 0dbe308

Browse files
space testing
1 parent d11e925 commit 0dbe308

File tree

2 files changed

+255
-0
lines changed

2 files changed

+255
-0
lines changed
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
name: "Agressivly Maximize Space"
2+
description: "Maximize the available disk space for your build job"
3+
branding:
4+
icon: "crop"
5+
color: "orange"
6+
inputs:
7+
root-reserve-mb:
8+
description: "Space to be left free on the root filesystem, in Megabytes."
9+
required: false
10+
default: "1024"
11+
swap-size-mb:
12+
description: "Swap space to create, in Megabytes."
13+
required: false
14+
default: "4096"
15+
build-mount-path:
16+
description: "Absolute path to the mount point where the build space will be available, defaults to $GITHUB_WORKSPACE if unset."
17+
required: false
18+
build-mount-path-ownership:
19+
description: 'Ownership of the mount point path, defaults to standard "runner" user and group.'
20+
required: false
21+
default: "runner:runner"
22+
pv-loop-path:
23+
description: "Absolute file path for the LVM image created on the root filesystem, the default is usually fine."
24+
required: false
25+
default: "/pv.img"
26+
tmp-pv-loop-path:
27+
description: "Absolute file path for the LVM image created on the temp filesystem, the default is usually fine. Must reside on /mnt"
28+
required: false
29+
default: "/mnt/tmp-pv.img"
30+
boot-pv-loop-path:
31+
description: "Absolute file path for the LVM image created on the boot filesystem, the default is usually fine. Must reside on /boot"
32+
required: false
33+
default: "/boot/boot-pv.img"
34+
35+
runs:
36+
using: "composite"
37+
steps:
38+
- name: Disk space report before modification
39+
shell: bash
40+
run: |
41+
echo "Memory and swap:"
42+
sudo free -h
43+
echo
44+
sudo swapon --show
45+
echo
46+
47+
echo "Available storage:"
48+
sudo df -h
49+
echo
50+
51+
- name: Show info
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
56+
BUILD_MOUNT_PATH="${{ inputs.build-mount-path }}"
57+
if [[ -z "${BUILD_MOUNT_PATH}" ]]; then
58+
BUILD_MOUNT_PATH="${GITHUB_WORKSPACE}"
59+
fi
60+
61+
echo "Arguments:"
62+
echo
63+
echo " Root reserve: ${{ inputs.root-reserve-mb }} MiB"
64+
echo " Swap space: ${{ inputs.swap-size-mb }} MiB"
65+
echo " Mount path: ${BUILD_MOUNT_PATH}"
66+
echo " Root PV loop path: ${{ inputs.pv-loop-path }}"
67+
echo " Temp PV loop path: ${{ inputs.tmp-pv-loop-path }}"
68+
echo " Boot PV loop path: ${{ inputs.boot-pv-loop-path }}"
69+
echo " EFI PV loop path: ${{ inputs.efi-pv-loop-path }}"
70+
71+
# ensure mount path exists before the action
72+
sudo mkdir -p "${BUILD_MOUNT_PATH}"
73+
sudo find "${BUILD_MOUNT_PATH}" -maxdepth 0 ! -empty -exec echo 'WARNING: directory [{}] is not empty, data loss might occur. Content:' \; -exec ls -al "{}" \;
74+
75+
- name: Prune Docker
76+
shell: bash
77+
run: sudo docker image prune --all --force
78+
79+
- name: Remove apt packages
80+
shell: bash
81+
run: |
82+
echo "Removing packages from apt"
83+
PACKAGES=(
84+
'microsoft-edge-stable'
85+
'azure-cli'
86+
'^google.*'
87+
'^temurin.*'
88+
'powershell'
89+
'^llvm.*'
90+
'snapd'
91+
'python-.*'
92+
'python3-.*'
93+
'containerd.io'
94+
'^docker-ce.*'
95+
'podman'
96+
'kubectl'
97+
'^clang.*'
98+
'^cpp.*'
99+
'.*postgres.*'
100+
'.*mysql.*'
101+
'.*sqlite.*'
102+
'mecab-ipadic'
103+
'.*gfortran.*'
104+
'apache2-bin'
105+
'shellcheck'
106+
'git-lfs'
107+
'mercurial'
108+
'adwaita-icon-theme'
109+
'^php.*'
110+
'ant'
111+
'shim-signed'
112+
)
113+
sudo apt-get remove --purge -y --allow-remove-essential ${PACKAGES[@]}
114+
sudo apt-get autoremove -y
115+
sudo apt-get clean -y
116+
117+
- name: Remove biggest directories
118+
shell: bash
119+
run: |
120+
echo "Removing directories"
121+
DIRS=(
122+
'/usr/local/lib/android'
123+
'/usr/local/.ghcup'
124+
'/opt/hostedtoolcache'
125+
'/usr/share/dotnet'
126+
'/usr/share/swift'
127+
'/usr/local/share/powershell'
128+
'/usr/share/miniconda'
129+
/usr/share/gradle*
130+
/usr/local/julia*
131+
'/home/runner/.rustup'
132+
'/home/runner/.cargo'
133+
'/home/runner/.dotnet'
134+
'/home/runner/.nvm'
135+
'/usr/local/share/chromium'
136+
'/opt/pipx'
137+
'/usr/local/aws-cli'
138+
'/home/packer'
139+
/root/*
140+
'/etc/skel'
141+
'/usr/local/aws-sam-cli'
142+
'/usr/libexec/docker'
143+
'/home/linuxbrew'
144+
'/usr/share/kotlinc'
145+
/usr/share/apache-maven*
146+
/boot/efi/*
147+
/boot/initrd*
148+
/boot/vmlinuz*
149+
)
150+
sudo rm -rf ${DIRS[@]}
151+
152+
- name: Remove Swap
153+
shell: bash
154+
run: |
155+
echo 'Removing Swap'
156+
sudo swapoff -a
157+
sudo rm -f /mnt/swapfile
158+
159+
- name: Create LVM Volume
160+
shell: bash
161+
run: |
162+
set -euo pipefail
163+
164+
BUILD_MOUNT_PATH="${{ inputs.build-mount-path }}"
165+
if [[ -z "${BUILD_MOUNT_PATH}" ]]; then
166+
BUILD_MOUNT_PATH="${GITHUB_WORKSPACE}"
167+
fi
168+
169+
VG_NAME=buildvg
170+
171+
echo "Creating LVM Volume."
172+
echo " Creating LVM PV on root fs."
173+
# create loop pv image on root fs
174+
ROOT_RESERVE_KB=$(expr ${{ inputs.root-reserve-mb }} \* 1024)
175+
ROOT_FREE_KB=$(df --block-size=1024 --output=avail / | tail -1)
176+
ROOT_LVM_SIZE_KB=$(expr $ROOT_FREE_KB - $ROOT_RESERVE_KB)
177+
ROOT_LVM_SIZE_BYTES=$(expr $ROOT_LVM_SIZE_KB \* 1024)
178+
sudo touch "${{ inputs.pv-loop-path }}" && sudo fallocate -z -l "${ROOT_LVM_SIZE_BYTES}" "${{ inputs.pv-loop-path }}"
179+
export ROOT_LOOP_DEV=$(sudo losetup --find --show "${{ inputs.pv-loop-path }}")
180+
sudo pvcreate -f "${ROOT_LOOP_DEV}"
181+
182+
# create pv on temp disk
183+
echo " Creating LVM PV on temp fs."
184+
TMP_FREE_KB=$(df --block-size=1024 --output=avail /mnt | tail -1)
185+
TMP_LVM_SIZE_KB=$TMP_FREE_KB
186+
TMP_LVM_SIZE_BYTES=$(expr $TMP_LVM_SIZE_KB \* 1024)
187+
sudo touch "${{ inputs.tmp-pv-loop-path }}" && sudo fallocate -z -l "${TMP_LVM_SIZE_BYTES}" "${{ inputs.tmp-pv-loop-path }}"
188+
export TMP_LOOP_DEV=$(sudo losetup --find --show "${{ inputs.tmp-pv-loop-path }}")
189+
sudo pvcreate -f "${TMP_LOOP_DEV}"
190+
191+
# create pv on boot disk
192+
echo " Creating LVM PV on boot fs."
193+
BOOT_FREE_KB=$(df --block-size=1024 --output=avail /boot | tail -1)
194+
BOOT_LVM_SIZE_KB=$BOOT_FREE_KB
195+
BOOT_LVM_SIZE_BYTES=$(expr $BOOT_LVM_SIZE_KB \* 1024)
196+
sudo touch "${{ inputs.boot-pv-loop-path }}" && sudo fallocate -z -l "${BOOT_LVM_SIZE_BYTES}" "${{ inputs.boot-pv-loop-path }}"
197+
export BOOT_LOOP_DEV=$(sudo losetup --find --show "${{ inputs.boot-pv-loop-path }}")
198+
sudo pvcreate -f "${BOOT_LOOP_DEV}"
199+
200+
# create volume group from these pvs
201+
sudo vgcreate "${VG_NAME}" "${TMP_LOOP_DEV}" "${ROOT_LOOP_DEV}" "${BOOT_LOOP_DEV}"
202+
203+
echo "Recreating swap"
204+
# create and activate swap
205+
sudo lvcreate -L "${{ inputs.swap-size-mb }}M" -n swap "${VG_NAME}"
206+
sudo mkswap "/dev/mapper/${VG_NAME}-swap"
207+
sudo swapon "/dev/mapper/${VG_NAME}-swap"
208+
209+
echo "Creating build volume"
210+
# create and mount build volume
211+
sudo lvcreate -l 100%FREE -n buildlv "${VG_NAME}"
212+
sudo mkfs.btrfs -K "/dev/mapper/${VG_NAME}-buildlv"
213+
sudo mount -o compress=zstd,noatime,nodiscard "/dev/mapper/${VG_NAME}-buildlv" "${BUILD_MOUNT_PATH}"
214+
sudo chown -R "${{ inputs.build-mount-path-ownership }}" "${BUILD_MOUNT_PATH}"
215+
216+
# if build mount path is a parent of $GITHUB_WORKSPACE, and has been deleted, recreate it
217+
if [[ ! -d "${GITHUB_WORKSPACE}" ]]; then
218+
sudo mkdir -p "${GITHUB_WORKSPACE}"
219+
sudo chown -R "${WORKSPACE_OWNER}" "${GITHUB_WORKSPACE}"
220+
fi
221+
222+
- name: Disk space report after modification
223+
shell: bash
224+
run: |
225+
echo "Memory and swap:"
226+
sudo free -h
227+
echo
228+
sudo swapon --show
229+
echo
230+
231+
echo "Available storage:"
232+
sudo df -h

.github/workflows/space.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
workflow_dispatch:
3+
4+
jobs:
5+
test:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: "actions/checkout@v6"
9+
- uses: "./.github/actions/aggressive-space"
10+
with:
11+
swap-size-mb: "1024"
12+
build-mount-path: /nix/store
13+
- name: Install Python for Nix
14+
run: sudo apt install python3
15+
- name: Install nix
16+
uses: cachix/install-nix-action@v31
17+
- name: Setup cachix
18+
uses: cachix/cachix-action@v16
19+
with:
20+
name: henriquekh
21+
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
22+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
23+
extraPullNames: nix-community,hyprland,niri

0 commit comments

Comments
 (0)