Repository navigation
399 lines (382 loc) · 17.1 KB
/
Copy pathgapic-generator-tests.yml
File metadata and controls
399 lines (382 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
permissions:
contents: read
name: Gapic Generator Specialized Tests
on:
pull_request:
push:
branches: [main]
concurrency:
group: gapic-gen-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
SHOWCASE_VERSION: 0.44.2
PROTOC_VERSION: 33.5
LATEST_STABLE_PYTHON: 3.14
OLDEST_PYTHON: '3.10'
PRERELEASE_PYTHON: 3.15
ALL_PYTHON: "['3.10', '3.11', '3.12', '3.13', '3.14', '3.15']"
TRIMMED_PYTHON: "['3.10', '3.14', '3.15']"
jobs:
# Check if the gapic-generator was changed. If so, execute specialized tests
check_changes:
runs-on: ubuntu-latest
outputs:
run_generator: ${{ steps.filter.outputs.generator }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
id: filter
with:
filters: |
generator:
- 'packages/gapic-generator/**'
- '.github/workflows/gapic-generator-tests.yml'
# Preserve the workaround for env variables in matrix
python_config:
needs: check_changes
if: ${{ needs.check_changes.outputs.run_generator == 'true' }}
runs-on: ubuntu-latest
outputs:
all_python: ${{ env.ALL_PYTHON }}
latest_stable_python: ${{ env.LATEST_STABLE_PYTHON }}
oldest_python: ${{ env.OLDEST_PYTHON }}
prerelease_python: ${{ env.PRERELEASE_PYTHON }}
trimmed_python: ${{ env.TRIMMED_PYTHON }}
steps:
- run: echo "Initializing config for gapic-generator"
showcase-unit:
needs: python_config
strategy:
fail-fast: false
matrix:
python: ${{ fromJSON(needs.python_config.outputs.all_python) }}
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, _w_rest_async]
logging_scope: ["", "google"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: "${{ matrix.python }}"
allow-prereleases: true
# Caches compiled wheels locally to prevent building heavy libraries
# such as grpcio, which we build from scratch on every run for Python 3.15+.
# Follow https://github.com/grpc/grpc/issues/41010 for updates.
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install System Deps & Protoc
run: |
sudo apt-get update && sudo apt-get install -y curl pandoc unzip
sudo mkdir -p /usr/src/protoc/ && sudo chown -R ${USER} /usr/src/
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc.zip
cd /usr/src/protoc/ && unzip protoc.zip
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- name: Run Nox
env:
GOOGLE_SDK_PYTHON_LOGGING_SCOPE: ${{ matrix.logging_scope }}
MATRIX_PYTHON: ${{ matrix.python }}
run: |
pip install nox
cd packages/gapic-generator
nox -s showcase_unit${{ matrix.variant }}-${MATRIX_PYTHON}
showcase:
needs: python_config
strategy:
# Run showcase tests on the lowest and highest supported runtimes
matrix:
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
target: [showcase, showcase_w_rest_async]
logging_scope: ["", "google"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python "${{ matrix.python }}"
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: "${{ matrix.python }}"
cache: 'pip'
- name: Install system dependencies.
run: |
sudo apt-get update
sudo apt-get install -y curl pandoc unzip
- name: Install showcase
run: |
sudo mkdir -p /usr/src/showcase
sudo chown -R ${USER} /usr/src/
curl --location https://github.com/googleapis/gapic-showcase/releases/download/v${SHOWCASE_VERSION}/gapic-showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz --output /usr/src/showcase/showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz
cd /usr/src/showcase/
tar -xf showcase-*
./gapic-showcase run &
cd -
- name: Install nox.
run: python -m pip install nox
- name: Install protoc
run: |
sudo mkdir -p /usr/src/protoc/
sudo chown -R ${USER} /usr/src/
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc-${PROTOC_VERSION}.zip
cd /usr/src/protoc/
unzip protoc-${PROTOC_VERSION}.zip
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- name: Run showcase tests.
env:
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2286): Construct nox sessions with logging enabled.
GOOGLE_SDK_PYTHON_LOGGING_SCOPE: ${{ matrix.logging_scope }}
MATRIX_PYTHON: ${{ matrix.python }}
run: |
cd packages/gapic-generator
nox -s ${{ matrix.target }}-${MATRIX_PYTHON}
- name: Upload Raw Spans Artifact
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: raw-spans-${{ matrix.target }}-${{ matrix.python }}${{ matrix.logging_scope && format('-{0}', matrix.logging_scope) || '' }}
path: packages/gapic-generator/tests/system/raw_spans_output.json
if-no-files-found: ignore
showcase-canary:
needs: python_config
strategy:
# Run canary tests with local monorepo google-api-core on bookend runtimes
matrix:
python: ["${{ needs.python_config.outputs.oldest_python }}", "${{ needs.python_config.outputs.latest_stable_python }}"]
target: [showcase, showcase_w_rest_async]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python "${{ matrix.python }}"
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: "${{ matrix.python }}"
cache: 'pip'
- name: Install system dependencies.
run: |
sudo apt-get update
sudo apt-get install -y curl pandoc unzip
- name: Install showcase
run: |
sudo mkdir -p /usr/src/showcase
sudo chown -R ${USER} /usr/src/
curl --location https://github.com/googleapis/gapic-showcase/releases/download/v${SHOWCASE_VERSION}/gapic-showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz --output /usr/src/showcase/showcase-${SHOWCASE_VERSION}-linux-amd64.tar.gz
cd /usr/src/showcase/
tar -xf showcase-*
./gapic-showcase run &
cd -
- name: Install nox.
run: python -m pip install nox
- name: Install protoc
run: |
sudo mkdir -p /usr/src/protoc/
sudo chown -R ${USER} /usr/src/
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc-${PROTOC_VERSION}.zip
cd /usr/src/protoc/
unzip protoc-${PROTOC_VERSION}.zip
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- name: Run showcase canary with local google-api-core.
env:
INSTALL_LOCAL_CORE: "true"
MATRIX_PYTHON: ${{ matrix.python }}
run: |
cd packages/gapic-generator
nox -s ${{ matrix.target }}-${MATRIX_PYTHON}
- name: Upload Raw Spans Artifact
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: raw-spans-canary-${{ matrix.target }}-${{ matrix.python }}
path: packages/gapic-generator/tests/system/raw_spans_output.json
if-no-files-found: ignore
showcase-mypy:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Mypy with released version of google-api-core from PyPI
run: |
pip install nox
cd packages/gapic-generator
nox -s showcase_mypy
showcase-mypy-canary:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Mypy Canary with local google-api-core
env:
INSTALL_LOCAL_CORE: "true"
run: |
pip install nox
cd packages/gapic-generator
nox -s showcase_mypy
goldens:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: ${{ needs.python_config.outputs.latest_stable_python }}
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Goldens
env:
LATEST_STABLE_PYTHON: ${{ needs.python_config.outputs.latest_stable_python }}
# TODO(https://github.com/googleapis/google-cloud-python/issues/16312):
# Add pkg 'showcase' once enum field header formatting in test_compliance.py is fixed.
run: |
pip install nox
cd packages/gapic-generator
for pkg in credentials eventarc logging redis; do
nox -f tests/integration/goldens/$pkg/noxfile.py -s format lint unit-${LATEST_STABLE_PYTHON} core_deps_from_source
done
# Run pylint (errors-only) over the goldens so generator regressions
# like undefined names or import-time breakage that ruff/flake8 do
# not flag are caught at PR time.
# See https://github.com/googleapis/google-cloud-python/issues/16393.
- name: Pylint goldens (errors only)
run: |
pip install --quiet pylint
cd packages/gapic-generator/tests/integration/goldens
for pkg in credentials eventarc logging redis showcase; do
pylint --rcfile=.pylintrc --errors-only --recursive=y "$pkg/google"
done
goldens-prerelease:
needs: python_config
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python ${{ needs.python_config.outputs.prerelease_python }}
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: ${{ needs.python_config.outputs.prerelease_python }}
allow-prereleases: true
# Caches compiled wheels locally to prevent building heavy libraries
# such as grpcio, which we build from scratch on every run for Python 3.15+.
# Follow https://github.com/grpc/grpc/issues/41010 for updates.
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install System Deps
run: sudo apt-get update && sudo apt-get install -y pandoc
- name: Run Goldens (Prerelease)
# TODO(https://github.com/googleapis/google-cloud-python/issues/16312):
# Add pkg 'showcase' once enum field header formatting in test_compliance.py is fixed.
run: |
pip install nox
cd packages/gapic-generator
for pkg in credentials eventarc logging redis; do
nox -f tests/integration/goldens/$pkg/noxfile.py -s prerelease_deps
done
fragment-snippet:
needs: python_config
strategy:
matrix:
python: ${{ fromJSON(needs.python_config.outputs.trimmed_python) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
# Caches compiled wheels locally to prevent building heavy libraries
# such as grpcio, which we build from scratch on every run for Python 3.15+.
# Follow https://github.com/grpc/grpc/issues/41010 for updates.
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
- name: Install System Deps & Protoc
run: |
sudo apt-get update && sudo apt-get install -y curl pandoc unzip
sudo mkdir -p /usr/src/protoc/ && sudo chown -R ${USER} /usr/src/
curl --location https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip --output /usr/src/protoc/protoc.zip
cd /usr/src/protoc/ && unzip protoc.zip
sudo ln -s /usr/src/protoc/bin/protoc /usr/local/bin/protoc
- name: Run Tests
run: |
pip install nox
cd packages/gapic-generator
# Run fragment for current matrix python
nox -s fragment-${MATRIX_PYTHON}
# Run snippetgen only on the latest stable to avoid the "Python not found" error
if [ "${MATRIX_PYTHON}" == "${LATEST_STABLE_PYTHON}" ]; then
nox -s snippetgen
fi
env:
MATRIX_PYTHON: ${{ matrix.python }}
LATEST_STABLE_PYTHON: ${{ needs.python_config.outputs.latest_stable_python }}
integration:
needs: python_config
# Only runs if the Gatekeeper passed
if: ${{ needs.python_config.result == 'success' }}
runs-on: ubuntu-latest
container: gcr.io/gapic-images/googleapis # zizmor: ignore[unpinned-images]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Cache Bazel files
id: cache-bazel
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: ~/.cache/bazel
# Ensure CACHE_VERSION is defined in the mono-repo secrets!
key: ${{ runner.os }}-bazel-20210105-${{ secrets.CACHE_VERSION }}
- name: Run Bazel Integration Tests
run: |
# We need to move into the package directory if the
# WORKSPACE file is located there.
cd packages/gapic-generator
bazelisk test //tests/integration/... --test_output=errors
# Final job to simplify branch protection rules.
# This job will be reported as 'Success' if all its dependencies either
# pass or are skipped due to path filtering.
status:
needs: [check_changes, python_config, showcase-unit, showcase, showcase-mypy, showcase-mypy-canary, goldens, goldens-prerelease, fragment-snippet, integration]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check all jobs for failure
env:
NEEDS_JSON: ${{ toJson(needs) }}
run: |
# 1. Print a human-readable list of each dependency job and its final status.
echo "Job Results:"
echo "$NEEDS_JSON" | jq -r 'to_entries[] | " - \(.key): \(.value.result)"'
# 2. Evaluate if any job actually failed or was cancelled.
if echo "$NEEDS_JSON" | jq -e 'to_entries[].value | select(.result == "failure" or .result == "cancelled")' >/dev/null; then
echo "Error: One or more required jobs failed or were cancelled."
exit 1
fi
echo "All checks passed or were successfully skipped."