[CI] (.github/actions, .github/workflows): create swap even when the runner image has none

This commit is contained in:
2026-11-15 05:45:04 -04:00
parent b2248b240f
commit 222f6209a0
3 changed files with 85 additions and 55 deletions
+29
View File
@@ -0,0 +1,29 @@
name: Set swap space
description: Replace the runner's swap with a swap file of the given size
inputs:
swap-size-gb:
description: Size of the swap file in GiB
required: true
runs:
using: composite
steps:
# Hosted images differ: some ship /swapfile, some ship no swap at all. Turn off whatever is
# active, then create the file at the path the image used, or /swapfile when there was none.
- shell: bash
env:
SWAP_SIZE_GB: ${{ inputs.swap-size-gb }}
run: |
set -euo pipefail
active="$(swapon --show=NAME --noheadings)"
swap_file="$(printf '%s\n' "$active" | grep '^/' | tail -n 1 || true)"
swap_file="${swap_file:-/swapfile}"
if [ -n "$active" ]; then
printf '%s\n' "$active" | xargs -r -n1 sudo swapoff
fi
sudo rm -f "$swap_file"
sudo fallocate -l "${SWAP_SIZE_GB}G" "$swap_file"
sudo chmod 600 "$swap_file"
sudo mkswap "$swap_file"
sudo swapon "$swap_file"
free -h
swapon --show