1#!/usr/bin/env bash 2# Copyright 2019 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16 17 18# Collection of helper functions that can be used in the different continuous 19# integration scripts. 20 21# A small utility to run the command and only print logs if the command fails. 22# On success, all logs are hidden. This helps to keep the log output clean and 23# makes debugging easier. 24function readable_run { 25 "$@" 2>&1 26 echo "Command completed successfully at $(date)" 27} 28 29# Check if the regex ${1} is to be found in the pathspec ${2}. 30# An optional error messsage can be passed with ${3} 31function check_contents() { 32 GREP_OUTPUT=$(git grep -E -rn ${1} -- ${2}) 33 34 if [ "${GREP_OUTPUT}" ]; then 35 echo "==============================================" 36 echo "Found matches for ${1} that are not permitted." 37 echo "${3}" 38 echo "==============================================" 39 echo "${GREP_OUTPUT}" 40 return 1 41 fi 42} 43