2828 workflow_dispatch :
2929 inputs :
3030 sha :
31- description : " SHA of commit to run against:"
31+ description : ' SHA of commit to run against:'
3232 type : string
3333 required : true
3434
35- py_version :
36- description : " Python version:"
35+ python_ver :
36+ description : ' Python version:'
3737 type : string
38- default : " 3.10.15"
38+ default : ' 3.10.15'
3939
4040 extra_bazel_options :
41- description : " Extra Bazel options:"
41+ description : ' Extra Bazel options:'
4242 type : string
4343
4444 remake_python_cache :
45- description : " Delete & remake the Python cache"
45+ description : ' Delete & remake the Python cache'
4646 type : boolean
4747 default : false
4848
4949 debug :
50- description : " Print additional workflow info"
50+ description : ' Print additional workflow info'
5151 type : boolean
5252 default : false
5353
5454env :
5555 # 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'
5757
5858 # Additional .bazelrc options to use.
5959 bazelrc_additions : |
@@ -122,29 +122,47 @@ jobs:
122122 GH_TOKEN : ${{github.token}}
123123 # Note that this approach doesn't need to check out a copy of the repo.
124124 run : |
125- set -x
125+ set -x +e
126126 # shellcheck disable=SC2207
127127 # Get an array of paths changed in this workflow trigger event.
128128 if [[ "${{github.event_name}}" == "pull_request" ]]; then
129129 url=${{github.event.pull_request.url}}
130130 paths=($(gh pr view $url --json files --jq '.files | .[].path'))
131131 else
132132 # 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
135153 paths=($(gh api $url --jq '.files[].filename'))
136154 fi
137155 # Test array of paths against the patterns of changes we can ignore.
138156 # 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"
140158 ignorable=(${{env.ignore_patterns}})
141159 for path in "${paths[@]}"; do
142160 for pattern in "${ignorable[@]}"; do
143161 # The path matched a pattern => can be ignored. Go to next path.
144162 [[ $path =~ $pattern ]] && continue 2
145163 done
146164 # None of the patterns matched this path.
147- echo " have_changes=true" >> "$GITHUB_OUTPUT"
165+ echo ' have_changes=true' >> "$GITHUB_OUTPUT"
148166 break
149167 done
150168
@@ -163,12 +181,11 @@ jobs:
163181 uses : actions/checkout@v4
164182
165183 # 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}}
169186 uses : actions/setup-python@v5
170187 with :
171- python-version : ${{inputs.py_version || env.py_version }}
188+ python-version : ${{inputs.python_ver || env.python_ver }}
172189
173190 - name : Set cache keys and other parameters
174191 id : parameters
@@ -257,13 +274,14 @@ jobs:
257274 - name : Set up Python
258275 uses : actions/setup-python@v5
259276 with :
260- python-version : ${{inputs.py_version || env.py_version }}
277+ python-version : ${{inputs.python_ver || env.python_ver }}
261278
262279 - name : Restore our Python cache
263280 uses : actions/cache@v4
264281 with :
265282 key : ${{needs.Setup.outputs.python_cache_key}}
266283 path : ${{needs.Setup.outputs.python_cache_paths}}
284+ fail-on-cache-miss : true
267285
268286 - name : Set up Bazel
269287 uses : bazel-contrib/setup-bazel@0.12.0
@@ -325,13 +343,14 @@ jobs:
325343 - name : Set up Python
326344 uses : actions/setup-python@v5
327345 with :
328- python-version : ${{inputs.py_version || env.py_version }}
346+ python-version : ${{inputs.python_ver || env.python_ver }}
329347
330348 - name : Restore our Python cache
331349 uses : actions/cache@v4
332350 with :
333351 key : ${{needs.Setup.outputs.python_cache_key}}
334352 path : ${{needs.Setup.outputs.python_cache_paths}}
353+ fail-on-cache-miss : true
335354
336355 - name : Get the Python wheel we built
337356 uses : actions/download-artifact@v4
@@ -345,7 +364,7 @@ jobs:
345364
346365 - name : Test the wheel
347366 run : |
348- set -x - e
367+ set -x + e
349368 ./scripts/run_example.sh
350369
351370 Bazel_tests :
@@ -360,13 +379,14 @@ jobs:
360379 - name : Set up Python
361380 uses : actions/setup-python@v5
362381 with :
363- python-version : ${{inputs.py_version || env.py_version }}
382+ python-version : ${{inputs.python_ver || env.python_ver }}
364383
365384 - name : Restore our Python cache
366385 uses : actions/cache@v4
367386 with :
368387 key : ${{needs.Setup.outputs.python_cache_key}}
369388 path : ${{needs.Setup.outputs.python_cache_paths}}
389+ fail-on-cache-miss : true
370390
371391 - name : Set up Bazel
372392 uses : bazel-contrib/setup-bazel@0.12.0
@@ -380,7 +400,7 @@ jobs:
380400 - name : Run all Bazel tests
381401 id : test
382402 run : |
383- set -x - e -o pipefail
403+ set -x + e -o pipefail
384404 printf "Y\n" | ./configure.sh
385405 bazel test ${{inputs.extra_bazel_options}} \
386406 //tensorflow_quantum/... 2>&1 | tee bazel-tests.log
@@ -413,13 +433,14 @@ jobs:
413433 - name : Set up Python
414434 uses : actions/setup-python@v5
415435 with :
416- python-version : ${{inputs.py_version || env.py_version }}
436+ python-version : ${{inputs.python_ver || env.python_ver }}
417437
418438 - name : Restore our Python cache
419439 uses : actions/cache@v4
420440 with :
421441 key : ${{needs.Setup.outputs.python_cache_key}}
422442 path : ${{needs.Setup.outputs.python_cache_paths}}
443+ fail-on-cache-miss : true
423444
424445 - name : Get the Python wheel we built
425446 uses : actions/download-artifact@v4
@@ -437,7 +458,7 @@ jobs:
437458 examples_output=$(python3 quantum/scripts/test_tutorials.py)
438459 exit_code=$?
439460 if [ "$exit_code" != "0" ]; then
440- echo " Tutorials failed to run to completion:"
461+ echo ' Tutorials failed to run to completion:'
441462 echo "{$examples_output}"
442463 exit 64;
443464 fi
@@ -457,13 +478,14 @@ jobs:
457478 - name : Set up Python
458479 uses : actions/setup-python@v5
459480 with :
460- python-version : ${{inputs.py_version || env.py_version }}
481+ python-version : ${{inputs.python_ver || env.python_ver }}
461482
462483 - name : Restore our Python cache
463484 uses : actions/cache@v4
464485 with :
465486 key : ${{needs.Setup.outputs.python_cache_key}}
466487 path : ${{needs.Setup.outputs.python_cache_paths}}
488+ fail-on-cache-miss : true
467489
468490 - name : Set up Bazel
469491 uses : bazel-contrib/setup-bazel@0.12.0
@@ -476,33 +498,33 @@ jobs:
476498
477499 - name : Print debugging info
478500 run : |
479- echo ""
501+ echo ''
480502 echo "::group::Contents of $(pwd)"
481503 ls -la
482- echo " ::endgroup::"
504+ echo ' ::endgroup::'
483505
484- echo " ::group::Pip info"
506+ echo ' ::group::Pip info'
485507 pip --version
486508 pip list
487- echo " ::endgroup::"
509+ echo ' ::endgroup::'
488510
489- echo " ::group::Python installation"
511+ echo ' ::group::Python installation'
490512 pyversion="$(python --version | awk '{print $2}')"
491513 ls -l /opt/hostedtoolcache/{.,Python,Python/"$pyversion"/x64/bin}
492- echo " ::endgroup::"
514+ echo ' ::endgroup::'
493515
494- echo " ::group::Bazel info"
516+ echo ' ::group::Bazel info'
495517 bazel --version
496518 ls -la /home/runner/.cache
497519 if [[ -e /home/runner/.bazel ]]; then
498520 ls -la /home/runner/.bazel
499521 fi
500- echo " ::endgroup::"
522+ echo ' ::endgroup::'
501523
502- echo " ::group::Contents of /home/runner/.bazelrc"
524+ echo ' ::group::Contents of /home/runner/.bazelrc'
503525 cat /home/runner/.bazelrc
504- echo " ::endgroup::"
526+ echo ' ::endgroup::'
505527
506- echo " ::group::Environment variables"
528+ echo ' ::group::Environment variables'
507529 env
508- echo " ::endgroup::"
530+ echo ' ::endgroup::'
0 commit comments