@@ -12,7 +12,55 @@ name: lint
1212permissions :
1313 contents : read
1414
15+ env :
16+ NOX_REUSE_EXISTING_VIRTUALENVS : " true"
17+ NOX_ENVDIR : " /tmp/shared_nox_envs"
18+ NOX_DEFAULT_VENV_BACKEND : " uv"
19+ UV_VENV_SEED : " 1"
20+ # Run checks in parallel using 4 cores
21+ PARALLEL_WORKERS : " 4"
22+
1523jobs :
24+ initialize :
25+ runs-on : ubuntu-latest
26+ outputs :
27+ matrix : ${{ steps.set-matrix.outputs.matrix }}
28+ is_full_run : ${{ steps.check-label.outputs.is_full_run }}
29+ env :
30+ MAX_SHARDS : 4
31+ steps :
32+ - name : Checkout
33+ uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
34+ # Use a fetch-depth of 2 to avoid error `fatal: origin/main...HEAD: no merge base`
35+ # See https://github.com/googleapis/google-cloud-python/issues/12013
36+ # and https://github.com/actions/checkout#checkout-head.
37+ with :
38+ fetch-depth : 2
39+ persist-credentials : false
40+ - name : Check for unit_test:all_packages label
41+ id : check-label
42+ run : |
43+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'unit_test:all_packages') }}" == "true" ]]; then
44+ echo "is_full_run=true" >> $GITHUB_OUTPUT
45+ else
46+ echo "is_full_run=false" >> $GITHUB_OUTPUT
47+ fi
48+ - name : Setup Python
49+ uses : actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
50+ with :
51+ python-version : " 3.10"
52+ - name : Get package shards
53+ id : set-matrix
54+ env :
55+ BUILD_TYPE : presubmit
56+ TARGET_BRANCH : ${{ github.base_ref || github.event.merge_group.base_ref }}
57+ TEST_ALL_PACKAGES : ${{ steps.check-label.outputs.is_full_run }}
58+ run : |
59+ if [ -n "$TARGET_BRANCH" ]; then
60+ git fetch origin "$TARGET_BRANCH" --depth=1 || true
61+ fi
62+ python3 ci/get_package_shards.py
63+
1664 lint :
1765 runs-on : ubuntu-latest
1866 steps :
@@ -24,18 +72,27 @@ jobs:
2472 with :
2573 fetch-depth : 2
2674 persist-credentials : false
75+ - name : Check for unit_test:all_packages label
76+ id : check-label
77+ run : |
78+ if [[ "${{ contains(github.event.pull_request.labels.*.name, 'unit_test:all_packages') }}" == "true" ]]; then
79+ echo "is_full_run=true" >> $GITHUB_OUTPUT
80+ else
81+ echo "is_full_run=false" >> $GITHUB_OUTPUT
82+ fi
2783 - name : Setup Python
2884 uses : actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
2985 with :
3086 python-version : " 3.14"
3187 - name : Install nox
3288 run : |
3389 python -m pip install --upgrade setuptools pip wheel
34- python -m pip install nox
90+ python -m pip install nox uv
3591 - name : Run lint
3692 env :
3793 BUILD_TYPE : presubmit
3894 TARGET_BRANCH : ${{ github.base_ref || github.event.merge_group.base_ref }}
95+ TEST_ALL_PACKAGES : ${{ steps.check-label.outputs.is_full_run }}
3996 TEST_TYPE : lint
4097 # TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
4198 PY_VERSION : " unused"
@@ -45,13 +102,22 @@ jobs:
45102 env :
46103 BUILD_TYPE : presubmit
47104 TARGET_BRANCH : ${{ github.base_ref || github.event.merge_group.base_ref }}
105+ TEST_ALL_PACKAGES : ${{ steps.check-label.outputs.is_full_run }}
48106 TEST_TYPE : lint_setup_py
49107 # TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
50108 PY_VERSION : " unused"
51109 run : |
52110 ci/run_conditional_tests.sh
53- mypy :
111+
112+ mypy-shard :
113+ needs : initialize
114+ if : needs.initialize.outputs.matrix != '[]' && needs.initialize.outputs.matrix != ''
54115 runs-on : ubuntu-latest
116+ strategy :
117+ fail-fast : true
118+ matrix :
119+ package_shard : ${{ fromJson(needs.initialize.outputs.matrix) }}
120+ name : ${{ matrix.package_shard.is_sharded && format('mypy ({0})', matrix.package_shard.name) || format('mypy ({0})', matrix.package_shard.description) }}
55121 steps :
56122 - name : Checkout
57123 uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
@@ -68,13 +134,28 @@ jobs:
68134 - name : Install nox
69135 run : |
70136 python -m pip install --upgrade setuptools pip wheel
71- python -m pip install nox
72- - name : Run mypy
137+ python -m pip install nox uv
138+ - name : Run mypy for ${{ matrix.package_shard.description }}
73139 env :
74140 BUILD_TYPE : presubmit
75141 TARGET_BRANCH : ${{ github.base_ref || github.event.merge_group.base_ref }}
76142 TEST_TYPE : mypy
143+ PACKAGE_LIST : ${{ matrix.package_shard.packages }}
77144 # TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
78145 PY_VERSION : " unused"
79146 run : |
80147 ci/run_conditional_tests.sh
148+
149+ mypy-status :
150+ if : always()
151+ needs : [initialize, mypy-shard]
152+ runs-on : ubuntu-latest
153+ name : mypy-status
154+ steps :
155+ - name : Check mypy job status
156+ run : |
157+ if [[ "${{ needs['mypy-shard'].result }}" != "success" && "${{ needs['mypy-shard'].result }}" != "skipped" ]]; then
158+ echo "mypy failed with result: ${{ needs['mypy-shard'].result }}"
159+ exit 1
160+ fi
161+ echo "All mypy shards passed successfully!"
0 commit comments