Skip to content

Commit a7ad2fd

Browse files
authored
Add Flask Port Finder test workflow
This workflow runs tests for the Flask Port Finder and includes a Redis service for testing. It also configures omnipkg for non-interactive use and archives the demo output.
1 parent 7c5dcb1 commit a7ad2fd

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: "🧪 Flask Port Finder & Auto-Healing Test"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
services:
14+
redis:
15+
image: redis:7
16+
options: >-
17+
--health-cmd "redis-cli ping"
18+
--health-interval 10s
19+
--health-timeout 5s
20+
--health-retries 5
21+
ports:
22+
- 6379:6379
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Python 3.11
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: '3.11'
32+
33+
- name: 📦 Install omnipkg (editable) and Redis client
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -e . redis
37+
38+
- name: Configure omnipkg for non-interactive use
39+
run: |
40+
python - << 'EOF'
41+
import sys
42+
import site
43+
import json
44+
from pathlib import Path
45+
import os
46+
import sysconfig
47+
48+
try:
49+
site_packages_path = site.getsitepackages()[0]
50+
except (IndexError, AttributeError):
51+
site_packages_path = sysconfig.get_paths()['purelib']
52+
53+
project_root = Path(os.environ['GITHUB_WORKSPACE'])
54+
55+
builder_script = project_root / 'omnipkg' / 'package_meta_builder.py'
56+
if not builder_script.exists():
57+
print(f"Error: {builder_script} does not exist")
58+
sys.exit(1)
59+
60+
config_data = {
61+
'site_packages_path': site_packages_path,
62+
'multiversion_base': str(Path(site_packages_path) / '.omnipkg_versions'),
63+
'python_executable': sys.executable,
64+
'builder_script_path': str(builder_script),
65+
'redis_host': 'localhost',
66+
'redis_port': 6379,
67+
'redis_key_prefix': 'omnipkg:pkg:',
68+
'paths_to_index': [str(Path(sys.executable).parent), '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin'],
69+
'auto_cleanup': True,
70+
'cleanup_threshold_days': 30
71+
}
72+
73+
config_dir = Path.home() / '.config' / 'omnipkg'
74+
config_dir.mkdir(parents=True, exist_ok=True)
75+
config_path = config_dir / 'config.json'
76+
77+
try:
78+
with open(config_path, 'w') as f:
79+
json.dump(config_data, f, indent=2)
80+
print(f'omnipkg config created at {config_path}:')
81+
print(json.dumps(config_data, indent=2))
82+
except Exception as e:
83+
print(f"Error writing config: {e}")
84+
sys.exit(1)
85+
EOF
86+
87+
- name: 🧪 Run the Demo - Flask Port Finder Test
88+
id: run_demo
89+
run: |
90+
echo "--- Running Omnipkg Demo for Flask Port Finder (Auto-Healing) ---"
91+
mkdir -p /tmp/omnipkg-artifacts
92+
93+
# Run demo #9 and capture output and the correct exit code from the omnipkg command
94+
timeout 900 bash -c 'echo "9" | omnipkg demo 2>&1 | tee /tmp/omnipkg-artifacts/flask_demo_output.txt'
95+
DEMO_EXIT_CODE=${PIPESTATUS[0]}
96+
97+
# Save output to GitHub step summary for easy viewing
98+
echo "## Flask Port Finder Demo Output" >> $GITHUB_STEP_SUMMARY
99+
echo '```' >> $GITHUB_STEP_SUMMARY
100+
cat /tmp/omnipkg-artifacts/flask_demo_output.txt >> $GITHUB_STEP_SUMMARY
101+
echo '```' >> $GITHUB_STEP_SUMMARY
102+
103+
# The overall script should exit with 0 if the final, healed run was successful.
104+
# We add extra checks of the log content for robustness.
105+
if [ $DEMO_EXIT_CODE -eq 0 ]; then
106+
echo "Demo completed with successful exit code ($DEMO_EXIT_CODE). Performing log verification..."
107+
echo "demo_outcome=success" >> $GITHUB_OUTPUT
108+
109+
# Count the number of passed tests in the final summary block
110+
PASSED_COUNT=$(grep -c "✅ TEST .* PASSED" /tmp/omnipkg-artifacts/flask_demo_output.txt || echo "0")
111+
112+
# Check that all 6 tests are marked as passed
113+
if [ "$PASSED_COUNT" -ge 6 ] && grep -q "Demo completed successfully" /tmp/omnipkg-artifacts/flask_demo_output.txt; then
114+
echo "✅ Verification PASSED: Found $PASSED_COUNT passed tests and success message in the logs."
115+
else
116+
echo "❌ Verification FAILED: Expected 6 PASSED tests and a success message, but validation failed."
117+
echo "--- Full Demo Output ---"
118+
cat /tmp/omnipkg-artifacts/flask_demo_output.txt
119+
exit 1
120+
fi
121+
else
122+
echo "❌ Demo failed with a non-zero exit code: $DEMO_EXIT_CODE."
123+
echo "demo_outcome=failure" >> $GITHUB_OUTPUT
124+
echo "--- Full Demo Output ---"
125+
cat /tmp/omnipkg-artifacts/flask_demo_output.txt
126+
exit 1
127+
fi
128+
129+
- name: Archive Demo Output
130+
if: always()
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: omnipkg-flask-demo-output
134+
path: /tmp/omnipkg-artifacts/
135+
retention-days: 7
136+
compression-level: 6

0 commit comments

Comments
 (0)