Skip to content

Commit 6fbcb87

Browse files
Extend gencode compatibility support back to 3.20.0 (#22424)
* Extend gencode compatibility support back to 3.20.0 This adds 2 shims for some previous breakages, and compatibility tests to avoid further accidents. This will be backported to 25.x and 29.x. PiperOrigin-RevId: 776414924 * Remove 26.x and 30.x * Remove continuous testing tags which didn't exist in 25.x * Fix requirements install * pin to bazel 6.3.0 * Desynchronize upb/pure tests * Remove missing test proto from hardcoded list * Use python 11 for 25.x * Run tests independently to avoid contamination of global state between generator/descriptor tests * Update comment
1 parent 974b235 commit 6fbcb87

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

.github/workflows/test_upb.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,56 @@ jobs:
277277
for test in $TESTS; do
278278
python -m unittest -v $test
279279
done
280+
281+
test_python_compatibility:
282+
name: Test Python Compatibility (${{ matrix.implementation }} - ${{ matrix.version }})
283+
needs: build_wheels
284+
strategy:
285+
fail-fast: false # Don't cancel all jobs if one fails.
286+
matrix:
287+
# Test the first release of each python major version, plus some extra coverage for 3.x.y
288+
# since it predates our breaking change policies.
289+
# Major versions: 4.21.0
290+
version: ["3.18.0", "3.20.0", "21.0"]
291+
implementation: ["Pure", "upb"]
292+
include:
293+
# We don't support 3.18.0 anymore, so our infra should show a failure.
294+
- version: "3.18.0"
295+
fail: true
296+
runs-on: ubuntu-latest
297+
if: ${{ github.event_name != 'pull_request_target' }}
298+
steps:
299+
- name: Checkout pending changes
300+
uses: protocolbuffers/protobuf-ci/checkout@v4
301+
with:
302+
ref: ${{ inputs.safe-checkout }}
303+
- name: Download Wheels
304+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 #4.1.8
305+
with:
306+
name: python-wheels
307+
path: wheels
308+
- name: Delete Binary Wheels (pure python only)
309+
if: ${{ matrix.implementation == 'Pure' }}
310+
run: find wheels -type f | grep -v none-any | xargs rm
311+
- name: Setup Python
312+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
313+
with:
314+
python-version: 3.11
315+
- name: Setup Python venv
316+
run: |
317+
python -m pip install --upgrade pip
318+
python -m venv env
319+
source env/bin/activate
320+
echo "VIRTUAL ENV:" $VIRTUAL_ENV
321+
- name: Install numpy
322+
run: pip install numpy
323+
- name: Install Protobuf Wheels
324+
run: pip install -vvv --no-index --find-links wheels protobuf protobuftests
325+
- name: Make the test script executable
326+
run: chmod +x ci/python_compatibility.sh
327+
- name: Run compatibility tests
328+
if: ${{ !matrix.fail }}
329+
run: ci/python_compatibility.sh ${{ matrix.version }} ${{ matrix.implementation == 'upb' && 'pb_unit_tests.*py$' || '_test.py' }}
330+
- name: Run failing compatibility tests
331+
if: ${{ matrix.fail }}
332+
run: (! ci/python_compatibility.sh ${{ matrix.version }} ${{ matrix.implementation == 'upb' && 'pb_unit_tests.*py$' || '_test.py' }})

ci/python_compatibility.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
PROTOC_VERSION=$1
6+
TEST_FILTER=$2
7+
PROTOC_DOWNLOAD=https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip
8+
PY_SITE_PACKAGES=$(python -c 'import site; print(site.getsitepackages()[0])')
9+
10+
rm -rf protoc-old
11+
mkdir protoc-old
12+
pushd protoc-old
13+
wget $PROTOC_DOWNLOAD
14+
unzip *.zip
15+
PROTOC=$(pwd)/bin/protoc
16+
popd
17+
18+
# protoc prior to 28.0 doesn't support inf/nan option values.
19+
sed -i 's/\(inf\|nan\)/0/g' src/google/protobuf/unittest_custom_options.proto
20+
21+
USE_BAZEL_VERSION=6.3.0 bazelisk build //python:copied_test_proto_files //python:copied_wkt_proto_files
22+
23+
COMPAT_COPIED_PROTOS=(
24+
# Well-known types give good build coverage
25+
any
26+
api
27+
duration
28+
empty
29+
field_mask
30+
source_context
31+
struct
32+
timestamp
33+
type
34+
wrappers
35+
# These protos are used in tests of custom options handling.
36+
unittest_custom_options
37+
unittest_import
38+
)
39+
40+
for proto in ${COMPAT_COPIED_PROTOS[@]}; do
41+
$PROTOC --python_out=$PY_SITE_PACKAGES \
42+
bazel-bin/python/google/protobuf/$proto.proto \
43+
-Ibazel-bin/python
44+
done
45+
46+
COMPAT_PROTOS=(
47+
# All protos without transitive dependencies on edition 2023+.
48+
descriptor_pool_test1
49+
descriptor_pool_test2
50+
factory_test1
51+
factory_test2
52+
file_options_test
53+
import_test_package/import_public
54+
import_test_package/import_public_nested
55+
import_test_package/inner
56+
import_test_package/outer
57+
message_set_extensions
58+
missing_enum_values
59+
more_extensions
60+
more_extensions_dynamic
61+
more_messages
62+
no_package
63+
packed_field_test
64+
test_bad_identifiers
65+
test_proto3_optional
66+
)
67+
68+
for proto in ${COMPAT_PROTOS[@]}; do
69+
$PROTOC --python_out=$PY_SITE_PACKAGES \
70+
python/google/protobuf/internal/$proto.proto \
71+
-Ipython
72+
done
73+
74+
# Exclude pybind11 tests because they require C++ code that doesn't ship with
75+
# our test wheels.
76+
TEST_EXCLUSIONS="_pybind11_test.py"
77+
TESTS=$(pip show -f protobuftests | grep -i $TEST_FILTER | grep --invert-match $TEST_EXCLUSIONS | sed 's,/,.,g' | sed -E 's,.py$,,g')
78+
for test in $TESTS; do
79+
python -m unittest -v $test
80+
done

0 commit comments

Comments
 (0)