|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + python-version: ['3.10', '3.11', '3.12', '3.13'] |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python ${{ matrix.python-version }} |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: ${{ matrix.python-version }} |
| 25 | + |
| 26 | + - name: Cache pip packages |
| 27 | + uses: actions/cache@v4 |
| 28 | + with: |
| 29 | + path: ~/.cache/pip |
| 30 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} |
| 31 | + restore-keys: | |
| 32 | + ${{ runner.os }}-pip- |
| 33 | +
|
| 34 | + - name: Install runtime + test tools |
| 35 | + run: | |
| 36 | + python -m pip install --upgrade pip |
| 37 | + # Устанавливаем package (runtime deps) |
| 38 | + pip install -e "." |
| 39 | + # Явно ставим инструменты для тестов/линта, чтобы они были доступны в runner |
| 40 | + pip install pytest pytest-asyncio pytest-cov pytest-timeout flake8 mypy |
| 41 | +
|
| 42 | + - name: Lint with flake8 |
| 43 | + run: | |
| 44 | + flake8 src/pymax tests \ |
| 45 | + --count \ |
| 46 | + --select=E9,F63,F7,F82 \ |
| 47 | + --show-source \ |
| 48 | + --statistics |
| 49 | + flake8 src/pymax tests \ |
| 50 | + --count \ |
| 51 | + --exit-zero \ |
| 52 | + --max-complexity=10 \ |
| 53 | + --max-line-length=79 \ |
| 54 | + --statistics |
| 55 | + continue-on-error: true |
| 56 | + |
| 57 | + - name: Type check with mypy |
| 58 | + run: | |
| 59 | + mypy src/pymax \ |
| 60 | + --ignore-missing-imports \ |
| 61 | + --no-error-summary |
| 62 | + continue-on-error: true |
| 63 | + |
| 64 | + - name: Run unit tests |
| 65 | + run: | |
| 66 | + pytest -m "not mockserver" \ |
| 67 | + --cov=src/pymax \ |
| 68 | + --cov-report=xml \ |
| 69 | + --cov-report=term-missing |
| 70 | +
|
| 71 | + - name: Upload coverage to Codecov |
| 72 | + uses: codecov/codecov-action@v4 |
| 73 | + with: |
| 74 | + files: coverage.xml |
| 75 | + flags: unittests |
| 76 | + name: codecov-umbrella |
| 77 | + fail_ci_if_error: false |
| 78 | + |
| 79 | + - name: Archive pytest cache |
| 80 | + if: always() |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + with: |
| 83 | + name: pytest-cache-${{ matrix.python-version }} |
| 84 | + path: .pytest_cache/ |
| 85 | + retention-days: 5 |
| 86 | + |
| 87 | + integration-tests: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + |
| 90 | + steps: |
| 91 | + - name: Checkout repository (with submodules) |
| 92 | + uses: actions/checkout@v4 |
| 93 | + with: |
| 94 | + submodules: recursive |
| 95 | + |
| 96 | + - name: Set up Python |
| 97 | + uses: actions/setup-python@v5 |
| 98 | + with: |
| 99 | + python-version: '3.13' |
| 100 | + |
| 101 | + - name: Install runtime + test tools (integration) |
| 102 | + run: | |
| 103 | + python -m pip install --upgrade pip |
| 104 | + pip install -e "." |
| 105 | + pip install pytest pytest-asyncio pytest-cov pytest-timeout flake8 mypy |
| 106 | +
|
| 107 | + - name: Set up Go |
| 108 | + uses: actions/setup-go@v5 |
| 109 | + with: |
| 110 | + go-version: '1.22' |
| 111 | + |
| 112 | + - name: Start MockServer |
| 113 | + run: | |
| 114 | + git clone https://github.com/fresh-milkshake/gomax-prerelease.git |
| 115 | + cd gomax-prerelease/mockserver |
| 116 | + go mod download |
| 117 | + go run cmd/server/main.go & |
| 118 | + sleep 3 |
| 119 | +
|
| 120 | + - name: Run integration tests |
| 121 | + run: | |
| 122 | + pytest -m mockserver -v --tb=short |
| 123 | + continue-on-error: true |
| 124 | + env: |
| 125 | + MOCKSERVER_WS_URL: ws://localhost:8080/ |
| 126 | + MOCKSERVER_HTTP_URL: http://localhost:8080 |
| 127 | + |
| 128 | + code-quality: |
| 129 | + runs-on: ubuntu-latest |
| 130 | + |
| 131 | + steps: |
| 132 | + - name: Checkout repository |
| 133 | + uses: actions/checkout@v4 |
| 134 | + |
| 135 | + - name: Set up Python |
| 136 | + uses: actions/setup-python@v5 |
| 137 | + with: |
| 138 | + python-version: '3.13' |
| 139 | + |
| 140 | + - name: Install dependencies + quality tools |
| 141 | + run: | |
| 142 | + python -m pip install --upgrade pip |
| 143 | + pip install -e "." |
| 144 | + # black/isort/pylint используются только в этом job |
| 145 | + pip install black isort pylint |
| 146 | +
|
| 147 | + - name: Check code formatting with black |
| 148 | + run: black --check src/pymax tests |
| 149 | + continue-on-error: true |
| 150 | + |
| 151 | + - name: Check import sorting with isort |
| 152 | + run: isort --check-only src/pymax tests |
| 153 | + continue-on-error: true |
0 commit comments