Skip to content

tests: always trigger gapic specialized tests #816

tests: always trigger gapic specialized tests

tests: always trigger gapic specialized tests #816

name: Gapic Generator Specialized Tests
on:
pull_request:
push:
branches: [main]
concurrency:
group: gapic-gen-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
SHOWCASE_VERSION: 0.35.0
PROTOC_VERSION: 3.20.2
LATEST_STABLE_PYTHON: 3.14
PRERELEASE_PYTHON: 3.15
ALL_PYTHON: "['3.10', '3.11', '3.12', '3.13', '3.14', '3.15']"
TRIMMED_PYTHON: "['3.10', '3.14', '3.15']"
# Workaround: Allows libcst to compile on Python 3.15+ while PyO3 catches up
# Can be removed once libcst releases a version with native Python 3.15 wheels
# Follow https://github.com/Instagram/LibCST/issues/1445 for updates.
PYO3_USE_ABI3_FORWARD_COMPATIBILITY: "1"
jobs:
# Check if the gapic-generator was changed. If so, execute specialized tests
check_changes:
runs-on: ubuntu-latest
outputs:
run_generator: ${{ steps.filter.outputs.generator }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
generator:
- 'packages/gapic-generator/**'
- '.github/workflows/gapic-generator-tests.yml'
# Preserve the workaround for env variables in matrix
python_config:
needs: check_changes
if: ${{ needs.check_changes.outputs.run_generator == 'true' }}
runs-on: ubuntu-latest
outputs:
all_python: ${{ env.ALL_PYTHON }}
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
prerelease_python: ${{ env.PRERELEASE_PYTHON }}
trimmed_python: $${{ env.TRIMMED_PYTHON }}
steps:
- run: echo "Initializing config for gapic-generator"
showcase-unit:
needs: python_config
strategy:
fail-fast: false
matrix:
python: ${{ fromJSON(needs.python_config.outputs.all_python) }}
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
logging_scope: ["", "google"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "${{ matrix.python }}"
allow-prereleases: true
# Caches compiled wheels locally to prevent building heavy libraries
# such as grpcio, which we build from scratch on every run for Python 3.15+.
# Follow https://github.com/grpc/grpc/issues/41010 for updates.
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install System Deps & Protoc
run: |
sudo apt-get update && sudo apt-get install -y curl pandoc unzip
sudo mkdir -p /usr/src/protoc/ && sudo chown -R ${USER} /usr/src/
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc.zip
cd /usr/src/protoc/ && unzip protoc.zip
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- name: Run Nox
env:
GOOGLE_SDK_PYTHON_LOGGING_SCOPE: ${{ matrix.logging_scope }}
run: |
pip install nox
cd packages/gapic-generator
nox -s showcase_unit${{ matrix.variant }}-${{ matrix.python }}
showcase-mypy:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Mypy
run: |
pip install nox
cd packages/gapic-generator
nox -s showcase_mypy
goldens:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Goldens
run: |
pip install nox
cd packages/gapic-generator
for pkg in credentials eventarc logging redis; do
nox -f tests/integration/goldens/$pkg/noxfile.py -s format lint unit-${{ needs.python_config.outputs.latest_stable_python }}
done
# Run pylint (errors-only) over the goldens so generator regressions
# like undefined names or import-time breakage that ruff/flake8 do
# not flag are caught at PR time.
# See https://github.com/googleapis/google-cloud-python/issues/16393.
- name: Pylint goldens (errors only)
run: |
pip install --quiet pylint
cd packages/gapic-generator/tests/integration/goldens
for pkg in credentials eventarc logging redis; do
pylint --rcfile=.pylintrc --errors-only --recursive=y "$pkg/google"
done
goldens-prerelease:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ needs.python_config.outputs.prerelease_python }}
uses: actions/setup-python@v6
with:
python-version: ${{ needs.python_config.outputs.prerelease_python }}
allow-prereleases: true
# Caches compiled wheels locally to prevent building heavy libraries
# such as grpcio, which we build from scratch on every run for Python 3.15+.
# Follow https://github.com/grpc/grpc/issues/41010 for updates.
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Goldens (Prerelease)
run: |
pip install nox
cd packages/gapic-generator
for pkg in credentials eventarc logging redis; do
nox -f tests/integration/goldens/$pkg/noxfile.py -s core_deps_from_source prerelease_deps
done
fragment-snippet:
needs: python_config
strategy:
matrix:
python: ${{ fromJSON(needs.python_config.outputs.trimmed_python) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
# Caches compiled wheels locally to prevent building heavy libraries
# such as grpcio, which we build from scratch on every run for Python 3.15+.
# Follow https://github.com/grpc/grpc/issues/41010 for updates.
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install System Deps & Protoc
run: |
sudo apt-get update && sudo apt-get install -y curl pandoc unzip
sudo mkdir -p /usr/src/protoc/ && sudo chown -R ${USER} /usr/src/
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc.zip
cd /usr/src/protoc/ && unzip protoc.zip
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- name: Run Tests
run: |
pip install nox
cd packages/gapic-generator
# Run fragment for current matrix python
nox -s fragment-${{ matrix.python }}
# Run snippetgen only on the latest stable to avoid the "Python not found" error
if [ "${{ matrix.python }}" == "${{ needs.python_config.outputs.latest_stable_python }}" ]; then
nox -s snippetgen
fi
integration:
needs: python_config
# Only runs if the Gatekeeper passed
if: ${{ needs.python_config.result == 'success' }}
runs-on: ubuntu-latest
container: gcr.io/gapic-images/googleapis
steps:
- uses: actions/checkout@v6
- name: Cache Bazel files
id: cache-bazel
uses: actions/cache@v5
with:
path: ~/.cache/bazel
# Ensure CACHE_VERSION is defined in the mono-repo secrets!
key: ${{ runner.os }}-bazel-20210105-${{ secrets.CACHE_VERSION }}
- name: Run Bazel Integration Tests
run: |
# We need to move into the package directory if the
# WORKSPACE file is located there.
cd packages/gapic-generator
bazelisk test //tests/integration/... --test_output=errors
# Final job to simplify branch protection rules.
# This job will be reported as 'Success' if all its dependencies either
# pass or are skipped due to path filtering.
status:
needs: [check_changes, python_config, showcase-unit, showcase-mypy, goldens, goldens-prerelease, fragment-snippet, integration]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check all jobs for failure
run: |
echo "check_changes result: ${{ needs.check_changes.result }}"
echo "python_config result: ${{ needs.python_config.result }}"
echo "showcase-unit result: ${{ needs.showcase-unit.result }}"
echo "showcase-mypy result: ${{ needs.showcase-mypy.result }}"
echo "goldens result: ${{ needs.goldens.result }}"
echo "goldens-prerelease result: ${{ needs.goldens-prerelease.result }}"
echo "fragment-snippet result: ${{ needs.fragment-snippet.result }}"
echo "integration result: ${{ needs.integration.result }}"
# Fail if any of the dependencies failed or were cancelled
if [ "${{ needs.check_changes.result }}" = "failure" ] || [ "${{ needs.check_changes.result }}" = "cancelled" ] || \
[ "${{ needs.python_config.result }}" = "failure" ] || [ "${{ needs.python_config.result }}" = "cancelled" ] || \
[ "${{ needs.showcase-unit.result }}" = "failure" ] || [ "${{ needs.showcase-unit.result }}" = "cancelled" ] || \
[ "${{ needs.showcase-mypy.result }}" = "failure" ] || [ "${{ needs.showcase-mypy.result }}" = "cancelled" ] || \
[ "${{ needs.goldens.result }}" = "failure" ] || [ "${{ needs.goldens.result }}" = "cancelled" ] || \
[ "${{ needs.goldens-prerelease.result }}" = "failure" ] || [ "${{ needs.goldens-prerelease.result }}" = "cancelled" ] || \
[ "${{ needs.fragment-snippet.result }}" = "failure" ] || [ "${{ needs.fragment-snippet.result }}" = "cancelled" ] || \
[ "${{ needs.integration.result }}" = "failure" ] || [ "${{ needs.integration.result }}" = "cancelled" ]; then
echo "Error: One or more required jobs failed or were cancelled."
exit 1
fi
echo "All checks passed or were successfully skipped."