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

Commit fa8ea30

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

1 file changed

Lines changed: 71 additions & 33 deletions

File tree

.github/workflows/tests.yaml

Lines changed: 71 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: ${{ steps.python_config.outputs.oldest_python }}
45+
latest_stable_python: ${{ steps.python_config.outputs.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: ["${{ oldest_python }}", "${{ latest_stable_python }}"]
6095
target: [showcase, showcase_w_rest_async]
6196
logging_scope: ["", "google"]
6297

@@ -111,10 +146,10 @@ jobs:
111146
run: |
112147
sudo mkdir -p /tmp/workspace/tests/cert/
113148
sudo chown -R ${USER} /tmp/workspace/
114-
- name: Set up Python "3.13"
149+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
115150
uses: actions/setup-python@v5
116151
with:
117-
python-version: "3.13"
152+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
118153
cache: 'pip'
119154
- name: Copy mtls files
120155
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
@@ -145,9 +180,10 @@ jobs:
145180
nox -s ${{ matrix.target }}
146181
# TODO(yon-mg): add compute unit tests
147182
showcase-unit:
183+
needs: all_python_setup
148184
strategy:
149185
matrix:
150-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
186+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
151187
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `_w_rest_async` variant when async rest is GA.
152188
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
153189
logging_scope: ["", "google"]
@@ -185,10 +221,10 @@ jobs:
185221
runs-on: ubuntu-latest
186222
steps:
187223
- uses: actions/checkout@v4
188-
- name: Set up Python "3.13"
224+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
189225
uses: actions/setup-python@v5
190226
with:
191-
python-version: "3.13"
227+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
192228
cache: 'pip'
193229
- name: Install system dependencies.
194230
run: |
@@ -213,10 +249,10 @@ jobs:
213249
variant: ['', _alternative_templates]
214250
steps:
215251
- uses: actions/checkout@v4
216-
- name: Set up Python "3.13"
252+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
217253
uses: actions/setup-python@v5
218254
with:
219-
python-version: "3.13"
255+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
220256
cache: 'pip'
221257
- name: Install system dependencies.
222258
run: |
@@ -235,13 +271,14 @@ jobs:
235271
- name: Typecheck the generated output.
236272
run: nox -s showcase_mypy${{ matrix.variant }}
237273
snippetgen:
274+
needs: all_python_setup
238275
runs-on: ubuntu-latest
239276
steps:
240277
- uses: actions/checkout@v4
241-
- name: Set up Python "3.13"
278+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
242279
uses: actions/setup-python@v5
243280
with:
244-
python-version: "3.13"
281+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
245282
cache: 'pip'
246283
- name: Install system dependencies.
247284
run: |
@@ -252,10 +289,10 @@ jobs:
252289
- name: Check autogenerated snippets.
253290
run: nox -s snippetgen
254291
unit:
292+
needs: all_python_setup
255293
strategy:
256294
matrix:
257-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
258-
295+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
259296
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
260297
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
261298
runs-on: ubuntu-22.04
@@ -264,7 +301,7 @@ jobs:
264301
- name: Set up Python ${{ matrix.python }}
265302
uses: actions/setup-python@v5
266303
with:
267-
python-version: ${{ matrix.python }}
304+
python-version: "${{ matrix.python }}"
268305
cache: 'pip'
269306
- name: Install pandoc
270307
run: |
@@ -276,9 +313,10 @@ jobs:
276313
- name: Run unit tests.
277314
run: nox -s unit-${{ matrix.python }}
278315
fragment:
316+
needs: all_python_setup
279317
strategy:
280318
matrix:
281-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
319+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
282320
variant: ['', _alternative_templates]
283321

284322
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
@@ -289,7 +327,7 @@ jobs:
289327
- name: Set up Python ${{ matrix.python }}
290328
uses: actions/setup-python@v5
291329
with:
292-
python-version: ${{ matrix.python }}
330+
python-version: "${{ matrix.python }}"
293331
cache: 'pip'
294332
- name: Install pandoc
295333
run: |
@@ -333,29 +371,29 @@ jobs:
333371
runs-on: ubuntu-latest
334372
steps:
335373
- uses: actions/checkout@v4
336-
- name: Set up Python 3.13
374+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
337375
uses: actions/setup-python@v5
338376
with:
339-
python-version: "3.13"
377+
python-version: ${{ env.LATEST_STABLE_PYTHON }}
340378
cache: 'pip'
341379
- name: Install nox.
342380
run: |
343381
python -m pip install nox
344382
- name: Run blacken and lint on the generated output.
345383
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
384+
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
385+
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
386+
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
387+
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
388+
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
351389
goldens-unit:
352390
runs-on: ubuntu-latest
353391
steps:
354392
- uses: actions/checkout@v4
355-
- name: Set up Python 3.13
393+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
356394
uses: actions/setup-python@v5
357395
with:
358-
python-version: "3.13"
396+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
359397
cache: 'pip'
360398
- name: Install nox.
361399
run: |
@@ -365,18 +403,18 @@ jobs:
365403
# in order to run unit tests
366404
# See https://github.com/googleapis/gapic-generator-python/issues/1806
367405
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
406+
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
407+
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
408+
nox -f tests/integration/goldens/logging/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
409+
nox -f tests/integration/goldens/redis/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
372410
goldens-prerelease:
373411
runs-on: ubuntu-latest
374412
steps:
375413
- uses: actions/checkout@v4
376-
- name: Set up Python 3.13
414+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
377415
uses: actions/setup-python@v5
378416
with:
379-
python-version: "3.13"
417+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
380418
cache: 'pip'
381419
- name: Install nox.
382420
run: |
@@ -394,10 +432,10 @@ jobs:
394432
runs-on: ubuntu-latest
395433
steps:
396434
- uses: actions/checkout@v4
397-
- name: Set up Python "3.13"
435+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
398436
uses: actions/setup-python@v5
399437
with:
400-
python-version: "3.13"
438+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
401439
cache: 'pip'
402440
- name: Install nox.
403441
run: |

0 commit comments

Comments
 (0)