From d7f76903ced4ab162ff742bc2c4026b06c0f4ef8 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 5 May 2025 16:33:15 +0000 Subject: [PATCH] test: add cross package compatibility test using pex --- .../test_cross_package_compatibility.yml | 65 +++++++++++++++++++ .../build_wheels.sh | 25 +++++++ .../create_requirements_file.sh | 31 +++++++++ .../generate_test_code.sh | 32 +++++++++ 4 files changed, 153 insertions(+) create mode 100644 .github/workflows/test_cross_package_compatibility.yml create mode 100755 scripts/test_cross_package_compatibility/build_wheels.sh create mode 100755 scripts/test_cross_package_compatibility/create_requirements_file.sh create mode 100755 scripts/test_cross_package_compatibility/generate_test_code.sh diff --git a/.github/workflows/test_cross_package_compatibility.yml b/.github/workflows/test_cross_package_compatibility.yml new file mode 100644 index 000000000000..bd9b022c9240 --- /dev/null +++ b/.github/workflows/test_cross_package_compatibility.yml @@ -0,0 +1,65 @@ +# Copyright 2025 Google LLC + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# https://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: A workflow for testing cross package compatibility using pex + +# Controls when the action will run. + +# Run this action anytime `gapic_version.py` is updated in main +on: + push: + paths: + - '**/gapic_version.py' + branches: + - main + # TODO: Remove this before merging + pull_request: + branches: + - main + + +permissions: + contents: read + +jobs: + build: + permissions: + issues: write # to open issues when compatibility issues are found + name: Cross Package Compatibility using Pex + runs-on: ubuntu-latest + # don't run the workflow on forks of googleapis/google-cloud-python + if: ${{github.repository == 'googleapis/google-cloud-python'}} + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: 3.13 + - name: Install build dependencies + run: pip install build wheel + - name: Build wheels for all packages + run: ./build_wheels.sh + working-directory: ./scripts/test_cross_package_compatibility + - name: Create requirements.txt file to install all packages from source + run: ./create_requirements_file.sh + working-directory: ./scripts/test_cross_package_compatibility + - name: Create python file to be used during the compatibility check + run: ./generate_test_code.sh + working-directory: ./scripts/test_cross_package_compatibility + - name: Install pex + run: pip install pex + - name: Install all packages and run compatibility check + run: pex -r requirements.txt -- test_imports.py + working-directory: ./scripts/test_cross_package_compatibility + # TODO : open github issue if there are failures diff --git a/scripts/test_cross_package_compatibility/build_wheels.sh b/scripts/test_cross_package_compatibility/build_wheels.sh new file mode 100755 index 000000000000..ad61e66ee9c2 --- /dev/null +++ b/scripts/test_cross_package_compatibility/build_wheels.sh @@ -0,0 +1,25 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")) +REPO_ROOT=${SCRIPT_ROOT/%'/scripts/test_cross_package_compatibility'} + +# Build wheels for all packages +for package in $REPO_ROOT/packages/*/ ; do + pushd ${package} + distribution_name=$(basename $package) + python3 -m build --wheel + popd +done diff --git a/scripts/test_cross_package_compatibility/create_requirements_file.sh b/scripts/test_cross_package_compatibility/create_requirements_file.sh new file mode 100755 index 000000000000..e7682a8b5481 --- /dev/null +++ b/scripts/test_cross_package_compatibility/create_requirements_file.sh @@ -0,0 +1,31 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")) +REPO_ROOT=${SCRIPT_ROOT/%'/scripts/test_cross_package_compatibility'} + +output='' +# Create a requirements.txt file with all packages in this repo +for package in $REPO_ROOT/packages/*/ ; do + distribution_name=$(basename $package) + # Replace `-` with `_` + distribution_name_wheel=$(echo ${distribution_name} | sed -E 's/\-/_/g') + output+="${distribution_name} @ file://localhost${REPO_ROOT}/packages/${distribution_name}/dist/${distribution_name_wheel}-0.0.0-py3-none-any.whl\n" +done +output+="# Remove pin below once https://github.com/googleapis/google-cloud-python/issues/13874 is fixed\n" +output+="protobuf<6" + +# Save the output to a requirements.txt +echo -e $output > requirements.txt diff --git a/scripts/test_cross_package_compatibility/generate_test_code.sh b/scripts/test_cross_package_compatibility/generate_test_code.sh new file mode 100755 index 000000000000..ce742dd3fc21 --- /dev/null +++ b/scripts/test_cross_package_compatibility/generate_test_code.sh @@ -0,0 +1,32 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR from google.cloud.billing import CloudBillingClientDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +SCRIPT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")) +REPO_ROOT=${SCRIPT_ROOT/%'/scripts/test_cross_package_compatibility'} + +output='' +# Create a requirements.txt file with all packages in this repo +for package in $REPO_ROOT/packages/*/ ; do + package_dir=$(basename $package) + top_namespace="${package_dir%%-*}" + for d in `find $package$top_namespace -name '__init__.py'`; do + init_relative_path=${d#$package} + module_path=$(echo $init_relative_path | sed -e "s/\/__init__.py//") + import_path="$(echo $module_path | sed -E 's/\//./g')" + output+="from $import_path import *\n" + done +done +# Save the output to a python file +echo -e $output > test_imports.py