CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
40 lines
1.7 KiB
Python
40 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Reclaim unused SDKs only inside a disposable GitHub-hosted Linux job VM.
|
|
|
|
This is CI setup, not a local toolbox cleanup command. No Docker images,
|
|
containers, project state, caches or user directories are deleted.
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
|
|
GB = 1000**3
|
|
SDK_PATHS = ('/usr/local/lib/android', '/usr/share/dotnet', '/usr/local/.ghcup')
|
|
|
|
|
|
def prepare():
|
|
if any(os.environ.get(key) != value for key,value in {
|
|
'GITHUB_ACTIONS':'true','RUNNER_ENVIRONMENT':'github-hosted','RUNNER_OS':'Linux'
|
|
}.items()):
|
|
raise RuntimeError('CI disk preparation is restricted to disposable GitHub-hosted Linux jobs')
|
|
workspace = Path(os.environ.get('GITHUB_WORKSPACE',''))
|
|
if not workspace.is_absolute() or not workspace.is_dir():
|
|
raise RuntimeError('Missing hosted-job workspace')
|
|
for name in SDK_PATHS:
|
|
free = shutil.disk_usage(workspace).free
|
|
print(f'Hosted runner free disk: {free/GB:.2f} GB',flush=True)
|
|
if free >= 30*GB: return
|
|
path = Path(name)
|
|
if not path.exists(): continue
|
|
if path.is_symlink() or path.resolve() != path or not path.is_dir():
|
|
raise RuntimeError('Refusing unexpected preinstalled SDK path: '+name)
|
|
print('Removing unused preinstalled SDK from this disposable job VM: '+name,flush=True)
|
|
subprocess.run(['sudo','-n','rm','-rf','--one-file-system','--',name],check=True,timeout=180)
|
|
free = shutil.disk_usage(workspace).free
|
|
if free < 30*GB:
|
|
raise RuntimeError(f'Hosted runner has {free/GB:.2f} GB free; 30 GB is required to preserve the 20 GB product budget plus 10 GB host reserve')
|
|
|
|
|
|
if __name__ == '__main__': prepare()
|