28
28
workflow_dispatch :
29
29
inputs :
30
30
sha :
31
- description : " SHA of commit to run against:"
31
+ description : ' SHA of commit to run against:'
32
32
type : string
33
33
required : true
34
34
35
- py_version :
36
- description : " Python version:"
35
+ python_ver :
36
+ description : ' Python version:'
37
37
type : string
38
- default : " 3.10.15"
38
+ default : ' 3.10.15'
39
39
40
40
extra_bazel_options :
41
- description : " Extra Bazel options:"
41
+ description : ' Extra Bazel options:'
42
42
type : string
43
43
44
44
remake_python_cache :
45
- description : " Delete & remake the Python cache"
45
+ description : ' Delete & remake the Python cache'
46
46
type : boolean
47
47
default : false
48
48
49
49
debug :
50
- description : " Print additional workflow info"
50
+ description : ' Print additional workflow info'
51
51
type : boolean
52
52
default : false
53
53
54
54
env :
55
55
# Default Python version to use. Important: give it a full x.y.z number.
56
- py_version : ' 3.10.15'
56
+ python_ver : ' 3.10.15'
57
57
58
58
# Additional .bazelrc options to use.
59
59
bazelrc_additions : |
@@ -122,29 +122,47 @@ jobs:
122
122
GH_TOKEN : ${{github.token}}
123
123
# Note that this approach doesn't need to check out a copy of the repo.
124
124
run : |
125
- set -x
125
+ set -x +e
126
126
# shellcheck disable=SC2207
127
127
# Get an array of paths changed in this workflow trigger event.
128
128
if [[ "${{github.event_name}}" == "pull_request" ]]; then
129
129
url=${{github.event.pull_request.url}}
130
130
paths=($(gh pr view $url --json files --jq '.files | .[].path'))
131
131
else
132
132
# There's no event sha for manual runs, so we rely on user input.
133
- sha=${{github.sha || inputs.sha}}
134
- url="/repos/${{github.repository}}/commits/$sha"
133
+ # Make sure the sha is valid.
134
+ if [[ "${{github.event_name}}" == "workflow_dispatch" ]]; then
135
+ url="repos/${{github.repository}}/commits/${{inputs.sha}}"
136
+ full_sha="$(gh api $url -q '.sha')"
137
+ exit_code=$?
138
+ if [[ "$exit_code" == "0" ]]; then
139
+ sha=$full_sha
140
+ else
141
+ {
142
+ echo "### :x: Workflow error"
143
+ echo "The SHA provided to _Run Workflow_ does not exist:"
144
+ echo "<code>${{inputs.sha}}</code>"
145
+ } >> "$GITHUB_STEP_SUMMARY"
146
+ exit 1
147
+ fi
148
+ else
149
+ sha=${{github.sha}}
150
+ fi
151
+ url="repos/${{github.repository}}/commits/$sha"
152
+ # shellcheck disable=SC2086
135
153
paths=($(gh api $url --jq '.files[].filename'))
136
154
fi
137
155
# Test array of paths against the patterns of changes we can ignore.
138
156
# Default to no-changes if every path matches at least one pattern.
139
- echo " have_changes=false" >> "$GITHUB_OUTPUT"
157
+ echo ' have_changes=false' >> "$GITHUB_OUTPUT"
140
158
ignorable=(${{env.ignore_patterns}})
141
159
for path in "${paths[@]}"; do
142
160
for pattern in "${ignorable[@]}"; do
143
161
# The path matched a pattern => can be ignored. Go to next path.
144
162
[[ $path =~ $pattern ]] && continue 2
145
163
done
146
164
# None of the patterns matched this path.
147
- echo " have_changes=true" >> "$GITHUB_OUTPUT"
165
+ echo ' have_changes=true' >> "$GITHUB_OUTPUT"
148
166
break
149
167
done
150
168
@@ -163,12 +181,11 @@ jobs:
163
181
uses : actions/checkout@v4
164
182
165
183
# Note: setup-python has a cache facility, but we don't use it here
166
- # because we want to cache more things than setup-python does.
167
- - name : Set up Python ${{inputs.py_version || env.py_version}}
168
- id : python
184
+ # because we want to cache more Python things than setup-python does.
185
+ - name : Set up Python ${{inputs.python_ver || env.python_ver}}
169
186
uses : actions/setup-python@v5
170
187
with :
171
- python-version : ${{inputs.py_version || env.py_version }}
188
+ python-version : ${{inputs.python_ver || env.python_ver }}
172
189
173
190
- name : Set cache keys and other parameters
174
191
id : parameters
@@ -257,13 +274,14 @@ jobs:
257
274
- name : Set up Python
258
275
uses : actions/setup-python@v5
259
276
with :
260
- python-version : ${{inputs.py_version || env.py_version }}
277
+ python-version : ${{inputs.python_ver || env.python_ver }}
261
278
262
279
- name : Restore our Python cache
263
280
uses : actions/cache@v4
264
281
with :
265
282
key : ${{needs.Setup.outputs.python_cache_key}}
266
283
path : ${{needs.Setup.outputs.python_cache_paths}}
284
+ fail-on-cache-miss : true
267
285
268
286
- name : Set up Bazel
269
287
uses :
bazel-contrib/[email protected]
@@ -325,13 +343,14 @@ jobs:
325
343
- name : Set up Python
326
344
uses : actions/setup-python@v5
327
345
with :
328
- python-version : ${{inputs.py_version || env.py_version }}
346
+ python-version : ${{inputs.python_ver || env.python_ver }}
329
347
330
348
- name : Restore our Python cache
331
349
uses : actions/cache@v4
332
350
with :
333
351
key : ${{needs.Setup.outputs.python_cache_key}}
334
352
path : ${{needs.Setup.outputs.python_cache_paths}}
353
+ fail-on-cache-miss : true
335
354
336
355
- name : Get the Python wheel we built
337
356
uses : actions/download-artifact@v4
@@ -345,7 +364,7 @@ jobs:
345
364
346
365
- name : Test the wheel
347
366
run : |
348
- set -x - e
367
+ set -x + e
349
368
./scripts/run_example.sh
350
369
351
370
Bazel_tests :
@@ -360,13 +379,14 @@ jobs:
360
379
- name : Set up Python
361
380
uses : actions/setup-python@v5
362
381
with :
363
- python-version : ${{inputs.py_version || env.py_version }}
382
+ python-version : ${{inputs.python_ver || env.python_ver }}
364
383
365
384
- name : Restore our Python cache
366
385
uses : actions/cache@v4
367
386
with :
368
387
key : ${{needs.Setup.outputs.python_cache_key}}
369
388
path : ${{needs.Setup.outputs.python_cache_paths}}
389
+ fail-on-cache-miss : true
370
390
371
391
- name : Set up Bazel
372
392
uses :
bazel-contrib/[email protected]
@@ -380,7 +400,7 @@ jobs:
380
400
- name : Run all Bazel tests
381
401
id : test
382
402
run : |
383
- set -x - e -o pipefail
403
+ set -x + e -o pipefail
384
404
printf "Y\n" | ./configure.sh
385
405
bazel test ${{inputs.extra_bazel_options}} \
386
406
//tensorflow_quantum/... 2>&1 | tee bazel-tests.log
@@ -413,13 +433,14 @@ jobs:
413
433
- name : Set up Python
414
434
uses : actions/setup-python@v5
415
435
with :
416
- python-version : ${{inputs.py_version || env.py_version }}
436
+ python-version : ${{inputs.python_ver || env.python_ver }}
417
437
418
438
- name : Restore our Python cache
419
439
uses : actions/cache@v4
420
440
with :
421
441
key : ${{needs.Setup.outputs.python_cache_key}}
422
442
path : ${{needs.Setup.outputs.python_cache_paths}}
443
+ fail-on-cache-miss : true
423
444
424
445
- name : Get the Python wheel we built
425
446
uses : actions/download-artifact@v4
@@ -437,7 +458,7 @@ jobs:
437
458
examples_output=$(python3 quantum/scripts/test_tutorials.py)
438
459
exit_code=$?
439
460
if [ "$exit_code" != "0" ]; then
440
- echo " Tutorials failed to run to completion:"
461
+ echo ' Tutorials failed to run to completion:'
441
462
echo "{$examples_output}"
442
463
exit 64;
443
464
fi
@@ -457,13 +478,14 @@ jobs:
457
478
- name : Set up Python
458
479
uses : actions/setup-python@v5
459
480
with :
460
- python-version : ${{inputs.py_version || env.py_version }}
481
+ python-version : ${{inputs.python_ver || env.python_ver }}
461
482
462
483
- name : Restore our Python cache
463
484
uses : actions/cache@v4
464
485
with :
465
486
key : ${{needs.Setup.outputs.python_cache_key}}
466
487
path : ${{needs.Setup.outputs.python_cache_paths}}
488
+ fail-on-cache-miss : true
467
489
468
490
- name : Set up Bazel
469
491
uses :
bazel-contrib/[email protected]
@@ -476,33 +498,33 @@ jobs:
476
498
477
499
- name : Print debugging info
478
500
run : |
479
- echo ""
501
+ echo ''
480
502
echo "::group::Contents of $(pwd)"
481
503
ls -la
482
- echo " ::endgroup::"
504
+ echo ' ::endgroup::'
483
505
484
- echo " ::group::Pip info"
506
+ echo ' ::group::Pip info'
485
507
pip --version
486
508
pip list
487
- echo " ::endgroup::"
509
+ echo ' ::endgroup::'
488
510
489
- echo " ::group::Python installation"
511
+ echo ' ::group::Python installation'
490
512
pyversion="$(python --version | awk '{print $2}')"
491
513
ls -l /opt/hostedtoolcache/{.,Python,Python/"$pyversion"/x64/bin}
492
- echo " ::endgroup::"
514
+ echo ' ::endgroup::'
493
515
494
- echo " ::group::Bazel info"
516
+ echo ' ::group::Bazel info'
495
517
bazel --version
496
518
ls -la /home/runner/.cache
497
519
if [[ -e /home/runner/.bazel ]]; then
498
520
ls -la /home/runner/.bazel
499
521
fi
500
- echo " ::endgroup::"
522
+ echo ' ::endgroup::'
501
523
502
- echo " ::group::Contents of /home/runner/.bazelrc"
524
+ echo ' ::group::Contents of /home/runner/.bazelrc'
503
525
cat /home/runner/.bazelrc
504
- echo " ::endgroup::"
526
+ echo ' ::endgroup::'
505
527
506
- echo " ::group::Environment variables"
528
+ echo ' ::group::Environment variables'
507
529
env
508
- echo " ::endgroup::"
530
+ echo ' ::endgroup::'
0 commit comments