Browse Source

Fix Bash 4.3 issue and make scripts fail appropriately for similar issues in future

Tianon Gravi 5 years ago
parent
commit
79f67f8010
2 changed files with 36 additions and 25 deletions
  1. 30 25
      bashbrew/travis.sh
  2. 6 0
      naughty-commits.sh

+ 30 - 25
bashbrew/travis.sh

@@ -51,33 +51,38 @@ if badTags="$(bashbrew list "${repos[@]}" | grep -E ':.+latest.*|:.*latest.+')"
 	exit 1
 fi
 
-if [ -n "$extraCommands" ] && naughtyFrom="$(../naughty-from.sh "${repos[@]}")" && [ -n "$naughtyFrom" ]; then
-	echo >&2
-	echo >&2 "Invalid 'FROM' + 'Architectures' combinations detected:"
-	echo >&2
-	echo >&2 "$naughtyFrom"
-	echo >&2
-	echo >&2 'Read https://github.com/docker-library/official-images#multiple-architectures for more details.'
-	echo >&2
-	exit 1
-fi
+if [ -n "$extraCommands" ]; then
+	naughtyFrom="$(../naughty-from.sh "${repos[@]}")"
+	if [ -n "$naughtyFrom" ]; then
+		echo >&2
+		echo >&2 "Invalid 'FROM' + 'Architectures' combinations detected:"
+		echo >&2
+		echo >&2 "$naughtyFrom"
+		echo >&2
+		echo >&2 'Read https://github.com/docker-library/official-images#multiple-architectures for more details.'
+		echo >&2
+		exit 1
+	fi
 
-if [ -n "$extraCommands" ] && naughtyConstraints="$(../naughty-constraints.sh "${repos[@]}")" && [ -n "$naughtyConstraints" ]; then
-	echo >&2
-	echo >&2 "Invalid 'FROM' + 'Constraints' combinations detected:"
-	echo >&2
-	echo >&2 "$naughtyConstraints"
-	echo >&2
-	exit 1
-fi
+	naughtyConstraints="$(../naughty-constraints.sh "${repos[@]}")"
+	if [ -n "$naughtyConstraints" ]; then
+		echo >&2
+		echo >&2 "Invalid 'FROM' + 'Constraints' combinations detected:"
+		echo >&2
+		echo >&2 "$naughtyConstraints"
+		echo >&2
+		exit 1
+	fi
 
-if [ -n "$extraCommands" ] && naughtyCommits="$(../naughty-commits.sh "${repos[@]}")" && [ -n "$naughtyCommits" ]; then
-	echo >&2
-	echo >&2 "Unpleasant commits detected:"
-	echo >&2
-	echo >&2 "$naughtyCommits"
-	echo >&2
-	exit 1
+	naughtyCommits="$(../naughty-commits.sh "${repos[@]}")"
+	if [ -n "$naughtyCommits" ]; then
+		echo >&2
+		echo >&2 "Unpleasant commits detected:"
+		echo >&2
+		echo >&2 "$naughtyCommits"
+		echo >&2
+		exit 1
+	fi
 fi
 
 _bashbrew() {

+ 6 - 0
naughty-commits.sh

@@ -44,6 +44,9 @@ for img in $imgs; do
 		potentiallyNaughtyCommits=( $(_git log --diff-filter=DMT --format='format:%H' "$topCommit" -- "${potentiallyNaughtyGlobs[@]}") )
 		unset IFS
 
+		# bash 4.3 sucks (https://stackoverflow.com/a/7577209/433558)
+		[ "${#potentiallyNaughtyCommits[@]}" -gt 0 ] || continue
+
 		for commit in "${potentiallyNaughtyCommits[@]}"; do
 			[ -z "${seenCommits[$commit]:-}" ] || break
 			seenCommits[$commit]=1
@@ -57,6 +60,9 @@ for img in $imgs; do
 			) )
 			unset IFS
 
+			# bash 4.3 sucks (https://stackoverflow.com/a/7577209/433558)
+			[ "${#binaryFiles[@]}" -gt 0 ] || continue
+
 			naughtyReasons=()
 			for file in "${binaryFiles[@]}"; do
 				fileSize="$(_git ls-tree -r --long "$commit" -- "$file" | awk '{ print $4 }')"