Skip to content

Commit 6b060df

Browse files
authored
ci: reduce disk usage in unit tests (free space + test-only deps) (#412)
* ci: reduce disk usage in unit tests (free space + test-only deps) * ci: install main+test deps (skip dev), add disk check, fix step comments * ci: address PR review — remove --no-root/--no-cache, configurable MIN_FREE_GB * ci: clarify deps rationale, fix disk check step name and int parsing * ci: robust disk check (bytes), set MIN_FREE_GB=7, safe parallel cleanup
1 parent af3abd4 commit 6b060df

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

.github/workflows/04-pytest.yml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
TESTING: true
2525
SKIP_AUTH: true
2626
DEVELOPMENT_MODE: true
27+
MIN_FREE_GB: 7 # Minimum free disk space (GB) after cleanup
2728
# Test environment variables
2829
JWT_SECRET_KEY: test-secret-key-for-ci
2930
RAG_LLM: openai
@@ -59,7 +60,26 @@ jobs:
5960
virtualenvs-create: true
6061
virtualenvs-in-project: true
6162

62-
# 3️⃣ Cache Poetry dependencies for faster builds
63+
# 3️⃣ Free up disk space before heavy operations
64+
- name: 🧹 Free Up Disk Space
65+
run: |
66+
echo "Initial: $(df -h / | awk 'NR==2 {print $4}') available"
67+
68+
# Remove large packages in parallel
69+
for p in \
70+
/usr/share/dotnet \
71+
/opt/ghc \
72+
/usr/local/share/boost \
73+
"$AGENT_TOOLSDIRECTORY" \
74+
/usr/local/lib/android \
75+
/usr/share/swift; do
76+
if [ -e "$p" ]; then sudo rm -rf "$p" & fi
77+
done
78+
wait
79+
80+
echo "After cleanup: $(df -h / | awk 'NR==2 {print $4}') available"
81+
82+
# 4️⃣ Cache Poetry dependencies for faster builds
6383
- name: 📚 Cache Poetry dependencies
6484
uses: actions/cache@v4
6585
with:
@@ -70,11 +90,32 @@ jobs:
7090
restore-keys: |
7191
${{ runner.os }}-poetry-
7292
73-
# 4️⃣ Install Python dependencies
74-
- name: 📥 Install dependencies
75-
run: cd backend && poetry install --with dev,test
93+
# 5️⃣ Install Python dependencies (main + test, skip dev)
94+
- name: 📥 Install main + test dependencies (skip dev)
95+
run: |
96+
cd backend
97+
# Install runtime + test deps; skip dev tools to reduce disk usage.
98+
# Note: We intentionally skip the 'dev' group in unit tests to avoid
99+
# heavy linters/type-checkers. pytest-cov and friends are declared in
100+
# the 'test' group in pyproject.toml, so coverage still works.
101+
# If coverage fails due to env drift, consider adding pytest-cov here
102+
# explicitly or switching to `--with dev,test` selectively.
103+
poetry install --with test --without dev
104+
105+
# 6️⃣ Validate free disk space after cleanup (optional)
106+
- name: ✅ Ensure sufficient free disk space
107+
run: |
108+
THRESHOLD=${MIN_FREE_GB:-5}
109+
# Compare using bytes to avoid rounding edge cases
110+
FREE_BYTES=$(df -B1 / | awk 'NR==2 {print $4}')
111+
THRESHOLD_BYTES=$((THRESHOLD*1024*1024*1024))
112+
echo "Free space: $((FREE_BYTES/1024/1024/1024))G (threshold: ${THRESHOLD}G)"
113+
if [ "$FREE_BYTES" -lt "$THRESHOLD_BYTES" ]; then
114+
echo "Error: Less than ${THRESHOLD}G free after cleanup"
115+
exit 1
116+
fi
76117
77-
# 5️⃣ Run unit/atomic tests with coverage
118+
# 7️⃣ Run unit/atomic tests with coverage
78119
- name: 🧪 Run unit tests with coverage
79120
run: |
80121
cd backend

0 commit comments

Comments
 (0)