Rollup merge of #145704 - marcoieni:no-windows-disk-cleanup, r=jieyouxu

ci: don't cleanup windows disk
This commit is contained in:
Jacob Pratt 2025-08-21 17:57:57 -04:00 committed by GitHub
commit 0fcf80c055
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 2 additions and 246 deletions

View file

@ -117,12 +117,12 @@ jobs:
with:
fetch-depth: 2
# Free up disk space on Linux and Windows by removing preinstalled components that
# Free up disk space on Linux by removing preinstalled components that
# we do not need. We do this to enable some of the less resource
# intensive jobs to run on free runners, which however also have
# less disk space.
- name: free up disk space
run: src/ci/scripts/free-disk-space.sh
run: src/ci/scripts/free-disk-space-linux.sh
if: matrix.free_disk
# If we don't need to free up disk space then just report how much space we have
@ -223,11 +223,6 @@ jobs:
cd src/ci/citool
CARGO_INCREMENTAL=0 CARGO_TARGET_DIR=../../../build/citool cargo build
- name: wait for Windows disk cleanup to finish
if: ${{ matrix.free_disk && startsWith(matrix.os, 'windows-') }}
run: |
python3 src/ci/scripts/free-disk-space-windows-wait.py
- name: run the build
run: |
set +e

View file

@ -28,7 +28,6 @@ runners:
- &job-windows
os: windows-2025
free_disk: true
<<: *base-job
- &job-windows-8c

View file

@ -1,72 +0,0 @@
"""
Start freeing disk space on Windows in the background by launching
the PowerShell cleanup script, and recording the PID in a file,
so later steps can wait for completion.
"""
import subprocess
from pathlib import Path
from free_disk_space_windows_util import get_pid_file, get_log_file, run_main
def get_cleanup_script() -> Path:
script_dir = Path(__file__).resolve().parent
cleanup_script = script_dir / "free-disk-space-windows.ps1"
if not cleanup_script.exists():
raise Exception(f"Cleanup script '{cleanup_script}' not found")
return cleanup_script
def write_pid(pid: int):
pid_file = get_pid_file()
if pid_file.exists():
raise Exception(f"Pid file '{pid_file}' already exists")
pid_file.write_text(str(pid))
print(f"wrote pid {pid} in file {pid_file}")
def launch_cleanup_process():
cleanup_script = get_cleanup_script()
log_file_path = get_log_file()
# Launch the PowerShell cleanup in the background and redirect logs.
try:
with open(log_file_path, "w", encoding="utf-8") as log_file:
proc = subprocess.Popen(
[
"pwsh",
# Suppress PowerShell startup banner/logo for cleaner logs.
"-NoLogo",
# Don't load user/system profiles. Ensures a clean, predictable environment.
"-NoProfile",
# Disable interactive prompts. Required for CI to avoid hangs.
"-NonInteractive",
# Execute the specified script file (next argument).
"-File",
str(cleanup_script),
],
# Write child stdout to the log file.
stdout=log_file,
# Merge stderr into stdout for a single, ordered log stream.
stderr=subprocess.STDOUT,
)
print(
f"Started free-disk-space cleanup in background. "
f"pid={proc.pid}; log_file={log_file_path}"
)
return proc
except FileNotFoundError as e:
raise Exception("pwsh not found on PATH; cannot start disk cleanup.") from e
def main() -> int:
proc = launch_cleanup_process()
# Write pid of the process to a file, so that later steps can read it and wait
# until the process completes.
write_pid(proc.pid)
return 0
if __name__ == "__main__":
run_main(main)

View file

@ -1,92 +0,0 @@
"""
Wait for the background Windows disk cleanup process.
"""
import ctypes
import time
from free_disk_space_windows_util import get_pid_file, get_log_file, run_main
def is_process_running(pid: int) -> bool:
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
processHandle = ctypes.windll.kernel32.OpenProcess(
PROCESS_QUERY_LIMITED_INFORMATION, 0, pid
)
if processHandle == 0:
# The process is not running.
# If you don't have the sufficient rights to check if a process is running,
# zero is also returned. But in GitHub Actions we have these rights.
return False
else:
ctypes.windll.kernel32.CloseHandle(processHandle)
return True
def print_logs():
"""Print the logs from the cleanup script."""
log_file = get_log_file()
if log_file.exists():
print("free-disk-space logs:")
# Print entire log; replace undecodable bytes to avoid exceptions.
try:
with open(log_file, "r", encoding="utf-8", errors="replace") as f:
print(f.read())
except Exception as e:
raise Exception(f"Failed to read log file '{log_file}'") from e
else:
print(f"::warning::Log file '{log_file}' not found")
def read_pid_from_file() -> int:
"""Read the PID from the pid file."""
pid_file = get_pid_file()
if not pid_file.exists():
raise Exception(
f"No background free-disk-space process to wait for: pid file {pid_file} not found"
)
pid_file_content = pid_file.read_text().strip()
# Delete the file if it exists
pid_file.unlink(missing_ok=True)
try:
# Read the first line and convert to int.
pid = int(pid_file_content.splitlines()[0])
return pid
except Exception as e:
raise Exception(
f"Error while parsing the pid file with content '{pid_file_content!r}'"
) from e
def wait_for_process(pid: int):
timeout_duration_seconds = 5 * 60
interval_seconds = 3
max_attempts = timeout_duration_seconds / interval_seconds
attempts = 0
# Poll until process exits
while is_process_running(pid):
if attempts >= max_attempts:
print(
"::warning::Timeout expired while waiting for the disk cleanup process to finish."
)
break
time.sleep(interval_seconds)
attempts += 1
def main() -> int:
pid = read_pid_from_file()
wait_for_process(pid)
print_logs()
return 0
if __name__ == "__main__":
run_main(main)

View file

@ -1,35 +0,0 @@
# Free disk space on Windows GitHub action runners.
$ErrorActionPreference = 'Stop'
Get-Volume | Out-String | Write-Output
$available = $(Get-Volume C).SizeRemaining
$dirs = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm',
'C:\rtools45', 'C:\ghcup', 'C:\Program Files (x86)\Android',
'C:\Program Files\Google\Chrome', 'C:\Program Files (x86)\Microsoft\Edge',
'C:\Program Files\Mozilla Firefox', 'C:\Program Files\MySQL', 'C:\Julia',
'C:\Program Files\MongoDB', 'C:\Program Files\Azure Cosmos DB Emulator',
'C:\Program Files\PostgreSQL', 'C:\Program Files\Unity Hub',
'C:\Strawberry', 'C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk'
foreach ($dir in $dirs) {
Start-ThreadJob -InputObject $dir {
Remove-Item -Recurse -Force -LiteralPath $input
} | Out-Null
}
foreach ($job in Get-Job) {
Wait-Job $job | Out-Null
if ($job.Error) {
Write-Output "::warning file=$PSCommandPath::$($job.Error)"
}
Remove-Job $job
}
Get-Volume | Out-String | Write-Output
$saved = ($(Get-Volume C).SizeRemaining - $available) / 1gb
$savedRounded = [math]::Round($saved, 3)
Write-Output "total space saved: $savedRounded GB"

View file

@ -1,10 +0,0 @@
#!/bin/bash
set -euo pipefail
script_dir=$(dirname "$0")
if [[ "${RUNNER_OS:-}" == "Windows" ]]; then
python3 "$script_dir/free-disk-space-windows-start.py"
else
$script_dir/free-disk-space-linux.sh
fi

View file

@ -1,29 +0,0 @@
"""
Utilities for Windows disk space cleanup scripts.
"""
import os
from pathlib import Path
import sys
def get_temp_dir() -> Path:
"""Get the temporary directory set by GitHub Actions."""
return Path(os.environ.get("RUNNER_TEMP"))
def get_pid_file() -> Path:
return get_temp_dir() / "free-disk-space.pid"
def get_log_file() -> Path:
return get_temp_dir() / "free-disk-space.log"
def run_main(main_fn):
exit_code = 1
try:
exit_code = main_fn()
except Exception as e:
print(f"::error::{e}")
sys.exit(exit_code)