Skip to content

Commit 1678e3c

Browse files
authored
Fix bugs & improve new CI workflows (#857)
There are no functional changes in this PR in terms of what checks are performed; everything concerns either - bugs in the workflows that didn't become apparent until they were merged - minor improvements for better error catching and reporting - changes for style consistency across the files
2 parents 2f1503f + 6691288 commit 1678e3c

File tree

5 files changed

+231
-167
lines changed

5 files changed

+231
-167
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "clang-format-error",
5+
"severity": "error",
6+
"pattern": [
7+
{
8+
"regexp": "^(.*?)\\((\\d+),(\\d*)\\):\\s+(?:fatal\\s+)?error:\\s+(.*)$",
9+
"file": 1,
10+
"line": 2,
11+
"column": 3,
12+
"message": 4
13+
}
14+
]
15+
},
16+
{
17+
"owner": "clang-format-warning",
18+
"severity": "warning",
19+
"pattern": [
20+
{
21+
"regexp": "^(.*?)\\((\\d+),(\\d*)\\):\\s+(?:fatal\\s+)?warning:\\s+(.*)$",
22+
"file": 1,
23+
"line": 2,
24+
"column": 3,
25+
"message": 4
26+
}
27+
]
28+
}
29+
]
30+
}

.github/workflows/ci-build-checks.yaml

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ on:
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

5454
env:
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/[email protected]
@@ -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/[email protected]
@@ -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/[email protected]
@@ -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

Comments
 (0)