Skip to content

Commit 6262f96

Browse files
committed
fix rclone install
fix re-run passed tests to not fail the ci add file cleanup after execution
1 parent c35250a commit 6262f96

File tree

1 file changed

+129
-5
lines changed

1 file changed

+129
-5
lines changed

.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,17 @@ jobs:
142142
TS=$(date +'%Y_%^B_%d__%H_%M_%S');
143143
echo "TS=$TS" >> "$GITHUB_ENV"
144144
echo "TIMESTAMP=$TS" >> "$GITHUB_ENV"
145+
146+
# Fix any interrupted dpkg operations first
147+
sudo dpkg --configure -a || true
148+
149+
# Clean up any partial packages
150+
sudo apt-get clean
151+
sudo apt-get autoclean
152+
153+
# Update package lists and install rclone
145154
sudo apt-get update -y && sudo apt-get install -y rclone
155+
146156
mkdir -p ~/.config/rclone
147157
cat > ~/.config/rclone/rclone.conf <<EOF
148158
[r2]
@@ -276,17 +286,55 @@ jobs:
276286
run: |
277287
set +e
278288
pytest mx-chain-testing-suite/scenarios/ --html=report.html --self-contained-html --continue-on-collection-errors
279-
PYTEST_EXIT_CODE=$?
289+
INITIAL_PYTEST_EXIT_CODE=$?
280290
set -e
281-
echo "PYTEST_EXIT_CODE=$PYTEST_EXIT_CODE" >> $GITHUB_ENV
282-
echo "Pytest exit code: $PYTEST_EXIT_CODE"
291+
292+
echo "Initial pytest exit code: $INITIAL_PYTEST_EXIT_CODE"
293+
294+
# Parse the HTML report to determine actual test status
295+
FINAL_PYTEST_EXIT_CODE=$INITIAL_PYTEST_EXIT_CODE
296+
283297
if [ -f "report.html" ]; then
284298
echo "Report generated successfully."
299+
300+
# Extract test summary from HTML report using multiple parsing approaches
301+
FAILED_TESTS=$(grep -E '[0-9]+ Failed|Failed.*[0-9]+' report.html | head -1 | grep -o '[0-9]\+' | head -1 || echo "0")
302+
ERROR_TESTS=$(grep -E '[0-9]+ Errors|Errors.*[0-9]+' report.html | head -1 | grep -o '[0-9]\+' | head -1 || echo "0")
303+
RERUN_TESTS=$(grep -E '[0-9]+ Reruns|Reruns.*[0-9]+' report.html | head -1 | grep -o '[0-9]\+' | head -1 || echo "0")
304+
305+
# Fallback: check for "0 Failed" pattern directly
306+
if grep -q "0 Failed" report.html && [ "$INITIAL_PYTEST_EXIT_CODE" -ne 0 ]; then
307+
echo "Detected '0 Failed' pattern in report despite non-zero exit code - likely successful reruns"
308+
FAILED_TESTS=0
309+
fi
310+
311+
echo "Failed tests: $FAILED_TESTS"
312+
echo "Error tests: $ERROR_TESTS"
313+
echo "Rerun tests: $RERUN_TESTS"
314+
315+
# Determine final status based on actual test results
316+
if [ "$FAILED_TESTS" -eq 0 ] && [ "$ERROR_TESTS" -eq 0 ]; then
317+
if [ "$RERUN_TESTS" -gt 0 ]; then
318+
echo "✅ All tests passed after $RERUN_TESTS reruns - considering as SUCCESS"
319+
else
320+
echo "✅ All tests passed on first attempt"
321+
fi
322+
FINAL_PYTEST_EXIT_CODE=0
323+
else
324+
echo "❌ Tests have genuine failures: $FAILED_TESTS failed, $ERROR_TESTS errors"
325+
FINAL_PYTEST_EXIT_CODE=1
326+
fi
327+
328+
# Move report to reports directory
285329
mkdir -p ./reports
286330
mv report.html ./reports/
287331
else
288-
echo "Report not found."
332+
echo "❌ Report not found - using original exit code"
333+
FINAL_PYTEST_EXIT_CODE=$INITIAL_PYTEST_EXIT_CODE
289334
fi
335+
336+
echo "PYTEST_EXIT_CODE=$FINAL_PYTEST_EXIT_CODE" >> $GITHUB_ENV
337+
echo "Final pytest exit code: $FINAL_PYTEST_EXIT_CODE"
290338
291339
- name: Stage report for R2
292340
run: |
@@ -482,4 +530,80 @@ jobs:
482530
exit 1
483531
else
484532
echo "Tests passed successfully."
485-
fi
533+
fi
534+
535+
536+
- name: Cleanup Workspace and Processes
537+
if: always()
538+
run: |
539+
echo "🧹 Starting SAFE cleanup for job ${{ github.run_id }}..."
540+
541+
# Get current working directory to limit cleanup scope
542+
WORKSPACE_DIR=$(pwd)
543+
echo "Workspace directory: $WORKSPACE_DIR"
544+
545+
# 1. Kill only OUR ChainSimulator processes (by checking working directory)
546+
echo "Killing ChainSimulator processes from this workspace..."
547+
for pid in $(pgrep -f "chainsimulator"); do
548+
if [ -n "$pid" ]; then
549+
CWD=$(pwdx $pid 2>/dev/null | awk '{print $2}' || echo "")
550+
if [[ "$CWD" == *"$WORKSPACE_DIR"* ]]; then
551+
echo "Killing chainsimulator process $pid from our workspace"
552+
kill -TERM $pid 2>/dev/null || true
553+
sleep 2
554+
kill -9 $pid 2>/dev/null || true
555+
fi
556+
fi
557+
done
558+
559+
# 2. Kill only OUR pytest processes (by checking if they're in our workspace)
560+
echo "Killing pytest processes from this workspace..."
561+
for pid in $(pgrep -f "pytest.*scenarios"); do
562+
if [ -n "$pid" ]; then
563+
CWD=$(pwdx $pid 2>/dev/null | awk '{print $2}' || echo "")
564+
if [[ "$CWD" == *"$WORKSPACE_DIR"* ]]; then
565+
echo "Killing pytest process $pid from our workspace"
566+
kill -TERM $pid 2>/dev/null || true
567+
fi
568+
fi
569+
done
570+
571+
# 3. Remove only OUR temporary files (with unique identifiers)
572+
echo "Removing temporary files from this job..."
573+
rm -f /tmp/chainsim_init_${{ github.run_id }}.log || true
574+
rm -f /tmp/chain_simulator_initialized_${{ github.run_id }}.lock || true
575+
# Only remove temp files that might be from this job (be very specific)
576+
rm -f /tmp/chainsim_init.log || true # Only if we created it without job ID
577+
rm -f /tmp/chain_simulator_initialized.lock || true # Only if we created it without job ID
578+
579+
# 4. Clean up ONLY our workspace directories
580+
echo "Cleaning up workspace directories..."
581+
rm -rf "$WORKSPACE_DIR/mx-chain-go" || true
582+
rm -rf "$WORKSPACE_DIR/mx-chain-simulator-go" || true
583+
rm -rf "$WORKSPACE_DIR/mx-chain-testing-suite" || true
584+
rm -rf "$WORKSPACE_DIR/reports" || true
585+
rm -rf "$WORKSPACE_DIR/r2_upload" || true
586+
rm -f "$WORKSPACE_DIR/report.html" || true
587+
588+
# 5. Clean up Python cache ONLY in our workspace
589+
echo "Cleaning Python cache in workspace..."
590+
find "$WORKSPACE_DIR" -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
591+
find "$WORKSPACE_DIR" -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
592+
find "$WORKSPACE_DIR" -type f -name "*.pyc" -delete 2>/dev/null || true
593+
594+
# 6. Check disk space (informational only)
595+
echo "Checking remaining disk space..."
596+
df -h "$WORKSPACE_DIR" || true
597+
598+
# 7. Show what processes are still running FROM OUR WORKSPACE (for debugging)
599+
echo "Checking for remaining processes from our workspace:"
600+
for pid in $(pgrep -f "chainsimulator\|pytest.*scenarios"); do
601+
if [ -n "$pid" ]; then
602+
CWD=$(pwdx $pid 2>/dev/null | awk '{print $2}' || echo "unknown")
603+
if [[ "$CWD" == *"$WORKSPACE_DIR"* ]]; then
604+
echo "⚠️ Process $pid still running from our workspace: $CWD"
605+
fi
606+
fi
607+
done
608+
609+
echo "✅ Safe cleanup completed for job ${{ github.run_id }}!"

0 commit comments

Comments
 (0)