|
| 1 | +name: Python Tests & Validation |
1 | 2 |
|
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master ] |
| 8 | + schedule: |
| 9 | + - cron: '0 0 * * *' # Daily run |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + python-version: ["3.9", "3.10", "3.11"] |
| 17 | + os: [ubuntu-latest] |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v3 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Set up Python ${{ matrix.python-version }} |
| 26 | + uses: actions/setup-python@v4 |
| 27 | + with: |
| 28 | + python-version: ${{ matrix.python-version }} |
| 29 | + cache: 'pip' |
| 30 | + |
| 31 | + - name: Display Python version |
| 32 | + run: python -c "import sys; print(f'Python {sys.version}')" |
| 33 | + |
| 34 | + - name: Install system dependencies |
| 35 | + run: | |
| 36 | + sudo apt-get update |
| 37 | + sudo apt-get install -y build-essential python3-dev |
| 38 | +
|
| 39 | + - name: Install Python dependencies |
| 40 | + run: | |
| 41 | + python -m pip install --upgrade pip |
| 42 | + pip install pytest pytest-cov pytest-asyncio |
| 43 | + pip install -r requirements.txt |
| 44 | + python -m spacy download en_core_web_sm |
| 45 | + python -c "import nltk; nltk.download('punkt'); nltk.download('wordnet')" |
| 46 | +
|
| 47 | + - name: Run basic syntax check |
| 48 | + run: | |
| 49 | + echo "Checking Python syntax..." |
| 50 | + python -m py_compile src/truthprobe_v3.py |
| 51 | + if [ -f "src/enhanced_detector.py" ]; then |
| 52 | + python -m py_compile src/enhanced_detector.py |
| 53 | + fi |
| 54 | +
|
| 55 | + - name: Run tests with pytest |
| 56 | + run: | |
| 57 | + python -m pytest tests/ -v --cov=src --cov-report=xml --cov-report=html --junitxml=junit/test-results.xml |
| 58 | + env: |
| 59 | + PYTHONPATH: ${{ github.workspace }} |
| 60 | + |
| 61 | + - name: Upload coverage to Codecov |
| 62 | + uses: codecov/codecov-action@v3 |
| 63 | + with: |
| 64 | + file: ./coverage.xml |
| 65 | + fail_ci_if_error: true |
| 66 | + |
| 67 | + - name: Upload test results |
| 68 | + if: always() |
| 69 | + uses: actions/upload-artifact@v3 |
| 70 | + with: |
| 71 | + name: test-results-${{ matrix.python-version }} |
| 72 | + path: | |
| 73 | + junit/test-results.xml |
| 74 | + coverage.xml |
| 75 | + htmlcov/ |
| 76 | +
|
| 77 | + lint: |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: test |
| 80 | + if: always() |
| 81 | + |
| 82 | + steps: |
| 83 | + - name: Checkout repository |
| 84 | + uses: actions/checkout@v3 |
| 85 | + |
| 86 | + - name: Set up Python |
| 87 | + uses: actions/setup-python@v4 |
| 88 | + with: |
| 89 | + python-version: "3.10" |
| 90 | + |
| 91 | + - name: Install linting tools |
| 92 | + run: | |
| 93 | + pip install flake8 black isort mypy bandit |
| 94 | +
|
| 95 | + - name: Check code formatting with Black |
| 96 | + run: | |
| 97 | + black --check src/ tests/ --diff |
| 98 | +
|
| 99 | + - name: Lint with flake8 |
| 100 | + run: | |
| 101 | + flake8 src/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics |
| 102 | + flake8 src/ tests/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 103 | +
|
| 104 | + - name: Check import order with isort |
| 105 | + run: | |
| 106 | + isort --check-only --diff src/ tests/ |
| 107 | +
|
| 108 | + - name: Type check with mypy |
| 109 | + run: | |
| 110 | + mypy src/ --ignore-missing-imports --strict |
| 111 | +
|
| 112 | + - name: Security scan with bandit |
| 113 | + run: | |
| 114 | + bandit -r src/ -f json -o bandit-report.json || true |
| 115 | +
|
| 116 | + build: |
| 117 | + runs-on: ubuntu-latest |
| 118 | + needs: [test, lint] |
| 119 | + if: always() |
| 120 | + |
| 121 | + steps: |
| 122 | + - name: Checkout repository |
| 123 | + uses: actions/checkout@v3 |
| 124 | + |
| 125 | + - name: Set up Python |
| 126 | + uses: actions/setup-python@v4 |
| 127 | + with: |
| 128 | + python-version: "3.10" |
| 129 | + |
| 130 | + - name: Build package |
| 131 | + run: | |
| 132 | + python setup.py sdist bdist_wheel |
| 133 | +
|
| 134 | + - name: Verify package |
| 135 | + run: | |
| 136 | + pip install twine |
| 137 | + twine check dist/* |
| 138 | +
|
| 139 | + - name: Upload build artifacts |
| 140 | + uses: actions/upload-artifact@v3 |
| 141 | + with: |
| 142 | + name: dist-package |
| 143 | + path: dist/ |
| 144 | + |
| 145 | + deploy-docs: |
| 146 | + runs-on: ubuntu-latest |
| 147 | + needs: build |
| 148 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 149 | + |
| 150 | + steps: |
| 151 | + - name: Checkout repository |
| 152 | + uses: actions/checkout@v3 |
| 153 | + |
| 154 | + - name: Deploy to GitHub Pages |
| 155 | + uses: peaceiris/actions-gh-pages@v3 |
| 156 | + with: |
| 157 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 158 | + publish_dir: ./docs |
| 159 | + keep_files: true |
| 160 | + |
| 161 | + status: |
| 162 | + runs-on: ubuntu-latest |
| 163 | + needs: [test, lint, build] |
| 164 | + if: always() |
| 165 | + |
| 166 | + steps: |
| 167 | + - name: Create Status Badge |
| 168 | + run: | |
| 169 | + echo "All checks passed successfully!" > status.txt |
| 170 | + echo "✅ All tests passed" >> status.txt |
| 171 | + date >> status.txt |
| 172 | + |
| 173 | + - name: Upload Status |
| 174 | + uses: actions/upload-artifact@v3 |
| 175 | + with: |
| 176 | + name: status |
| 177 | + path: status.txt |
0 commit comments