Skip to content

Commit dfb9dcb

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

File tree

1 file changed

+72
-33
lines changed

1 file changed

+72
-33
lines changed

.github/workflows/tests.yaml

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,39 @@ 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+
ALL_PYTHON: "['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13']"
22+
23+
permissions:
24+
contents: read
1925

2026
jobs:
27+
# `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`.
28+
# Some jobs set up a text matrix which is outside of `steps` and environment variables can't be used directly.
29+
# This requires a workaround based on the discussion in:
30+
# https://github.com/actions/runner/issues/2372
31+
# The limitation is captured here where certain job configurations don't have access to `env`
32+
# https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability
33+
all_python_setup:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
all_python: ${{ env.ALL_PYTHON }}
37+
steps:
38+
- name: Set up all python
39+
id: all_python
40+
run: |
41+
echo 'all_python={{ "${{ env.ALL_PYTHON }}" }}'
42+
python_config:
43+
runs-on: ubuntu-latest
44+
outputs:
45+
oldest_python: ${{ env.OLDEST_PYTHON }}
46+
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
47+
steps:
48+
- name: Print env variables for `python_config`
49+
run: |
50+
echo 'oldest_python={{ "${{ env.OLDEST_PYTHON }}" }}'
51+
echo 'latest_stable_python={{ "${{ env.LATEST_STABLE_PYTHON }}" }}'
2152
docs:
2253
runs-on: ubuntu-latest
2354
steps:
@@ -34,11 +65,15 @@ jobs:
3465
- name: Build the documentation.
3566
run: nox -s docs
3667
mypy:
68+
needs: all_python_setup
3769
strategy:
3870
matrix:
3971
# Run mypy on all of the supported python versions listed in setup.py
4072
# https://github.com/python/mypy/blob/master/setup.py
41-
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
73+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
74+
exclude:
75+
# Remove once https://github.com/googleapis/gapic-generator-python/issues/2303 is fixed
76+
- python: '3.7'
4277
runs-on: ubuntu-latest
4378
steps:
4479
- uses: actions/checkout@v4
@@ -52,11 +87,12 @@ jobs:
5287
- name: Check type annotations.
5388
run: nox -s mypy-${{ matrix.python }}
5489
showcase:
90+
needs: python_config
5591
strategy:
5692
# Run showcase tests on the lowest and highest supported runtimes
5793
matrix:
5894
# 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"]
95+
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
6096
target: [showcase, showcase_w_rest_async]
6197
logging_scope: ["", "google"]
6298

@@ -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 ${{ env.LATEST_STABLE_PYTHON }}
115151
uses: actions/setup-python@v5
116152
with:
117-
python-version: "3.13"
153+
python-version: "${{ env.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)