forked from garagesteve1155/PowerTrader_AI
-
Notifications
You must be signed in to change notification settings - Fork 1
288 lines (246 loc) · 9.47 KB
/
code-quality.yml
File metadata and controls
288 lines (246 loc) · 9.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
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