Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 8e5c183

Browse files
committed
build: clean up github action
1 parent 9310dd9 commit 8e5c183

1 file changed

Lines changed: 72 additions & 33 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,38 @@ concurrency:
1616
env:
1717
SHOWCASE_VERSION: 0.35.0
1818
PROTOC_VERSION: 3.20.2
19+
OLDEST_PYTHON: 3.7
20+
LATEST_STABLE_PYTHON: 3.13
21+
22+
permissions:
23+
contents: read
1924

2025
jobs:
26+
# `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`.
27+
# Some jobs set up a text matrix which is outside of `steps` and environment variables can't be used directly.
28+
# This requires a workaround based on the discussion in:
29+
# https://github.com/actions/runner/issues/2372
30+
# The limitation is captured here where certain job configurations don't have access to `env`
31+
# https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability
32+
all_python_setup:
33+
runs-on: ubuntu-latest
34+
outputs:
35+
all_python: ${{ steps.all_python_setup.outputs.all_python }}
36+
steps:
37+
- name: Set up all python
38+
id: all_python
39+
run: |
40+
echo 'all_python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]' >> $GITHUB_OUTPUT
41+
python_config:
42+
runs-on: ubuntu-latest
43+
outputs:
44+
oldest_python: ${{ env.OLDEST_PYTHON }}
45+
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
46+
steps:
47+
- name: Print env variables for `python_config`
48+
run: |
49+
echo 'oldest_python={{ "${{ env.OLDEST_PYTHON }}" }}'
50+
echo 'latest_stable_python={{ "${{ env.LATEST_STABLE_PYTHON }}" }}'
2151
docs:
2252
runs-on: ubuntu-latest
2353
steps:
@@ -34,11 +64,15 @@ jobs:
3464
- name: Build the documentation.
3565
run: nox -s docs
3666
mypy:
67+
needs: all_python_setup
3768
strategy:
3869
matrix:
3970
# Run mypy on all of the supported python versions listed in setup.py
4071
# https://github.com/python/mypy/blob/master/setup.py
41-
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
72+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
73+
exclude:
74+
# Remove once https://github.com/googleapis/gapic-generator-python/issues/2303 is fixed
75+
- python: 3.7
4276
runs-on: ubuntu-latest
4377
steps:
4478
- uses: actions/checkout@v4
@@ -52,11 +86,12 @@ jobs:
5286
- name: Check type annotations.
5387
run: nox -s mypy-${{ matrix.python }}
5488
showcase:
89+
needs: python_config
5590
strategy:
5691
# Run showcase tests on the lowest and highest supported runtimes
5792
matrix:
5893
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
59-
python: ["3.7", "3.13"]
94+
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
6095
target: [showcase, showcase_w_rest_async]
6196
logging_scope: ["", "google"]
6297

@@ -99,6 +134,7 @@ jobs:
99134
GOOGLE_SDK_PYTHON_LOGGING_SCOPE: ${{ matrix.logging_scope }}
100135
run: nox -s ${{ matrix.target }}-${{ matrix.python }}
101136
showcase-mtls:
137+
needs: python_config
102138
if: ${{ false }} # TODO(dovs): reenable when #1218 is fixed
103139
strategy:
104140
matrix:
@@ -111,10 +147,10 @@ jobs:
111147
run: |
112148
sudo mkdir -p /tmp/workspace/tests/cert/
113149
sudo chown -R ${USER} /tmp/workspace/
114-
- name: Set up Python "3.13"
150+
- name: Set up Python ${{ needs.python_config.outputs.latest_stable_python }}
115151
uses: actions/setup-python@v5
116152
with:
117-
python-version: "3.13"
153+
python-version: "${{ needs.python_config.outputs.latest_stable_python }}"
118154
cache: 'pip'
119155
- name: Copy mtls files
120156
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
@@ -145,9 +181,10 @@ jobs:
145181
nox -s ${{ matrix.target }}
146182
# TODO(yon-mg): add compute unit tests
147183
showcase-unit:
184+
needs: all_python_setup
148185
strategy:
149186
matrix:
150-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
187+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
151188
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `_w_rest_async` variant when async rest is GA.
152189
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
153190
logging_scope: ["", "google"]
@@ -185,10 +222,10 @@ jobs:
185222
runs-on: ubuntu-latest
186223
steps:
187224
- uses: actions/checkout@v4
188-
- name: Set up Python "3.13"
225+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
189226
uses: actions/setup-python@v5
190227
with:
191-
python-version: "3.13"
228+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
192229
cache: 'pip'
193230
- name: Install system dependencies.
194231
run: |
@@ -213,10 +250,10 @@ jobs:
213250
variant: ['', _alternative_templates]
214251
steps:
215252
- uses: actions/checkout@v4
216-
- name: Set up Python "3.13"
253+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
217254
uses: actions/setup-python@v5
218255
with:
219-
python-version: "3.13"
256+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
220257
cache: 'pip'
221258
- name: Install system dependencies.
222259
run: |
@@ -235,13 +272,14 @@ jobs:
235272
- name: Typecheck the generated output.
236273
run: nox -s showcase_mypy${{ matrix.variant }}
237274
snippetgen:
275+
needs: all_python_setup
238276
runs-on: ubuntu-latest
239277
steps:
240278
- uses: actions/checkout@v4
241-
- name: Set up Python "3.13"
279+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
242280
uses: actions/setup-python@v5
243281
with:
244-
python-version: "3.13"
282+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
245283
cache: 'pip'
246284
- name: Install system dependencies.
247285
run: |
@@ -252,10 +290,10 @@ jobs:
252290
- name: Check autogenerated snippets.
253291
run: nox -s snippetgen
254292
unit:
293+
needs: all_python_setup
255294
strategy:
256295
matrix:
257-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
258-
296+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
259297
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
260298
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
261299
runs-on: ubuntu-22.04
@@ -264,7 +302,7 @@ jobs:
264302
- name: Set up Python ${{ matrix.python }}
265303
uses: actions/setup-python@v5
266304
with:
267-
python-version: ${{ matrix.python }}
305+
python-version: "${{ matrix.python }}"
268306
cache: 'pip'
269307
- name: Install pandoc
270308
run: |
@@ -276,9 +314,10 @@ jobs:
276314
- name: Run unit tests.
277315
run: nox -s unit-${{ matrix.python }}
278316
fragment:
317+
needs: all_python_setup
279318
strategy:
280319
matrix:
281-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
320+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
282321
variant: ['', _alternative_templates]
283322

284323
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
@@ -289,7 +328,7 @@ jobs:
289328
- name: Set up Python ${{ matrix.python }}
290329
uses: actions/setup-python@v5
291330
with:
292-
python-version: ${{ matrix.python }}
331+
python-version: "${{ matrix.python }}"
293332
cache: 'pip'
294333
- name: Install pandoc
295334
run: |
@@ -333,29 +372,29 @@ jobs:
333372
runs-on: ubuntu-latest
334373
steps:
335374
- uses: actions/checkout@v4
336-
- name: Set up Python 3.13
375+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
337376
uses: actions/setup-python@v5
338377
with:
339-
python-version: "3.13"
378+
python-version: ${{ env.LATEST_STABLE_PYTHON }}
340379
cache: 'pip'
341380
- name: Install nox.
342381
run: |
343382
python -m pip install nox
344383
- name: Run blacken and lint on the generated output.
345384
run: |
346-
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-3.13 blacken lint
347-
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-3.13 blacken lint
348-
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-3.13 blacken lint
349-
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-3.13 blacken lint
350-
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-3.13 blacken lint
385+
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
386+
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
387+
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
388+
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
389+
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
351390
goldens-unit:
352391
runs-on: ubuntu-latest
353392
steps:
354393
- uses: actions/checkout@v4
355-
- name: Set up Python 3.13
394+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
356395
uses: actions/setup-python@v5
357396
with:
358-
python-version: "3.13"
397+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
359398
cache: 'pip'
360399
- name: Install nox.
361400
run: |
@@ -365,18 +404,18 @@ jobs:
365404
# in order to run unit tests
366405
# See https://github.com/googleapis/gapic-generator-python/issues/1806
367406
run: |
368-
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-3.13
369-
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-3.13
370-
nox -f tests/integration/goldens/logging/noxfile.py -s unit-3.13
371-
nox -f tests/integration/goldens/redis/noxfile.py -s unit-3.13
407+
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
408+
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
409+
nox -f tests/integration/goldens/logging/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
410+
nox -f tests/integration/goldens/redis/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
372411
goldens-prerelease:
373412
runs-on: ubuntu-latest
374413
steps:
375414
- uses: actions/checkout@v4
376-
- name: Set up Python 3.13
415+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
377416
uses: actions/setup-python@v5
378417
with:
379-
python-version: "3.13"
418+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
380419
cache: 'pip'
381420
- name: Install nox.
382421
run: |
@@ -394,10 +433,10 @@ jobs:
394433
runs-on: ubuntu-latest
395434
steps:
396435
- uses: actions/checkout@v4
397-
- name: Set up Python "3.13"
436+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
398437
uses: actions/setup-python@v5
399438
with:
400-
python-version: "3.13"
439+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
401440
cache: 'pip'
402441
- name: Install nox.
403442
run: |

0 commit comments

Comments
 (0)