Debian Codegraph @

third_party/upb/.github/workflows/python_tests.yml

raw
1 name: Python Tests
2
3 on:
4 push:
5 branches:
6 - main
7 pull_request:
8 branches:
9 - main
10 workflow_dispatch:
11
12 jobs:
13 build_wheels:
14 name: Build Wheels
15 runs-on: ubuntu-latest
16 if: ${{ github.repository_owner == 'protocolbuffers' }}
17 env:
18 DOCKER_IMAGE: gcr.io/protobuf-build/bazel/linux@sha256:05a41edee21f620445ca01c46b9d33be2e4d06c3d8adced4341ac5abea754baa
19 BAZEL_CACHE: --remote_cache=https://storage.googleapis.com/protobuf-bazel-cache --google_default_credentials
20
21 steps:
22 - uses: actions/checkout@v2
23 - name: Set up Cloud SDK
24 uses: google-github-actions/auth@v0
25 with:
26 credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
27 export_environment_variables: true
28 - name: Use gcloud CLI
29 run: gcloud info
30 - name: Configure Docker
31 run: gcloud auth configure-docker
32 - name: Pull Docker Image
33 run: docker pull $DOCKER_IMAGE
34 - name: Build Wheels
35 run: cd ${{ github.workspace }} && docker run -e GOOGLE_APPLICATION_CREDENTIALS=/workspace/$(basename $GOOGLE_APPLICATION_CREDENTIALS) -v$PWD:/workspace $DOCKER_IMAGE build $BAZEL_CACHE --crosstool_top=@com_google_protobuf//toolchain:clang_suite --symlink_prefix=/ -c dbg python/dist python/dist:test_wheel
36 - name: Move Wheels
37 run: mkdir wheels && find _build/out -name 'protobuf*.whl' -exec mv '{}' wheels ';'
38 - uses: actions/upload-artifact@v3
39 with:
40 name: python-wheels
41 path: wheels/
42
43 test_wheels:
44 name: Test Wheels
45 needs: build_wheels
46 strategy:
47 fail-fast: false # Don't cancel all jobs if one fails.
48 matrix:
49 include:
50 # Linux and Mac use the limited API, so all Python versions will use a single wheel.
51 # As a result we can just test the oldest and newest supported Python versions and assume
52 # this gives us sufficient test coverage.
53 - { os: ubuntu-18.04, python-version: "3.7", architecture: x64 }
54 - { os: macos-10.15, python-version: "3.7", architecture: x64 }
55 - { os: ubuntu-20.04, python-version: "3.10", architecture: x64 }
56 - { os: macos-12, python-version: "3.10", architecture: x64 }
57 # Windows uses the full API up until Python 3.10, so each of these
58 # jobs tests a distinct binary wheel.
59 - { os: windows-2019, python-version: "3.7", architecture: x86 }
60 - { os: windows-2019, python-version: "3.8", architecture: x86 }
61 - { os: windows-2019, python-version: "3.9", architecture: x86 }
62 - { os: windows-2019, python-version: "3.10", architecture: x86 }
63 - { os: windows-2019, python-version: "3.7", architecture: x64 }
64 - { os: windows-2019, python-version: "3.8", architecture: x64 }
65 - { os: windows-2019, python-version: "3.9", architecture: x64 }
66 - { os: windows-2019, python-version: "3.10", architecture: x64 }
67 runs-on: ${{ matrix.os }}
68 defaults:
69 run:
70 shell: bash
71 steps:
72 - name: Download Wheels
73 uses: actions/download-artifact@v3
74 with:
75 name: python-wheels
76 path: wheels
77 - uses: actions/setup-python@v2
78 with:
79 python-version: ${{ matrix.python-version }}
80 architecture: ${{ matrix.architecture }}
81 - name: Setup Python venv
82 run: |
83 python -m pip install --upgrade pip
84 python -m venv env
85 # Windows uses 'Scripts' instead of 'bin'
86 source env/bin/activate || source env/Scripts/activate
87 echo "VIRTUAL ENV:" $VIRTUAL_ENV
88 - name: Install tzdata
89 run: pip install tzdata
90 # Only needed on Windows, Linux ships with tzdata.
91 if: ${{ contains(matrix.os, 'windows') }}
92 - name: Install Protobuf Wheels
93 run: pip install -vvv --no-index --find-links wheels protobuf protobuftests
94 - name: Test that module is importable
95 run: python -v -c 'from google._upb import _message; assert "google._upb._message.MessageMeta" in str(_message.MessageMeta)'
96 if: ${{ !matrix.pure_python }}
97 - name: Run the unit tests
98 run: |
99 TESTS=$(pip show -f protobuftests | grep pb_unit_tests.*py$ | sed 's,/,.,g' | sed 's,\\,.,g' | sed -E 's,.py$,,g')
100 for test in $TESTS; do
101 python -m unittest -v $test
102 done
103
104 test_pure_python_wheels:
105 name: Test Pure Python Wheels
106 needs: build_wheels
107 strategy:
108 fail-fast: false # Don't cancel all jobs if one fails.
109 matrix:
110 python-version: ["3.7", "3.10"]
111 runs-on: ubuntu-latest
112
113 steps:
114 - name: Download Wheels
115 uses: actions/download-artifact@v3
116 with:
117 name: python-wheels
118 path: wheels
119 - name: Delete Binary Wheels
120 run: find wheels -type f | grep -v none-any | xargs rm
121 - uses: actions/setup-python@v2
122 with:
123 python-version: ${{ matrix.python-version }}
124 - name: Setup Python venv
125 run: |
126 python -m pip install --upgrade pip
127 python -m venv env
128 source env/bin/activate
129 echo "VIRTUAL ENV:" $VIRTUAL_ENV
130 - name: Install Protobuf Wheels
131 run: pip install -vvv --no-index --find-links wheels protobuf protobuftests
132 - name: Run the unit tests
133 run: |
134 TESTS=$(pip show -f protobuftests | grep _test.py | sed 's,/,.,g' | sed -E 's,.py$,,g')
135 for test in $TESTS; do
136 python -m unittest -v $test
137 done