| name: Python Tests | |
| on: | |
| workflow_call: | |
| inputs: | |
| continuous-run: | |
| required: true | |
| description: "Boolean string denoting whether this run is continuous -- | |
| empty string for presubmit, non-empty string for continuous." | |
| type: string | |
| safe-checkout: | |
| required: true | |
| description: "The SHA key for the commit we want to run over" | |
| type: string | |
| continuous-prefix: | |
| required: true | |
| description: "The string continuous-only tests should be prefixed with when displaying test | |
| results." | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| linux: | |
| strategy: | |
| fail-fast: false # Don't cancel all jobs if one fails. | |
| matrix: | |
| type: [ Pure, C++] | |
| version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| # TODO: Enable bzlmod once python headers are supported for python dist. | |
| bzlmod: [--noenable_bzlmod] | |
| include: | |
| - type: Pure | |
| targets: //python/... //python:python_version_test | |
| flags: --define=use_fast_cpp_protos=false | |
| - type: C++ | |
| targets: //python/... //python:python_version_test | |
| flags: --define=use_fast_cpp_protos=true | |
| - version: "3.9" | |
| - version: "3.10" | |
| continuous-only: true | |
| - version: "3.11" | |
| continuous-only: true | |
| - version: "3.12" | |
| continuous-only: true | |
| - version: "3.13" | |
| - type: C++ | |
| version: aarch64 | |
| targets: //python/... //python:aarch64_test | |
| # TODO Enable this once conformance tests are fixed. | |
| flags: --define=use_fast_cpp_protos=true --test_tag_filters=-conformance | |
| bzlmod: --noenable_bzlmod | |
| image: us-docker.pkg.dev/protobuf-build/containers/test/linux/emulation:7.1.2-aarch64-2920199ab0090ed427413a8e422e62695c8392a8 | |
| name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} Linux ${{ matrix.type }} ${{ matrix.version }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout pending changes | |
| if: ${{ !matrix.continuous-only || inputs.continuous-run }} | |
| uses: protocolbuffers/protobuf-ci/checkout@v4 | |
| with: | |
| ref: ${{ inputs.safe-checkout }} | |
| - name: Run tests | |
| if: ${{ !matrix.continuous-only || inputs.continuous-run }} | |
| uses: protocolbuffers/protobuf-ci/bazel-docker@v4 | |
| with: | |
| image: ${{ matrix.image || format('us-docker.pkg.dev/protobuf-build/containers/test/linux/python:7.1.2-{0}-d9624f2aa83cba3eaf906f751d75b36aacb9aa82', matrix.version) }} | |
| credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} | |
| bazel-cache: python_linux/${{ matrix.type }}_${{ matrix.version }} | |
| bazel: test ${{ matrix.targets }} ${{ matrix.flags }} ${{ matrix.bzlmod }} --test_env=KOKORO_PYTHON_VERSION | |
| macos: | |
| strategy: | |
| fail-fast: false # Don't cancel all jobs if one fails. | |
| matrix: | |
| type: [ Pure, C++] | |
| version: [ "3.12", "3.13" ] | |
| # TODO: Enable bzlmod once python headers are supported for python dist. | |
| bzlmod: [--noenable_bzlmod] | |
| include: | |
| - type: Pure | |
| targets: //python/... //python:python_version_test | |
| - type: C++ | |
| targets: //python/... //python:python_version_test | |
| flags: --define=use_fast_cpp_protos=true | |
| - version: "3.13" | |
| continuous-only: true | |
| name: MacOS ${{ matrix.type }} ${{ matrix.version }} | |
| runs-on: macos-13 | |
| steps: | |
| - name: Checkout pending changes | |
| uses: protocolbuffers/protobuf-ci/checkout@v4 | |
| with: | |
| ref: ${{ inputs.safe-checkout }} | |
| - name: Pin Python version | |
| uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f #v5.1.1 | |
| with: | |
| python-version: ${{ matrix.version }} | |
| cache: pip | |
| cache-dependency-path: 'python/requirements.txt' | |
| - name: Validate version | |
| run: python3 --version | grep ${{ matrix.version }} || (echo "Invalid Python version - $(python3 --version)" && exit 1) | |
| - name: Create and start virtual environment | |
| run: | | |
| python3 -m venv venv | |
| source venv/bin/activate | |
| - name: Run tests | |
| uses: protocolbuffers/protobuf-ci/bazel@v4 | |
| env: | |
| KOKORO_PYTHON_VERSION: ${{ matrix.version }} | |
| with: | |
| version: 7.1.2 # Bazel version | |
| credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }} | |
| bazel-cache: python_macos/${{ matrix.type }}_${{ matrix.version }} | |
| bazel: >- | |
| test ${{ matrix.targets }} ${{ matrix.flags }} ${{ matrix.bzlmod }} | |
| --test_env=KOKORO_PYTHON_VERSION=${{ matrix.version }} | |
| --macos_minimum_os=11.0 |