Skip to content

[FEATURE] Paper mode in hub: blue palette, banner, sample runner - closes #86 #87 #196

[FEATURE] Paper mode in hub: blue palette, banner, sample runner - closes #86 #87

[FEATURE] Paper mode in hub: blue palette, banner, sample runner - closes #86 #87 #196

Workflow file for this run

name: Code Quality & Testing
# Workflow optimized for app/ directory structure
on:
push:
branches: [ 'main', 'master', 'develop', 'release/*' ] # Only important branches
pull_request:
branches: [ 'main', 'master', 'develop' ] # PRs to main branches only
workflow_dispatch: # Allow manual triggering for testing
env:
PYTHON_VERSION: '3.11'
jobs:
security-scan:
name: Security & Code Quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('app/requirements.txt', 'requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install security tools
run: |
python -m pip install --upgrade pip
pip install bandit safety flake8 black isort pbr
# Install project dependencies from app directory
if [ -f app/requirements.txt ]; then
pip install -r app/requirements.txt
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: Code formatting check
run: |
black --check --diff . || echo "Black formatting issues found"
isort --check-only --diff . || echo "Import sorting issues found"
continue-on-error: true
- name: Linting
run: |
# Basic syntax and import errors only
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-ignore=E203,W503
# Extended linting with warnings
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics --extend-ignore=E203,W503
continue-on-error: true
- name: Security scan with Bandit
run: |
bandit -r . -f json -o bandit-report.json -x tests/ || true
bandit -r . -f txt || true
continue-on-error: true
- name: Dependency security check
run: |
safety check --json --output safety-report.json || true
safety check || true
continue-on-error: true
- name: Upload security reports
uses: actions/upload-artifact@v4
with:
name: security-reports
path: |
bandit-report.json
safety-report.json
if: always()
test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11']
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('app/requirements.txt', 'requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov pytest-mock pytest-benchmark memory-profiler
# Install project dependencies from app directory
if [ -f app/requirements.txt ]; then
pip install -r app/requirements.txt
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
# Install test-specific dependencies including cryptography
pip install responses requests-mock cryptography
- name: Create test environment
run: |
# Create minimal test environment
mkdir -p logs
export POWERTRADER_ENV=test
export POWERTRADER_LOG_LEVEL=DEBUG
- name: Run tests
run: |
# Set test environment variables
export POWERTRADER_ENV=test
export POWERTRADER_LOG_LEVEL=DEBUG
export POWERTRADER_SKIP_CREDENTIALS=true
# Set up Robinhood API credentials from GitHub secrets (for CI/CD)
export POWERTRADER_ROBINHOOD_API_KEY="${{ secrets.ROBINHOOD_API_KEY }}"
export POWERTRADER_ROBINHOOD_PRIVATE_KEY="${{ secrets.ROBINHOOD_PRIVATE_KEY }}"
# Run tests from .github/scripts directory
if [ -d ".github/scripts" ] && [ -f ".github/scripts/conftest.py" ]; then
echo "Running pytest on .github/scripts/"
python -m pytest .github/scripts/ -v --cov=app --cov-report=xml --cov-report=html --tb=short --continue-on-collection-errors || echo "Tests completed with warnings/errors"
else
echo "No test scripts found, running basic import test"
python -c "
import sys
print('Python version:', sys.version)
print('Import test: PASS')
"
fi
# Also run new advanced feature tests in app directory
if [ -f "app/test_advanced_features.py" ]; then
echo "Running advanced features tests..."
cd app && python test_advanced_features.py || echo "Advanced tests completed with warnings/errors"
fi
if [ -f "app/test_integration.py" ]; then
echo "Running integration tests..."
cd app && python test_integration.py || echo "Integration tests completed with warnings/errors"
fi
continue-on-error: true
- name: Upload coverage reports
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
token: ${{ secrets.CODECOV_TOKEN }}
if: always()
build-and-validate:
name: Build & Integration Test
runs-on: ubuntu-latest
needs: [security-scan]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Install project dependencies from app directory
if [ -f app/requirements.txt ]; then
pip install -r app/requirements.txt
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
- name: Basic import test
run: |
# Set up Robinhood API credentials from GitHub secrets (for CI/CD)
export POWERTRADER_ROBINHOOD_API_KEY="${{ secrets.ROBINHOOD_API_KEY }}"
export POWERTRADER_ROBINHOOD_PRIVATE_KEY="${{ secrets.ROBINHOOD_PRIVATE_KEY }}"
export POWERTRADER_ENV=test
# Test basic Python file imports from app directory
echo "Testing basic imports..."
python -c "
import sys, os
print('Python version:', sys.version)
print('Current directory:', os.getcwd())
print('Files in root:', os.listdir('.'))
# Add app directory to path if it exists
if os.path.exists('app'):
sys.path.insert(0, os.path.abspath('app'))
print('Added app directory to Python path')
print('Files in app directory:', os.listdir('app'))
else:
print('No app directory found, checking root')
# Try to import main files if they exist
files_to_test = ['pt_hub', 'pt_trader', 'pt_thinker', 'pt_trainer', 'pt_desktop_app']
for module_name in files_to_test:
try:
__import__(module_name)
print(f'✓ {module_name}: PASS')
except Exception as e:
print(f'✗ {module_name}: FAIL - {str(e)[:100]}')
"
- name: Validate configuration files
run: |
# Check for common configuration files
echo "Validating configuration files..."
if [ -f "app/requirements.txt" ]; then
echo "✓ app/requirements.txt found"
pip check || echo "⚠ Dependency conflicts detected"
elif [ -f "requirements.txt" ]; then
echo "✓ requirements.txt found"
pip check || echo "⚠ Dependency conflicts detected"
else
echo "- requirements.txt not found"
fi
if [ -f "README.md" ]; then
echo "✓ README.md found"
fi
if [ -d "app" ]; then
echo "✓ app/ directory found"
fi
if [ -d "app" ]; then
echo "✓ app/ directory found"
echo "App files:"
ls -la app/*.py 2>/dev/null || echo "No Python files in app directory"
fi
if [ -d "docs" ]; then
echo "✓ Documentation directory found"
echo "Documentation files:"
find docs -name "*.md" | head -10
fi
- name: Test project structure
run: |
echo "Project structure validation..."
# Check for main Python files in app directory
echo "Main Python files:"
if [ -d "app" ]; then
ls -la app/*.py 2>/dev/null || echo "No Python files in app directory"
else
ls -la *.py 2>/dev/null || echo "No Python files in root directory"
fi
# Check for important directories
for dir in app docs tests .github; do
if [ -d "$dir" ]; then
echo "✓ $dir/ directory exists"
else
echo "- $dir/ directory missing"
fi
done
# Test app directory structure
if [ -d "app" ]; then
echo "✓ app/ directory exists"
if [ -f "app/pt_desktop_app.py" ]; then
python -c "import ast; ast.parse(open('app/pt_desktop_app.py').read())" && echo "✓ pt_desktop_app.py syntax valid" || echo "✗ pt_desktop_app.py syntax error"
fi
fi