From 7cd39d14e3b910415c3ee0950f8ec5d27993dfe2 Mon Sep 17 00:00:00 2001 From: Andreas Fleig Date: Tue, 20 Jun 2023 19:46:30 +0200 Subject: [PATCH] hack/boilerplate.sh: fix error handling and use python3 (#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: https://github.com/actions/runner-images/issues/7402 --- hack/boilerplate.sh | 11 +++++++---- hack/boilerplate/boilerplate.py | 2 +- hack/boilerplate/boilerplate.py.txt | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/hack/boilerplate.sh b/hack/boilerplate.sh index b8cdb96f2..492db0938 100755 --- a/hack/boilerplate.sh +++ b/hack/boilerplate.sh @@ -1,5 +1,4 @@ #!/bin/bash - # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -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 diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py index 049db2ab0..2f9e2bce3 100644 --- a/hack/boilerplate/boilerplate.py +++ b/hack/boilerplate/boilerplate.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2018 Google LLC # diff --git a/hack/boilerplate/boilerplate.py.txt b/hack/boilerplate/boilerplate.py.txt index 3b676c312..6d6f49ec8 100644 --- a/hack/boilerplate/boilerplate.py.txt +++ b/hack/boilerplate/boilerplate.py.txt @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright YEAR Google LLC #