|
| 1 | +name: CI - Linting and Testing |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ['**'] # Run on all branches |
| 6 | + pull_request: |
| 7 | + branches: ['**'] # Run on all pull requests |
| 8 | + |
| 9 | +jobs: |
| 10 | + code-quality: |
| 11 | + name: Code Quality Checks |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Set up Python |
| 19 | + uses: actions/setup-python@v5 |
| 20 | + with: |
| 21 | + python-version: '3.11' |
| 22 | + cache: 'pip' |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + python -m pip install --upgrade pip |
| 27 | + pip install black isort mypy pytest pytest-cov |
| 28 | + # Install project dependencies if requirements files exist |
| 29 | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 30 | + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi |
| 31 | +
|
| 32 | + - name: Check code formatting with Black |
| 33 | + run: | |
| 34 | + black --check --diff . |
| 35 | +
|
| 36 | + - name: Check import sorting with isort |
| 37 | + run: | |
| 38 | + isort --check-only --diff . |
| 39 | +
|
| 40 | + - name: Type checking with mypy |
| 41 | + run: | |
| 42 | + mypy *.py --ignore-missing-imports |
| 43 | + continue-on-error: true # Don't fail the build on type errors initially |
| 44 | + |
| 45 | + - name: Run tests with pytest |
| 46 | + run: | |
| 47 | + python -m pytest --cov=. --cov-report=xml --cov-report=term |
| 48 | + continue-on-error: false # Fail if tests don't pass |
| 49 | + |
| 50 | + - name: Upload coverage reports |
| 51 | + uses: codecov/codecov-action@v4 |
| 52 | + if: always() |
| 53 | + with: |
| 54 | + file: ./coverage.xml |
| 55 | + flags: unittests |
| 56 | + fail_ci_if_error: false |
| 57 | + env: |
| 58 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 59 | + |
| 60 | + lint-summary: |
| 61 | + name: Linting Summary |
| 62 | + runs-on: ubuntu-latest |
| 63 | + needs: code-quality |
| 64 | + if: always() |
| 65 | + |
| 66 | + steps: |
| 67 | + - name: Check code quality status |
| 68 | + run: | |
| 69 | + if [ "${{ needs.code-quality.result }}" == "failure" ]; then |
| 70 | + echo "❌ Code quality checks failed" |
| 71 | + echo "Please run the following commands locally to fix issues:" |
| 72 | + echo " black ." |
| 73 | + echo " isort ." |
| 74 | + echo " pytest" |
| 75 | + exit 1 |
| 76 | + else |
| 77 | + echo "✅ All code quality checks passed" |
| 78 | + fi |
0 commit comments