Skip to content

Commit 70974c2

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

File tree

1 file changed

+74
-33
lines changed

1 file changed

+74
-33
lines changed

.github/workflows/tests.yaml

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

2027
jobs:
28+
# `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`.
29+
# Some jobs set up a text matrix which is outside of `steps` and environment variables can't be used directly.
30+
# This requires a workaround based on the discussion in:
31+
# https://github.com/actions/runner/issues/2372
32+
# The limitation is captured here where certain job configurations don't have access to `env`
33+
# https://docs.github.com/en/enterprise-cloud@latest/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#context-availability
34+
all_python_setup:
35+
runs-on: ubuntu-latest
36+
outputs:
37+
all_python: ${{ env.ALL_PYTHON }}
38+
steps:
39+
- name: Set up all python
40+
id: all_python
41+
run: |
42+
echo 'all_python={{ "${{ env.ALL_PYTHON }}" }}'
43+
python_config:
44+
runs-on: ubuntu-latest
45+
outputs:
46+
oldest_python: ${{ env.OLDEST_PYTHON }}
47+
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
48+
steps:
49+
- name: Print env variables for `python_config`
50+
run: |
51+
echo 'oldest_python={{ "${{ env.OLDEST_PYTHON }}" }}'
52+
echo 'latest_stable_python={{ "${{ env.LATEST_STABLE_PYTHON }}" }}'
2153
docs:
2254
runs-on: ubuntu-latest
2355
steps:
@@ -34,11 +66,15 @@ jobs:
3466
- name: Build the documentation.
3567
run: nox -s docs
3668
mypy:
69+
needs: all_python_setup
3770
strategy:
3871
matrix:
3972
# Run mypy on all of the supported python versions listed in setup.py
4073
# https://github.com/python/mypy/blob/master/setup.py
41-
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
74+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
75+
exclude:
76+
# Remove once https://github.com/googleapis/gapic-generator-python/issues/2303 is fixed
77+
- python: '3.7'
4278
runs-on: ubuntu-latest
4379
steps:
4480
- uses: actions/checkout@v4
@@ -52,11 +88,12 @@ jobs:
5288
- name: Check type annotations.
5389
run: nox -s mypy-${{ matrix.python }}
5490
showcase:
91+
needs: python_config
5592
strategy:
5693
# Run showcase tests on the lowest and highest supported runtimes
5794
matrix:
5895
# 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"]
96+
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
6097
target: [showcase, showcase_w_rest_async]
6198
logging_scope: ["", "google"]
6299

@@ -111,10 +148,10 @@ jobs:
111148
run: |
112149
sudo mkdir -p /tmp/workspace/tests/cert/
113150
sudo chown -R ${USER} /tmp/workspace/
114-
- name: Set up Python "3.13"
151+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
115152
uses: actions/setup-python@v5
116153
with:
117-
python-version: "3.13"
154+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
118155
cache: 'pip'
119156
- name: Copy mtls files
120157
run: cp tests/cert/mtls.* /tmp/workspace/tests/cert/
@@ -145,9 +182,10 @@ jobs:
145182
nox -s ${{ matrix.target }}
146183
# TODO(yon-mg): add compute unit tests
147184
showcase-unit:
185+
needs: all_python_setup
148186
strategy:
149187
matrix:
150-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
188+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
151189
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `_w_rest_async` variant when async rest is GA.
152190
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
153191
logging_scope: ["", "google"]
@@ -185,10 +223,10 @@ jobs:
185223
runs-on: ubuntu-latest
186224
steps:
187225
- uses: actions/checkout@v4
188-
- name: Set up Python "3.13"
226+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
189227
uses: actions/setup-python@v5
190228
with:
191-
python-version: "3.13"
229+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
192230
cache: 'pip'
193231
- name: Install system dependencies.
194232
run: |
@@ -213,10 +251,10 @@ jobs:
213251
variant: ['', _alternative_templates]
214252
steps:
215253
- uses: actions/checkout@v4
216-
- name: Set up Python "3.13"
254+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
217255
uses: actions/setup-python@v5
218256
with:
219-
python-version: "3.13"
257+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
220258
cache: 'pip'
221259
- name: Install system dependencies.
222260
run: |
@@ -235,13 +273,14 @@ jobs:
235273
- name: Typecheck the generated output.
236274
run: nox -s showcase_mypy${{ matrix.variant }}
237275
snippetgen:
276+
needs: all_python_setup
238277
runs-on: ubuntu-latest
239278
steps:
240279
- uses: actions/checkout@v4
241-
- name: Set up Python "3.13"
280+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
242281
uses: actions/setup-python@v5
243282
with:
244-
python-version: "3.13"
283+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
245284
cache: 'pip'
246285
- name: Install system dependencies.
247286
run: |
@@ -252,10 +291,10 @@ jobs:
252291
- name: Check autogenerated snippets.
253292
run: nox -s snippetgen
254293
unit:
294+
needs: all_python_setup
255295
strategy:
256296
matrix:
257-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
258-
297+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
259298
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
260299
# Use ubuntu-22.04 until Python 3.7 is removed from the test matrix
261300
runs-on: ubuntu-22.04
@@ -264,7 +303,7 @@ jobs:
264303
- name: Set up Python ${{ matrix.python }}
265304
uses: actions/setup-python@v5
266305
with:
267-
python-version: ${{ matrix.python }}
306+
python-version: "${{ matrix.python }}"
268307
cache: 'pip'
269308
- name: Install pandoc
270309
run: |
@@ -276,9 +315,10 @@ jobs:
276315
- name: Run unit tests.
277316
run: nox -s unit-${{ matrix.python }}
278317
fragment:
318+
needs: all_python_setup
279319
strategy:
280320
matrix:
281-
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
321+
python: ${{ fromJSON(needs.all_python_setup.outputs.all_python) }}
282322
variant: ['', _alternative_templates]
283323

284324
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303): use `ubuntu-latest` once this bug is fixed.
@@ -289,7 +329,7 @@ jobs:
289329
- name: Set up Python ${{ matrix.python }}
290330
uses: actions/setup-python@v5
291331
with:
292-
python-version: ${{ matrix.python }}
332+
python-version: "${{ matrix.python }}"
293333
cache: 'pip'
294334
- name: Install pandoc
295335
run: |
@@ -333,29 +373,29 @@ jobs:
333373
runs-on: ubuntu-latest
334374
steps:
335375
- uses: actions/checkout@v4
336-
- name: Set up Python 3.13
376+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
337377
uses: actions/setup-python@v5
338378
with:
339-
python-version: "3.13"
379+
python-version: ${{ env.LATEST_STABLE_PYTHON }}
340380
cache: 'pip'
341381
- name: Install nox.
342382
run: |
343383
python -m pip install nox
344384
- name: Run blacken and lint on the generated output.
345385
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
386+
nox -f tests/integration/goldens/asset/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
387+
nox -f tests/integration/goldens/credentials/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
388+
nox -f tests/integration/goldens/eventarc/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
389+
nox -f tests/integration/goldens/logging/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
390+
nox -f tests/integration/goldens/redis/noxfile.py -s mypy-${{ env.LATEST_STABLE_PYTHON }} blacken lint
351391
goldens-unit:
352392
runs-on: ubuntu-latest
353393
steps:
354394
- uses: actions/checkout@v4
355-
- name: Set up Python 3.13
395+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
356396
uses: actions/setup-python@v5
357397
with:
358-
python-version: "3.13"
398+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
359399
cache: 'pip'
360400
- name: Install nox.
361401
run: |
@@ -365,19 +405,20 @@ jobs:
365405
# in order to run unit tests
366406
# See https://github.com/googleapis/gapic-generator-python/issues/1806
367407
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
408+
nox -f tests/integration/goldens/credentials/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
409+
nox -f tests/integration/goldens/eventarc/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
410+
nox -f tests/integration/goldens/logging/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
411+
nox -f tests/integration/goldens/redis/noxfile.py -s unit-${{ env.LATEST_STABLE_PYTHON }}
372412
goldens-prerelease:
373413
runs-on: ubuntu-latest
374414
steps:
375415
- uses: actions/checkout@v4
376-
- name: Set up Python 3.13
416+
- name: Set up Python ${{ env.PRE_RELEASE_PYTHON }}
377417
uses: actions/setup-python@v5
378418
with:
379-
python-version: "3.13"
419+
python-version: "${{ env.PRE_RELEASE_PYTHON }}"
380420
cache: 'pip'
421+
allow-prereleases: true
381422
- name: Install nox.
382423
run: |
383424
python -m pip install nox
@@ -394,10 +435,10 @@ jobs:
394435
runs-on: ubuntu-latest
395436
steps:
396437
- uses: actions/checkout@v4
397-
- name: Set up Python "3.13"
438+
- name: Set up Python ${{ env.LATEST_STABLE_PYTHON }}
398439
uses: actions/setup-python@v5
399440
with:
400-
python-version: "3.13"
441+
python-version: "${{ env.LATEST_STABLE_PYTHON }}"
401442
cache: 'pip'
402443
- name: Install nox.
403444
run: |

0 commit comments

Comments
 (0)