Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/actions/free-disk-space/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Free runner disk space
description: >-
Delete preinstalled toolchains Lean Pool never uses (.NET, Android, GHC,
CodeQL, Swift), freeing about 25 GB. Without this, restoring the Lean
dependency cache plus the whole-pool build cache (about 8 GB compressed)
fails with "No space left on device". Run it before the first cache
restore; Workflow Lint enforces that.
runs:
using: composite
steps:
- name: Delete unused preinstalled toolchains
shell: bash
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
7 changes: 1 addition & 6 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ jobs:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
# The fresh main pool-build cache (about 8 GB compressed) plus the
# dependency cache overflow the runner's default free space.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space
- name: Restore Lean dependencies
id: dependency-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/docs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
# The fresh main pool-build cache (about 8 GB compressed) plus the
# dependency cache overflow the runner's default free space.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space
- name: Restore Lean dependencies
id: dependency-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/exposition-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,8 @@ jobs:
id: build-identity
run: echo "revision=$(PYTHONPATH=python python3 -m lean_pool.ci_cache revision)" >> "$GITHUB_OUTPUT"

# The dependency and pool build caches together exceed the runner's
# default free space, so restoring them fails with ENOSPC.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space

# Match Lean Action CI's cache lookup exactly. This workflow only needs
# compiled Lean artifacts; restoring doc-gen output here used to make a
Expand Down
32 changes: 4 additions & 28 deletions .github/workflows/lean_action_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,8 @@ jobs:
with:
fetch-depth: 0

# Restored caches plus the cache-save archive overflow the runner's
# default free space: every main build-cache save failed from
# 2026-10-16, so all runs rebuilt weeks of changes from a stale cache.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space

# Keep the large toolchain/Mathlib cache independent of per-commit builds.
- name: Restore Lean dependencies
Expand Down Expand Up @@ -549,14 +543,8 @@ jobs:
with:
fetch-depth: 0

# Restored caches plus the cache-save archive overflow the runner's
# default free space: every main build-cache save failed from
# 2026-10-16, so all runs rebuilt weeks of changes from a stale cache.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space

- name: Restore Lean dependencies
id: dependency-cache
Expand Down Expand Up @@ -656,14 +644,8 @@ jobs:
with:
fetch-depth: 0

# Restored caches plus the cache-save archive overflow the runner's
# default free space: every main build-cache save failed from
# 2026-10-16, so all runs rebuilt weeks of changes from a stale cache.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space

- name: Restore Lean dependencies
id: dependency-cache
Expand Down Expand Up @@ -934,14 +916,8 @@ jobs:
with:
fetch-depth: 0

# Restored caches plus the cache-save archive overflow the runner's
# default free space: every main build-cache save failed from
# 2026-10-16, so all runs rebuilt weeks of changes from a stale cache.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /
uses: ./.github/actions/free-disk-space

- name: Restore Lean dependencies
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/proof-profile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ jobs:
fetch-depth: 0
persist-credentials: false

# Inline copy of .github/actions/free-disk-space: this job checks out
# the PR head, which may predate that action. Workflow Lint keeps the
# two identical.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /

- name: Restore Lean dependencies
id: dependency-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae
Expand Down Expand Up @@ -398,6 +407,15 @@ jobs:
fetch-depth: 0
persist-credentials: false

# Inline copy of .github/actions/free-disk-space: this job checks out
# the PR head, which may predate that action. Workflow Lint keeps the
# two identical.
- name: Free runner disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
/usr/local/.ghcup /opt/hostedtoolcache/CodeQL /usr/share/swift
df -h /

- name: Restore Lean dependencies
id: dependency-cache
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/workflow_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,28 @@ jobs:

- name: Ensure Actions are pinned
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@fc87bb5b5a97953d987372e74478de634726b3e5

disk-cleanup:
needs: scope
if: always() && (needs.scope.result != 'success' || needs.scope.outputs.applicable != 'false')
runs-on: ubuntu-latest
name: Free disk before pool-build restores
steps:
- name: Require successful change classification
env:
SCOPE_RESULT: ${{ needs.scope.result }}
APPLICABLE: ${{ needs.scope.outputs.applicable }}
run: |
if [ "$SCOPE_RESULT" != success ] || [ "$APPLICABLE" != true ]; then
echo "::error::Change classification failed; required validation cannot be skipped."
exit 1
fi
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false

- name: Check disk cleanup precedes every pool-build restore
run: |
python3 -c 'import yaml' 2>/dev/null || sudo apt-get install -y python3-yaml
PYTHONPATH=python python3 -m lean_pool.workflow_disk
101 changes: 101 additions & 0 deletions python/lean_pool/workflow_disk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""Require runner disk cleanup before any job restores the whole-pool build cache.

The pool build cache (about 8 GB compressed) plus the Lean dependency cache do
not fit in a hosted runner's default free space, so a job that restores it
without first deleting unused preinstalled toolchains dies with "No space left
on device". This check fails Workflow Lint when a job skips that cleanup.
"""

from __future__ import annotations

import argparse
from pathlib import Path
from typing import Any

import yaml

ACTION_PATH = Path(".github/actions/free-disk-space/action.yml")
ACTION_REFERENCE = "./.github/actions/free-disk-space"
POOL_BUILD_CACHE_PREFIX = "LeanPoolBuild-"
CLEANUP_MARKER = "sudo rm -rf /usr/share/dotnet"
RESTORING_ACTIONS = ("actions/cache@", "actions/cache/restore@")


def cleanup_script(root: Path) -> str:
"""Return the shell script the shared free-disk-space action runs."""
action = yaml.safe_load((root / ACTION_PATH).read_text())
return action["runs"]["steps"][0]["run"].strip()


def restores_pool_build(step: dict[str, Any]) -> bool:
"""Whether a step downloads the whole-pool build cache onto the runner."""
if not str(step.get("uses", "")).startswith(RESTORING_ACTIONS):
return False
settings = step.get("with") or {}
if settings.get("lookup-only") in (True, "true"):
return False
keys = f"{settings.get('key', '')}\n{settings.get('restore-keys', '')}"
return POOL_BUILD_CACHE_PREFIX in keys


def frees_disk(step: dict[str, Any], script: str) -> bool:
"""Whether a step runs the shared cleanup, as the action or an exact copy."""
if step.get("uses") == ACTION_REFERENCE:
return True
return str(step.get("run", "")).strip() == script
Comment thread
Vilin97 marked this conversation as resolved.
Resolved


def job_errors(location: str, steps: list[dict[str, Any]], script: str) -> list[str]:
"""Report a missing, late, or drifted cleanup step in one job."""
errors = []
for step in steps:
run = str(step.get("run", ""))
if CLEANUP_MARKER in run and run.strip() != script:
errors.append(
f"{location}: inline disk cleanup differs from {ACTION_PATH}; "
f"use `uses: {ACTION_REFERENCE}` or copy its script exactly"
)
cleanup_conditions = []
for step in steps:
if frees_disk(step, script):
cleanup_conditions.append(step.get("if"))
elif restores_pool_build(step):
# A conditional cleanup only covers a restore with the same condition.
if not {None, step.get("if")} & set(cleanup_conditions):
errors.append(
f"{location}: step {step.get('name', step['uses'])!r} "
f"restores the pool build cache without an earlier cleanup "
f"that always runs with it; add `uses: {ACTION_REFERENCE}` "
f"after checkout"
)
break
return errors


def workflow_errors(root: Path) -> list[str]:
"""Check every job in every workflow under ``root``."""
script = cleanup_script(root)
errors = []
for path in sorted((root / ".github/workflows").glob("*.y*ml")):
workflow = yaml.safe_load(path.read_text()) or {}
for name, job in (workflow.get("jobs") or {}).items():
location = f"{path.relative_to(root)} job {name}"
errors.extend(job_errors(location, job.get("steps") or [], script))
return errors


def main() -> None:
"""Fail when a workflow job restores the pool build without freeing disk."""
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--root", type=Path, default=Path.cwd())
arguments = parser.parse_args()
errors = workflow_errors(arguments.root)
if errors:
for error in errors:
print(f"::error::{error}")
raise SystemExit(1)
print("Every job frees runner disk before restoring the pool build cache")


if __name__ == "__main__":
main()
Loading
Loading