@@ -16,8 +16,46 @@ concurrency:
1616env :
1717 SHOWCASE_VERSION : 0.35.0
1818 PROTOC_VERSION : 3.20.2
19+ OLDEST_PYTHON : 3.7
20+ LATEST_STABLE_PYTHON : 3.14
21+ # TODO(https://github.com/googleapis/gapic-generator-python/issues/2450):
22+ # Switch this to Python 3.15 alpha1 pre-release
23+ # https://peps.python.org/pep-0790/
24+ PREVIEW_PYTHON_VERSION : 3.14
25+ # TODO(https://github.com/googleapis/gapic-generator-python/issues/2450):
26+ # Add Python 3.15 alpha1 pre-release
27+ # https://peps.python.org/pep-0790/
28+ ALL_PYTHON : " ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']"
29+
30+ permissions :
31+ contents : read
1932
2033jobs :
34+ # `all_python_setup` amd `python_config` are a workaround for a known issue where it's not possible to use environment variables outside of `steps`.
35+ # Some jobs set up a text matrix which is outside of `steps` and environment variables can't be used directly.
36+ # This requires a workaround based on the discussion in:
37+ # https://github.com/actions/runner/issues/2372
38+ # The limitation is captured here where certain job configurations don't have access to `env`
39+ # https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability
40+ all_python_setup :
41+ runs-on : ubuntu-latest
42+ outputs :
43+ all_python : ${{ env.ALL_PYTHON }}
44+ steps :
45+ - name : Set up all python
46+ id : all_python
47+ run : |
48+ echo 'all_python={{ "${{ env.ALL_PYTHON }}" }}'
49+ python_config :
50+ runs-on : ubuntu-latest
51+ outputs :
52+ oldest_python : ${{ env.OLDEST_PYTHON }}
53+ latest_stable_python : ${{ env.LATEST_STABLE_PYTHON }}
54+ steps :
55+ - name : Print env variables for `python_config`
56+ run : |
57+ echo 'oldest_python={{ "${{ env.OLDEST_PYTHON }}" }}'
58+ echo 'latest_stable_python={{ "${{ env.LATEST_STABLE_PYTHON }}" }}'
2159 docs :
2260 runs-on : ubuntu-latest
2361 steps :
@@ -49,11 +87,15 @@ jobs:
4987 - name : Build the documentation.
5088 run : nox -s docfx
5189 mypy :
90+ needs : all_python_setup
5291 strategy :
5392 matrix :
5493 # Run mypy on all of the supported python versions listed in setup.py
5594 # https://github.com/python/mypy/blob/master/setup.py
56- python : ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
95+ python : ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
96+ exclude :
97+ # Remove once https://github.com/googleapis/gapic-generator-python/issues/2303 is fixed
98+ - python : ' 3.7'
5799 runs-on : ubuntu-latest
58100 steps :
59101 - uses : actions/checkout@v5
@@ -62,16 +104,18 @@ jobs:
62104 with :
63105 python-version : " ${{ matrix.python }}"
64106 cache : ' pip'
107+ allow-prereleases : true
65108 - name : Install nox.
66109 run : python -m pip install nox
67110 - name : Check type annotations.
68111 run : nox -s mypy-${{ matrix.python }}
69112 showcase :
113+ needs : python_config
70114 strategy :
71115 # Run showcase tests on the lowest and highest supported runtimes
72116 matrix :
73117 # TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
74- python : ["3.7 ", "3.13 "]
118+ python : ["${{ needs.python_config.outputs.oldest_python }} ", "${{ needs.python_config.outputs.latest_stable_python }} "]
75119 target : [showcase, showcase_w_rest_async]
76120 logging_scope : ["", "google"]
77121
@@ -126,10 +170,10 @@ jobs:
126170 run : |
127171 sudo mkdir -p /tmp/workspace/tests/cert/
128172 sudo chown -R ${USER} /tmp/workspace/
129- - name : Set up Python "3.13"
173+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
130174 uses : actions/setup-python@v6
131175 with :
132- python-version : " 3.13 "
176+ python-version : " ${{ env.LATEST_STABLE_PYTHON }} "
133177 cache : ' pip'
134178 - name : Copy mtls files
135179 run : cp tests/cert/mtls.* /tmp/workspace/tests/cert/
@@ -160,9 +204,10 @@ jobs:
160204 nox -s ${{ matrix.target }}
161205 # TODO(yon-mg): add compute unit tests
162206 showcase-unit :
207+ needs : all_python_setup
163208 strategy :
164209 matrix :
165- python : ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
210+ python : ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
166211 # TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `_w_rest_async` variant when async rest is GA.
167212 variant : ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
168213 logging_scope : ["", "google"]
@@ -177,6 +222,7 @@ jobs:
177222 with :
178223 python-version : " ${{ matrix.python }}"
179224 cache : ' pip'
225+ allow-prereleases : true
180226 - name : Install system dependencies.
181227 run : |
182228 sudo apt-get update
@@ -200,10 +246,10 @@ jobs:
200246 runs-on : ubuntu-latest
201247 steps :
202248 - uses : actions/checkout@v5
203- - name : Set up Python "3.13"
249+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
204250 uses : actions/setup-python@v6
205251 with :
206- python-version : " 3.13 "
252+ python-version : " ${{ env.LATEST_STABLE_PYTHON }} "
207253 cache : ' pip'
208254 - name : Install system dependencies.
209255 run : |
@@ -228,10 +274,10 @@ jobs:
228274 variant : ['', _alternative_templates]
229275 steps :
230276 - uses : actions/checkout@v5
231- - name : Set up Python "3.13"
277+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
232278 uses : actions/setup-python@v6
233279 with :
234- python-version : " 3.13 "
280+ python-version : " ${{ env.LATEST_STABLE_PYTHON }} "
235281 cache : ' pip'
236282 - name : Install system dependencies.
237283 run : |
@@ -250,13 +296,14 @@ jobs:
250296 - name : Typecheck the generated output.
251297 run : nox -s showcase_mypy${{ matrix.variant }}
252298 snippetgen :
299+ needs : all_python_setup
253300 runs-on : ubuntu-latest
254301 steps :
255302 - uses : actions/checkout@v5
256- - name : Set up Python "3.13"
303+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
257304 uses : actions/setup-python@v6
258305 with :
259- python-version : " 3.13 "
306+ python-version : " ${{ env.LATEST_STABLE_PYTHON }} "
260307 cache : ' pip'
261308 - name : Install system dependencies.
262309 run : |
@@ -267,10 +314,10 @@ jobs:
267314 - name : Check autogenerated snippets.
268315 run : nox -s snippetgen
269316 unit :
317+ needs : all_python_setup
270318 strategy :
271319 matrix :
272- python : ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
273-
320+ python : ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
274321 # TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
275322 # Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
276323 runs-on : ubuntu-22.04
@@ -279,8 +326,9 @@ jobs:
279326 - name : Set up Python ${{ matrix.python }}
280327 uses : actions/setup-python@v6
281328 with :
282- python-version : ${{ matrix.python }}
329+ python-version : " ${{ matrix.python }}"
283330 cache : ' pip'
331+ allow-prereleases : true
284332 - name : Install pandoc
285333 run : |
286334 sudo apt-get update
@@ -291,11 +339,11 @@ jobs:
291339 - name : Run unit tests.
292340 run : nox -s unit-${{ matrix.python }}
293341 fragment :
342+ needs : all_python_setup
294343 strategy :
295344 matrix :
296- python : ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
345+ python : ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
297346 variant : ['', _alternative_templates]
298-
299347 # TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
300348 # Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
301349 runs-on : ubuntu-22.04
@@ -304,8 +352,9 @@ jobs:
304352 - name : Set up Python ${{ matrix.python }}
305353 uses : actions/setup-python@v6
306354 with :
307- python-version : ${{ matrix.python }}
355+ python-version : " ${{ matrix.python }}"
308356 cache : ' pip'
357+ allow-prereleases : true
309358 - name : Install pandoc
310359 run : |
311360 sudo apt-get update
@@ -348,29 +397,29 @@ jobs:
348397 runs-on : ubuntu-latest
349398 steps :
350399 - uses : actions/checkout@v5
351- - name : Set up Python 3.13
400+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
352401 uses : actions/setup-python@v6
353402 with :
354- python-version : " 3.13 "
403+ python-version : ${{ env.LATEST_STABLE_PYTHON }}
355404 cache : ' pip'
356405 - name : Install nox.
357406 run : |
358407 python -m pip install nox
359408 - name : Run blacken and lint on the generated output.
360409 run : |
361- nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.13 blacken lint
362- nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.13 blacken lint
363- nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.13 blacken lint
364- nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.13 blacken lint
365- nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.13 blacken lint
410+ nox -f tests/integration/goldens/asset/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
411+ nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
412+ nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
413+ nox -f tests/integration/goldens/logging/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
414+ nox -f tests/integration/goldens/redis/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
366415 goldens-unit :
367416 runs-on : ubuntu-latest
368417 steps :
369418 - uses : actions/checkout@v5
370- - name : Set up Python 3.13
419+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
371420 uses : actions/setup-python@v6
372421 with :
373- python-version : " 3.13 "
422+ python-version : " ${{ env.LATEST_STABLE_PYTHON }} "
374423 cache : ' pip'
375424 - name : Install nox.
376425 run : |
@@ -380,19 +429,20 @@ jobs:
380429 # in order to run unit tests
381430 # See https://github.com/googleapis/gapic-generator-python/issues/1806
382431 run : |
383- nox -f tests/integration/goldens/credentials/noxfile.py -s unit-3.13
384- nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-3.13
385- nox -f tests/integration/goldens/logging/noxfile.py -s unit-3.13
386- nox -f tests/integration/goldens/redis/noxfile.py -s unit-3.13
432+ nox -f tests/integration/goldens/credentials/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
433+ nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
434+ nox -f tests/integration/goldens/logging/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
435+ nox -f tests/integration/goldens/redis/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
387436 goldens-prerelease :
388437 runs-on : ubuntu-latest
389438 steps :
390439 - uses : actions/checkout@v5
391- - name : Set up Python 3.13
440+ - name : Set up Python ${{ env.PREVIEW_PYTHON_VERSION }}
392441 uses : actions/setup-python@v6
393442 with :
394- python-version : " 3.13 "
443+ python-version : " ${{ env.PREVIEW_PYTHON_VERSION }} "
395444 cache : ' pip'
445+ allow-prereleases : true
396446 - name : Install nox.
397447 run : |
398448 python -m pip install nox
@@ -409,10 +459,10 @@ jobs:
409459 runs-on : ubuntu-latest
410460 steps :
411461 - uses : actions/checkout@v5
412- - name : Set up Python "3.13"
462+ - name : Set up Python ${{ env.LATEST_STABLE_PYTHON }}
413463 uses : actions/setup-python@v6
414464 with :
415- python-version : " 3.13 "
465+ python-version : " ${{ env.LATEST_STABLE_PYTHON }} "
416466 cache : ' pip'
417467 - name : Install nox.
418468 run : |
0 commit comments