mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #10797 from ethereum/refactor-and-shellcheck-cleanup-in-report-errors-sh
Refactor and shellcheck cleanup in report_errors.sh and check_style.sh
This commit is contained in:
		
						commit
						ead1a26f21
					
				| @ -3,57 +3,57 @@ | ||||
| ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)" | ||||
| 
 | ||||
| EXCLUDE_FILES=( | ||||
|   "libsolutil/picosha2.h" | ||||
|   "test/libsolutil/UTF8.cpp" | ||||
|   "test/libsolidity/syntaxTests/license/license_cr_endings.sol" | ||||
|   "test/libsolidity/syntaxTests/license/license_crlf_endings.sol" | ||||
|   "test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol" | ||||
|     "libsolutil/picosha2.h" | ||||
|     "test/libsolutil/UTF8.cpp" | ||||
|     "test/libsolidity/syntaxTests/license/license_cr_endings.sol" | ||||
|     "test/libsolidity/syntaxTests/license/license_crlf_endings.sol" | ||||
|     "test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol" | ||||
| ) | ||||
| EXCLUDE_FILES_JOINED=$(printf "%s\|" "${EXCLUDE_FILES[@]}") | ||||
| EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??} | ||||
| 
 | ||||
| ( | ||||
| REPO_ROOT="$(dirname "$0")"/.. | ||||
| cd $REPO_ROOT | ||||
| cd "$REPO_ROOT" || exit 1 | ||||
| 
 | ||||
| WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | | ||||
|   grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" | ||||
|     grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" | ||||
| ) | ||||
| 
 | ||||
| if [[ "$WHITESPACE" != "" ]] | ||||
| then | ||||
| 	echo "Error: Trailing whitespace found:" | tee -a $ERROR_LOG | ||||
| 	echo "$WHITESPACE" | tee -a $ERROR_LOG | ||||
| 	scripts/report_errors.sh "$ERROR_LOG" | ||||
| 	exit 1 | ||||
|     echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG" | ||||
|     echo "$WHITESPACE" | tee -a "$ERROR_LOG" | ||||
|     scripts/post_style_errors_on_github.sh "$ERROR_LOG" | ||||
|     exit 1 | ||||
| fi | ||||
| 
 | ||||
| function preparedGrep() | ||||
| { | ||||
| 	git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}" | ||||
| 	return $? | ||||
|     git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}" | ||||
|     return $? | ||||
| } | ||||
| 
 | ||||
| FORMATERROR=$( | ||||
| ( | ||||
| 	preparedGrep "#include \"" | egrep -v -e "license.h" -e "BuildInfo.h"  # Use include with <> characters | ||||
| 	preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" | ||||
| 	preparedGrep "\<for\>\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop | ||||
| 	preparedGrep "\<if\>\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" / "for" | ||||
| 	preparedGrep "[,\(<]\s*const " # const on left side of type | ||||
| 	preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) | ||||
| 	preparedGrep "^ [^*]|[^*] 	|	 [^*]" # uses spaces for indentation or mixes spaces and tabs | ||||
| 	preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | egrep -v "return [&]" # right-aligned reference ampersand (needs to exclude return) | ||||
| 	# right-aligned reference pointer star (needs to exclude return and comments) | ||||
| 	preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | egrep -v -e "return [*]" -e "^* [*]" -e "^*//.*" | ||||
| ) | egrep -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" | ||||
|     preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h"  # Use include with <> characters | ||||
|     preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" | ||||
|     preparedGrep "\<for\>\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop | ||||
|     preparedGrep "\<if\>\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" | ||||
|     preparedGrep "[,\(<]\s*const " # const on left side of type | ||||
|     preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) | ||||
|     preparedGrep "^ [^*]|[^*] 	|	 [^*]" # uses spaces for indentation or mixes spaces and tabs | ||||
|     preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return) | ||||
|     # right-aligned reference pointer star (needs to exclude return and comments) | ||||
|     preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*" | ||||
| ) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" | ||||
| ) | ||||
| 
 | ||||
| if [[ "$FORMATERROR" != "" ]] | ||||
| then | ||||
| 	echo "Coding style error:" | tee -a $ERROR_LOG | ||||
| 	echo "$FORMATERROR" | tee -a $ERROR_LOG | ||||
| 	scripts/report_errors.sh "$ERROR_LOG" | ||||
| 	exit 1 | ||||
|     echo "Coding style error:" | tee -a "$ERROR_LOG" | ||||
|     echo "$FORMATERROR" | tee -a "$ERROR_LOG" | ||||
|     scripts/post_style_errors_on_github.sh "$ERROR_LOG" | ||||
|     exit 1 | ||||
| fi | ||||
| ) | ||||
|  | ||||
| @ -14,7 +14,6 @@ | ||||
| ./scripts/docker_build.sh | ||||
| ./scripts/docs_version_pragma_check.sh | ||||
| ./scripts/uniqueErrors.sh | ||||
| ./scripts/report_errors.sh | ||||
| ./scripts/tests.sh | ||||
| ./scripts/docker_deploy.sh | ||||
| ./scripts/bytecodecompare/storebytecode.sh | ||||
| @ -24,7 +23,6 @@ | ||||
| ./scripts/install_obsolete_jsoncpp_1_7_4.sh | ||||
| ./scripts/install_deps.sh | ||||
| ./scripts/build.sh | ||||
| ./scripts/check_style.sh | ||||
| ./scripts/run_proofs.sh | ||||
| ./scripts/common_cmdline.sh | ||||
| ./scripts/docker_deploy_manual.sh | ||||
|  | ||||
| @ -4,16 +4,12 @@ ERROR_LOG="$1" | ||||
| 
 | ||||
| function report_error_to_github | ||||
| { | ||||
|     if [ -z $CIRCLE_PR_NUMBER ] | ||||
|     if [[ $CIRCLE_PR_NUMBER != "" ]] | ||||
|     then | ||||
|         CIRCLE_PR_NUMBER="${CIRCLE_PULL_REQUEST//[^0-9]/}" | ||||
|     fi | ||||
| 
 | ||||
|     ERROR_MSG=$(cat $ERROR_LOG) | ||||
| 
 | ||||
|     echo $ERROR_MSG | ||||
| 
 | ||||
|     if [ ! -z $CI ] | ||||
|     if [[ $CI == "true" ]] | ||||
|     then | ||||
|         echo "posting error message to github" | ||||
|         post_error_to_github | ||||
| @ -25,15 +21,15 @@ function post_error_to_github | ||||
| { | ||||
|     GITHUB_API_URL="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/issues/$CIRCLE_PR_NUMBER/comments" | ||||
| 
 | ||||
|     ESCAPED_ERROR_MSG=$(cat -e $ERROR_LOG | sed 's/\\/\\\\/g' | sed 's/"/\\\"/g') | ||||
|     ESCAPED_ERROR_MSG=$(cat -e "$ERROR_LOG" | sed 's/\\/\\\\/g' | sed 's/"/\\\"/g') | ||||
| 
 | ||||
|     FORMATTED_ERROR_MSG=$(echo $ESCAPED_ERROR_MSG | sed 's/\$/\\n/g' | tr -d '\n') | ||||
|     FORMATTED_ERROR_MSG=$(echo "$ESCAPED_ERROR_MSG" | sed 's/\$/\\n/g' | tr -d '\n') | ||||
| 
 | ||||
|     curl --request POST \ | ||||
|         --url $GITHUB_API_URL \ | ||||
|         --url "$GITHUB_API_URL" \ | ||||
|         --header 'accept: application/vnd.github.v3+json' \ | ||||
|         --header 'content-type: application/json' \ | ||||
|         -u stackenbotten:$GITHUB_ACCESS_TOKEN \ | ||||
|         -u "stackenbotten:$GITHUB_ACCESS_TOKEN" \ | ||||
|         --data "{\"body\": \"There was an error when running \`$CIRCLE_JOB\` for commit \`$CIRCLE_SHA1\`:\n\`\`\`\n$FORMATTED_ERROR_MSG\n\`\`\`\nPlease check that your changes are working as intended.\"}" | ||||
| } | ||||
| 
 | ||||
| @ -41,22 +37,22 @@ function post_review_comment_to_github | ||||
| { | ||||
|     GITHUB_API_URL="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$CIRCLE_PR_NUMBER/comments" | ||||
| 
 | ||||
|     sed -i 1d $ERROR_LOG | ||||
|     sed -i 1d "$ERROR_LOG" | ||||
| 
 | ||||
|     while read line | ||||
|     while read -r line | ||||
|     do | ||||
|         ERROR_PATH=$(echo $line | grep -oE ".*\.cpp") | ||||
|         ERROR_LINE=$(echo $line | grep -oE "[0-9]*") | ||||
|         ERROR_PATH=$(echo "$line" | grep -oE ".*\.cpp") | ||||
|         ERROR_LINE=$(echo "$line" | grep -oE "[0-9]*") | ||||
|         [[ $ERROR_PATH != "" ]] || { echo "ERROR: Error message does not contain file path."; exit 1; } | ||||
|         [[ $ERROR_LINE != "" ]] || { echo "ERROR: Error message does not contain line number."; exit 1; } | ||||
| 
 | ||||
|         curl --request POST \ | ||||
|             --url $GITHUB_API_URL \ | ||||
|             --url "$GITHUB_API_URL" \ | ||||
|             --header 'accept: application/vnd.github.v3+json, application/vnd.github.comfort-fade-preview+json' \ | ||||
|             --header 'content-type: application/json' \ | ||||
|             -u stackenbotten:$GITHUB_ACCESS_TOKEN \ | ||||
|             -u "stackenbotten:$GITHUB_ACCESS_TOKEN" \ | ||||
|             --data "{\"commit_id\": \"$CIRCLE_SHA1\", \"path\": \"$ERROR_PATH\", \"line\": $ERROR_LINE, \"side\": \"RIGHT\", \"body\": \"Coding style error\"}" | ||||
|     done < $ERROR_LOG | ||||
|     done < "$ERROR_LOG" | ||||
| } | ||||
| 
 | ||||
| report_error_to_github | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user