|
| 1 | +name: Tests |
| 2 | + |
| 3 | +# Controls when the action will run. |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches: [ $default-branch ] |
| 8 | + |
| 9 | + # Allows you to run this workflow manually from the Actions tab |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: tests-${{ github.head_ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + style-check: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + - name: Set up Python 3.8 |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: 3.8 |
| 25 | + - name: Install black |
| 26 | + run: pip install black==22.3.0 |
| 27 | + - name: Check diff |
| 28 | + run: black --diff --check . |
| 29 | + docs: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + - name: Set up Python 3.10 |
| 34 | + uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: "3.10" |
| 37 | + - name: Install nox. |
| 38 | + run: python -m pip install nox |
| 39 | + - name: Build the documentation. |
| 40 | + run: nox -s docs |
| 41 | + unit: |
| 42 | + runs-on: ubuntu-22.04 |
| 43 | + strategy: |
| 44 | + matrix: |
| 45 | + # See https://github.com/actions/setup-python?tab=readme-ov-file#basic-usage |
| 46 | + # for the format of the entries in 'python'. |
| 47 | + # See https://downloads.python.org/pypy/ for the current supported versions of PyPy. |
| 48 | + python: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14', 'pypy3.10'] |
| 49 | + variant: ['cpp', 'python', 'upb'] |
| 50 | + # TODO(https://github.com/googleapis/proto-plus-python/issues/389): |
| 51 | + # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. |
| 52 | + # The 'cpp' implementation requires Protobuf == 3.x however version 3.x |
| 53 | + # does not support Python 3.11 and newer. The 'cpp' implementation |
| 54 | + # must be excluded from the test matrix for these runtimes. |
| 55 | + exclude: |
| 56 | + - variant: "cpp" |
| 57 | + python: 3.11 |
| 58 | + - variant: "cpp" |
| 59 | + python: 3.12 |
| 60 | + - variant: "cpp" |
| 61 | + python: 3.13 |
| 62 | + - variant: "cpp" |
| 63 | + python: 3.14 |
| 64 | + # In PyPy 3.10, we see the following warning |
| 65 | + # UserWarning: Selected implementation upb is not available. Falling back to the python implementation. |
| 66 | + - variant: "upb" |
| 67 | + python: 'pypy3.10' |
| 68 | + # In PyPy 3.10, we see the following warning |
| 69 | + # UserWarning: PyPy does not work yet with cpp protocol buffers. Falling back to the python implementation. |
| 70 | + - variant: "cpp" |
| 71 | + python: 'pypy3.10' |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + - name: Set up Python ${{ matrix.python }} |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: ${{ matrix.python }} |
| 78 | + allow-prereleases: true |
| 79 | + - name: Install nox |
| 80 | + run: | |
| 81 | + pip install nox |
| 82 | + - name: Run unit tests |
| 83 | + env: |
| 84 | + COVERAGE_FILE: .coverage-${{ matrix.variant }}-${{ matrix.python }} |
| 85 | + run: | |
| 86 | + nox -s "unit-${{ matrix.python }}(implementation='${{ matrix.variant }}')" |
| 87 | + - name: Upload coverage results |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: coverage-artifact-${{ matrix.variant }}-${{ matrix.python }} |
| 91 | + path: .coverage-${{ matrix.variant }}-${{ matrix.python }} |
| 92 | + include-hidden-files: true |
| 93 | + prerelease: |
| 94 | + runs-on: ubuntu-22.04 |
| 95 | + strategy: |
| 96 | + matrix: |
| 97 | + python: ['3.14'] |
| 98 | + variant: ['python', 'upb'] |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v4 |
| 101 | + - name: Set up Python ${{ matrix.python }} |
| 102 | + uses: actions/setup-python@v5 |
| 103 | + with: |
| 104 | + python-version: ${{ matrix.python }} |
| 105 | + allow-prereleases: true |
| 106 | + - name: Install nox |
| 107 | + run: | |
| 108 | + pip install nox |
| 109 | + - name: Run unit tests |
| 110 | + env: |
| 111 | + COVERAGE_FILE: .coverage-prerelease-${{ matrix.variant }} |
| 112 | + run: | |
| 113 | + nox -s "prerelease_deps(implementation='${{ matrix.variant }}')" |
| 114 | + - name: Upload coverage results |
| 115 | + uses: actions/upload-artifact@v4 |
| 116 | + with: |
| 117 | + name: coverage-artifact-prerelease-${{ matrix.variant }} |
| 118 | + path: .coverage-prerelease-${{ matrix.variant }} |
| 119 | + cover: |
| 120 | + runs-on: ubuntu-latest |
| 121 | + needs: |
| 122 | + - unit |
| 123 | + steps: |
| 124 | + - name: Checkout |
| 125 | + uses: actions/checkout@v4 |
| 126 | + - name: Setup Python |
| 127 | + uses: actions/setup-python@v5 |
| 128 | + with: |
| 129 | + python-version: "3.10" |
| 130 | + - name: Install coverage |
| 131 | + run: | |
| 132 | + python -m pip install --upgrade setuptools pip wheel |
| 133 | + python -m pip install coverage |
| 134 | + - name: Download coverage results |
| 135 | + uses: actions/download-artifact@v4 |
| 136 | + with: |
| 137 | + path: .coverage-results/ |
| 138 | + - name: Report coverage results |
| 139 | + run: | |
| 140 | + find .coverage-results -type f -name '*.zip' -exec unzip {} \; |
| 141 | + coverage combine .coverage-results/**/.coverage* |
| 142 | + coverage report --show-missing --fail-under=100 |
0 commit comments