Fix flake8 undefined names in CI #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main, develop] | |
| pull_request: | |
| branches: [main] | |
| env: | |
| PYTHON_VERSION: "3.12" | |
| ENVIRONMENT: "test" | |
| RATE_LIMIT_ENABLED: "false" | |
| jobs: | |
| lint: | |
| name: Lint & Format Check | |
| 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: Install linting tools | |
| run: | | |
| pip install flake8 | |
| - name: Lint with flake8 (errors only) | |
| run: | | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics \ | |
| --exclude=text-generation-webui,text-generation-webui_BACKUP,alembic,.git | |
| - name: Lint with flake8 (warnings) | |
| run: | | |
| flake8 . --count --exit-zero --max-complexity=15 --max-line-length=120 --statistics \ | |
| --exclude=text-generation-webui,text-generation-webui_BACKUP,alembic,.git | |
| test: | |
| name: Tests | |
| 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('requirements.txt', 'requirements-dev.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt -r requirements-dev.txt | |
| - name: Run tests with coverage | |
| run: | | |
| pytest tests/ -v --cov=. --cov-report=xml --cov-report=term-missing \ | |
| --ignore=text-generation-webui \ | |
| --ignore=text-generation-webui_BACKUP | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| files: ./coverage.xml | |
| fail_ci_if_error: false | |
| security: | |
| name: Security Scan | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install security tools | |
| run: | | |
| pip install bandit safety | |
| - name: Run Bandit security scan | |
| run: | | |
| bandit -r . -x ./text-generation-webui,./text-generation-webui_BACKUP,./tests,./alembic \ | |
| --severity-level medium \ | |
| -f json -o bandit-report.json || true | |
| bandit -r . -x ./text-generation-webui,./text-generation-webui_BACKUP,./tests,./alembic \ | |
| --severity-level medium || true | |
| - name: Check dependencies for vulnerabilities | |
| run: | | |
| safety check -r requirements.txt --full-report || true | |
| build: | |
| name: Build Check | |
| runs-on: ubuntu-latest | |
| needs: [test, security] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install dependencies | |
| run: | | |
| pip install -r requirements.txt | |
| - name: Verify imports | |
| run: | | |
| python -c "from main import app; print('FastAPI app loaded successfully')" | |
| python -c "from middleware import RequestIDMiddleware; print('Middleware loaded')" | |
| python -c "from models import ScanRequest; print('Models loaded')" | |
| - name: Check database migrations | |
| run: | | |
| # Verify alembic can run (without actually migrating) | |
| pip install alembic | |
| alembic check || echo "Alembic check completed" | |
| notify: | |
| name: Notify on Failure | |
| runs-on: ubuntu-latest | |
| needs: [lint, test, security, build] | |
| if: failure() | |
| steps: | |
| - name: Create failure summary | |
| run: | | |
| echo "## CI Pipeline Failed" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "One or more jobs failed. Please check the logs for details." >> $GITHUB_STEP_SUMMARY |