Skip to content

Commit

Permalink
hack/boilerplate.sh: fix error handling and use python3 (GoogleContai…
Browse files Browse the repository at this point in the history
…nerTools#2587)

* hack/boilerplate.sh: fix successful return code when call to python fails

* hack/boilerplate.sh: update to python3

python2 is no longer included in most distros and will be removed from
Github Actions Ubuntu images:
actions/runner-images#7402
  • Loading branch information
andreasf committed Jun 20, 2023
1 parent cb242ae commit 7cd39d1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions hack/boilerplate.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,16 +12,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e

# Ignore these paths in the following tests.
ignore="vendor\|out"
BOILERPLATEDIR=./hack/boilerplate
files=$(python3 ${BOILERPLATEDIR}/boilerplate.py --rootdir . --boilerplate-dir ${BOILERPLATEDIR})

# Grep returns a non-zero exit code if we don't match anything, which is good in this case.
set +e
files=$(python ${BOILERPLATEDIR}/boilerplate.py --rootdir . --boilerplate-dir ${BOILERPLATEDIR} | grep -v $ignore)
relevant_files=$(echo "$files" | grep -v $ignore)
set -e
if [[ ! -z ${files} ]]; then

if [[ ! -z ${relevant_files} ]]; then
echo "Boilerplate missing in:"
echo "${files}"
echo "${relevant_files}"
exit 1
fi
2 changes: 1 addition & 1 deletion hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright 2018 Google LLC
#
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate/boilerplate.py.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright YEAR Google LLC
#
Expand Down

0 comments on commit 7cd39d1

Please sign in to comment.